You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove join scope weirdness in Async[Resource] #1619
The current implementation has a rather bizarre semantic, wherein if you join on a Fiber, the finalizer scope for the fiber is forwarded into the join scope, but via the Outcome. If you don't join, then the relevant finalizer scope is the one which arose originally from start.
In retrospect, I think this is a little counter-intuitive. The only situation under which join could terminate its scope before the outer scope is eval(joinEmbed.use) or something similar, meaning we don't actually get much in the way of expressiveness from this rather odd semantic, and the downsides are that join after join doesn't work reasonably, and the state machine is unnecessarily complex.
Instead of all of this, we should simply treat the Fiber itself as a resource (opened by start) and make that scope responsible for ensuring the inner finalizers are cleaned up.
Also, 👍 on the proposed semantic. Defining the scope as that of the Resource returned by start is much easier to understand and side-steps the multiple join oddities entirely. Early finalization due to .cancel also works out nicely since join controls access to the resource, making the start resource an upper-bound of sorts.
Also, 👍 on the proposed semantic. Defining the scope as that of the Resource returned by start is much easier to understand and side-steps the multiple join oddities entirely. Early finalization due to .cancel also works out nicely since join controls access to the resource, making the start resource an upper-bound of sorts.
@wemrysi Yeah I was thinking about it and I realized that we can just universally rely on the upper-bound and it all comes out to the same thing except when someone does use. The argument is similar for memoize: everything actually works exactly as you think it should except when you do use, at which point it kind of falls apart. I just generally think that use and allocated need to be treated as sorcerous artifacts and left alone as much as possible.
I'm going to need some examples/drawings to understand what this is about 😂
@kubukoz LOL It's not quite that bad. The implementation of Async[Resource].start in HEAD right now has a relatively convoluted semantic:
/* * 1. If the scope containing the *fiber* terminates: * a) if the fiber is incomplete, run its inner finalizers when it complets * b) if the fiber is succeeded, run its finalizers * 2. If the fiber is canceled or errored, finalize * 3. If the fiber succeeds, await joining and extend finalizers into joining scope * 4. If a fiber is canceled *after* it completes, we explicitly snag the finalizers and run them, setting the result to Canceled() * a) ...but only if the fiber has not yet been joined! This catches the "tree fell in the forest but no one was around" case * 5. If a fiber is joined multiple times, subsequent joins have access to the result but not the finalizers (mirroring memoization on a Resource)*/defstart[A](fa: Resource[F, A]):Resource[F, Fiber[Resource[F, *], Throwable, A]] = {
What we're talking about is removing case 3 and by extension case 5.
Activity
djspiewak commentedon Feb 7, 2021
Btw @wemryrsi, if you have some time and inclination, this is a good one to jump on. :-)
wemrysi commentedon Feb 15, 2021
@djspiewak Just noticed this, I'm on it 👍 .
wemrysi commentedon Feb 15, 2021
Also, 👍 on the proposed semantic. Defining the scope as that of the
Resourcereturned bystartis much easier to understand and side-steps the multiplejoinoddities entirely. Early finalization due to.cancelalso works out nicely sincejoincontrols access to the resource, making thestartresource an upper-bound of sorts.kubukoz commentedon Feb 16, 2021
I'm going to need some examples/drawings to understand what this is about 😂
djspiewak commentedon Feb 17, 2021
@wemrysi Yeah I was thinking about it and I realized that we can just universally rely on the upper-bound and it all comes out to the same thing except when someone does
use. The argument is similar formemoize: everything actually works exactly as you think it should except when you douse, at which point it kind of falls apart. I just generally think thatuseandallocatedneed to be treated as sorcerous artifacts and left alone as much as possible.@kubukoz LOL It's not quite that bad. The implementation of
Async[Resource].startin HEAD right now has a relatively convoluted semantic:What we're talking about is removing case 3 and by extension case 5.
wemrysi commentedon Feb 17, 2021
💯