Uh oh!
There was an error while loading. Please reload this page.
feat: Add immediate:boolean to RunForkOptions - #1896
Conversation
🦋 Changeset detectedLatest commit: 426bdbb The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
mattiamanzati
commented
Jan 11, 2024
Bonus, could we please have this also on unsafeRunCallback? It is useful to have the callback eventually be called synchronously if the effect is sync as well |
TylorS
commented
Jan 11, 2024
@mattiamanzati I should be able to add the |
917105e to
67952eeCompareTylorS
commented
Jan 11, 2024
@mattiamanzati Updated in the latest pushes |
mattiamanzati
commented
Jan 11, 2024
@TylorS Thanks 🙏 |
mikearnaldi
commented
Jan 11, 2024
Why would the fiber not being removed upon exit? that should be the behaviour |
TylorS
commented
Jan 11, 2024
@mikearnaldi When you do |
mikearnaldi
commented
Jan 11, 2024
you're right, I will investigate if adding an api to remove a finaliser may be useful |
In the same vein, I'm not positive that |
mikearnaldi
commented
Jan 11, 2024
/** @internal */exportconstforkIn=dual<(scope: Scope.Scope)=><R,E,A>(self: Effect.Effect<R,E,A>)=>Effect.Effect<R,never,Fiber.RuntimeFiber<E,A>>,<R,E,A>(self: Effect.Effect<R,E,A>,scope: Scope.Scope)=>Effect.Effect<R,never,Fiber.RuntimeFiber<E,A>>>(2,(self,scope)=>core.uninterruptibleMask((restore)=>core.flatMap(scope.fork(executionStrategy.sequential),(child)=>pipe(restore(self),core.onExit((exit)=>child.close(exit)),fiberRuntime.forkDaemon,core.tap((fiber)=>child.addFinalizer(()=>core.fiberIdWith((fiberId)=>Equal.equals(fiberId,fiber.id()) ?
core.unit :
core.asUnit(core.interruptFiber(fiber)))))))))This is safe, it forks a separate scope and that scope is closed as the fiber ends |
TylorS
commented
Jan 11, 2024
But closing that child/forked Scope doesn't remove its reference as a Finalizer in the parent Scope when it is closed |
I take that back, I found the code that keeps it safe here - https://github.com/Effect-TS/effect/blob/main/packages/effect/src/internal/fiberRuntime.ts#L2962 |
Uh oh!
There was an error while loading. Please reload this page.
67952ee to
16bce8cComparetim-smart
commented
Jan 12, 2024
The current behaviour is to start immediately, so you will see no change with this PR. |
mattiamanzati
commented
Jan 12, 2024
Uhm but run callback relies on run fork, so it should be affected as well right? |
TylorS
commented
Jan 12, 2024
This PR enables non-immediate starts through |
mattiamanzati
commented
Jan 12, 2024
Ohh, I though of it in the completely opposite direction. |
d720c87 to
6ebff6aComparemikearnaldi
commented
Jan 14, 2024
Can we add back Scope in the style used by forkIn? also it is worth updating the main runFork method in Effect.ts to take the RunOptions currently only Runtime exposes it |
TylorS
commented
Jan 14, 2024
@mikearnaldi PR Updated with Scope here and the additional options to Effect.runFork here |
Uh oh!
There was an error while loading. Please reload this page.
f723296 to
ff47da4Comparetim-smart
commented
Jan 15, 2024
@TylorS if you rebase that should fix CI |
refactor: use interrupting FiberId fix: remove Scope option due to memory leaks feat: add RunForkOptions to runCallback
8215ce6 to
426bdbbCompareTylorS
commented
Jan 15, 2024
Rebased |
Type
Description
Adds
immediate: booleantoRunForkOptionsto enable creating a Fiber which usesfiberRuntime.start()orfiberRuntime.resume()Adds
RunCallbackOptions<E, A>which extendsRunForkOptionswith anonExitcallback, such that runCallback has access to the same fork options as runFork.Related