Allow a fiber to be "freezed" / paused + resumed
See original GitHub issueThe title says it all. I want to be able to “pause” + “resume” a fiber/effect. This should already be possible at every point we currently would be doing interruption by just telling the scheduler to not run any more effects from this fiber.
Why would I want to do that?
example 1: I have a long running calculation that now and then has to access third party systems. There are many calls that access many third party systems. I could now implement a retry with backoff logic on every of these calls. But I could also have a component that monitors the connection to these third party systems. If one of the connections goes down, I want to be able to simply pause my long running effect and resume it when the connections are back up.
example 2: same long running calculation (by long running, I mean >24h)… my end-user wants to pause the long running calculation to inspect the used resources (e.g. published data in 3rd party systems/databases, created files/folders, logfiles, etc.) … kind of like debugging with a debugger, but at a higher level.
example 3: I could have various background jobs (e.g. processing some streams, syncing files, etc.) that I can manage using a UI where I can start / pause / resume / stop the job.
example 4: debugging (as a dev): When my system is behaving strangely, it would be helpful to simply pause some fibers that are creating a lot of noise. Then I can zoom-in to the part of the system that is creating problems using thread-dumps, heap-dumps, profilers, proxies, etc. I could even create a management module to list and control fibers from the outside via REST or JMX.
I know that I can implement a similar behavior as a workaround by creating a Ref[Boolean]
and check that in every step of my fiber… but I would have to do that in every new functionality I program and it would never be as clean as telling the scheduler “dont execute any more effects from that fiber”… so any “workaround” is not the point of this ticket.
In theory, freezing a fiber/effect would also be a first step to being able to migrate fibers/effects to other nodes, kind of like its possible in other languages like erlang (but that is just a thought experiment for now…)
I think this feature would be something entirely unique to ZIO on the JVM. Something that only a few people deemed possible a few years ago. Something that not even Loom will provide in the near future. And I think we should already be having almost everything that would be required to make that possible. In my simplified view of ZIO its as simple as telling the scheduler to stop processing effects from fiber x… I’m probably missing something, but would be great to read your thoughts!
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
@gregor-rayman I think you want to take a look at ZIO Flow for that.
A different but related topic: Would it be possible to suspend and persist a fiber (or something similar), stop the whole application (e.g. to deploy a new version) and then later to load the fiber’s state and to continue? (This would be usable for loooong running business processes that are waiting on external events.). I know this is more domain of BPEL… but describing business processes as for comprehentions seem so much more atractive