-
Notifications
You must be signed in to change notification settings - Fork 1.5k
improved Queue shutdown functionality #9844
Description
Hey, I've recently proposed something on Discord, and since feedback has been rather positive, I'm making a ticket to track the idea.
I've been working with Queues recently, and I've been having some issues around shutdown that I would like to address.
Specifically, I find it a common pattern that I send some kind of request object through a queue because I want another fiber to perform some action on my behalf. Along with the request, I send a Promise to have that fiber communicate the outcome of that action to me. By and large this works fine. The issue arises when the fiber that I'm sending requests to fails. In that case, I would like it to communicate the cause of the failure back to the other fibers. This is easy enough for the requests that I've already pulled out of the queue: I simply fail those promises.
But I also need to deal with other cases: fibers currently blocked in an offer call, future attempts to offer to the queue, and I also need to deal with requests that have been submitted to the queue but not yet retrieved.
So my idea is as follows:
- add an
Etype parameter toQueue - add a
shutdownCausemethod that takes a type parameter of typeCause[E] shutdownCausewould also return the items currently buffered in the queue in order to dispose of them- after
shutdownCausehas been called, any attempt to interact with the queue will fail with the cause - methods like
take, offeretc. should indicate errors of typeE - streams created with
ZStream.fromQueuewould also fail with this cause shutdownCauseshould be atomic: when multiple fibers call it at the same time, one of them wins and the others fail with the cause supplied by the winner
Afaik, adding a new method is a binary compatible change, as is adding a new type parameter. Hence I think this is a source incompatible but binary compatible change. @ghostdogpr therefore suggested it could be added in a ZIO 2.2 release.