Awaiting fibers deterministically
Hello!
I have a program that must be deterministic. Some operations should not block the program’s main execution. However, I need to make sure they complete before the program exits.
I’m using forkDaemon to spawn child fibers. I understand this means the fibers created are attached to the global scope. I’m using a Runtime at the root of the program, Runtime runFork to run it and Fiber.awaiting the returned fiber.
forkDaemoned fibers do not complete before the program exits. My guess is this behavior is actually deterministic per run of a program but I’m not certain.
Adding child fibers to the parent scope with Effect.fork and awaiting the parent as the program does now seems like it would fix this but I’m concerned that might entail nondeterministic execution per the warning in the docs here: https://effect.website/docs/concurrency/fibers/#when-do-fibers-run
Is there a way to await fibers attached to the global scope? Does yield forkDaemon guarantee the fiber starts or at least can be awaited?
I have a program that must be deterministic. Some operations should not block the program’s main execution. However, I need to make sure they complete before the program exits.
I’m using forkDaemon to spawn child fibers. I understand this means the fibers created are attached to the global scope. I’m using a Runtime at the root of the program, Runtime runFork to run it and Fiber.awaiting the returned fiber.
forkDaemoned fibers do not complete before the program exits. My guess is this behavior is actually deterministic per run of a program but I’m not certain.
Adding child fibers to the parent scope with Effect.fork and awaiting the parent as the program does now seems like it would fix this but I’m concerned that might entail nondeterministic execution per the warning in the docs here: https://effect.website/docs/concurrency/fibers/#when-do-fibers-run
Is there a way to await fibers attached to the global scope? Does yield forkDaemon guarantee the fiber starts or at least can be awaited?
Effect Documentation
Understand fibers in Effect, lightweight virtual threads enabling powerful concurrency, structured lifecycles, and efficient resource management for responsive applications.
