This commit is contained in:
@@ -119,15 +119,23 @@ export class Reffuse<R> {
|
|||||||
useFork<A, E>(
|
useFork<A, E>(
|
||||||
effect: Effect.Effect<A, E, R | Scope.Scope>,
|
effect: Effect.Effect<A, E, R | Scope.Scope>,
|
||||||
deps?: React.DependencyList,
|
deps?: React.DependencyList,
|
||||||
options?: Runtime.RunForkOptions & RenderOptions,
|
options?: Runtime.RunForkOptions & RenderOptions & ScopeOptions,
|
||||||
): void {
|
): void {
|
||||||
|
const runSync = this.useRunSync()
|
||||||
const runFork = this.useRunFork()
|
const runFork = this.useRunFork()
|
||||||
|
|
||||||
return React.useEffect(() => {
|
return React.useEffect(() => {
|
||||||
const fiber = runFork(Effect.scoped(effect), options)
|
const scope = runSync(Scope.make(options?.finalizerExecutionStrategy))
|
||||||
return () => { runFork(Fiber.interrupt(fiber)) }
|
const fiber = runFork(Effect.provideService(effect, Scope.Scope, scope), options)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
Fiber.interrupt(fiber).pipe(
|
||||||
|
Effect.flatMap(() => Scope.close(scope, Exit.void)),
|
||||||
|
runFork,
|
||||||
|
)
|
||||||
|
}
|
||||||
}, [
|
}, [
|
||||||
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runFork],
|
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync, runFork],
|
||||||
...(deps ?? []),
|
...(deps ?? []),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user