-
-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add immediate:boolean to RunForkOptions #1896
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 |
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 |
@mattiamanzati I should be able to add the |
917105e
to
67952ee
Compare
@mattiamanzati Updated in the latest pushes |
@TylorS Thanks 🙏 |
Why would the fiber not being removed upon exit? that should be the behaviour |
@mikearnaldi When you do |
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 |
/** @internal */
export const forkIn = 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 |
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 |
67952ee
to
16bce8c
Compare
The current behaviour is to start immediately, so you will see no change with this PR. |
Uhm but run callback relies on run fork, so it should be affected as well right? |
This PR enables non-immediate starts through |
Ohh, I though of it in the completely opposite direction. |
d720c87
to
6ebff6a
Compare
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 |
@mikearnaldi PR Updated with Scope here and the additional options to Effect.runFork here |
f723296
to
ff47da4
Compare
@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
426bdbb
Compare
Rebased |
Type
Description
Adds
immediate: boolean
toRunForkOptions
to enable creating a Fiber which usesfiberRuntime.start()
orfiberRuntime.resume()
Adds
RunCallbackOptions<E, A>
which extendsRunForkOptions
with anonExit
callback, such that runCallback has access to the same fork options as runFork.Related