useFork refactoring
Some checks failed
Lint / lint (push) Failing after 10s

This commit is contained in:
Julien Valverdé
2025-01-16 00:02:56 +01:00
parent 0e7f5d93bb
commit 4d411bc8dc

View File

@@ -119,15 +119,23 @@ export class Reffuse<R> {
useFork<A, E>(
effect: Effect.Effect<A, E, R | Scope.Scope>,
deps?: React.DependencyList,
options?: Runtime.RunForkOptions & RenderOptions,
options?: Runtime.RunForkOptions & RenderOptions & ScopeOptions,
): void {
const runSync = this.useRunSync()
const runFork = this.useRunFork()
return React.useEffect(() => {
const fiber = runFork(Effect.scoped(effect), options)
return () => { runFork(Fiber.interrupt(fiber)) }
const scope = runSync(Scope.make(options?.finalizerExecutionStrategy))
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 ?? []),
])
}