-
Notifications
You must be signed in to change notification settings - Fork 65
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
generalBracket By Design Is Not Nestable #166
Comments
Can this be accomplished with an additional map? snd <$> generalBracket foo
{ ...
, completed \(Tuple a _) _ -> doSomething with a
} bar It's not fully clear to me what you are accomplishing by only running something in the |
I cannot "do something with a" that returns a value on the completed case. That is the problem. Also, I am not ignoring the other cases; I provided values for each. |
shouldn't this work?
if take succeeds then you have a and immediately after that you start |
My assumption is that If binds cannot be killed then that would be curious to me. When exactly could an Aff action be killed then? Edit: upon further thinking, I now suspect binds are not killable. Aff actions themselves have Cancelers, which to me suggests each action can be killed rather than the binds between them. I would need confirmation of this though to know if your solution works @safareli. |
Also note that JS is single threaded so when some sync operation is being performed nothing else is done at the same time. so nothing can kill some Aff computation which is in "middle" of |
@safareli yes it could be killed during bind depending on how it is implemented. It could be implemented such as:
Maybe this violates some law but speculatively I don't rule such a possibility out. |
The only thing If I understand you correctly you want to satisfy an interface like: newtype AVarLock a = AVarLock (AVar a)
modify :: forall a b. AVarLock a -> (a -> Aff (Tuple a b)) -> Aff b With the conditions that:
I don't think that you want to run the inner block within a You can possibly solve it with more AVars and Fibers. I know it sounds hacky, but AVars exist to do arbitrary async coordination. I would try forking the work you want done, and use |
@natefaubion yes you have intuited my example accurately. If generalBracket is just about resource acquisition and releasing then perhaps it was never intended in the way I have conceptualised it. I thought it was to let one continue from an action by case analysis of how it completed. For this easy example I can use the AVar status during resource releasing to determine if it was left empty or not. It is a particular workaround only for this one example. Edit: Actually it depends on whether a kill can happen between the last action in a generalBracket and the completion handler. If yes then the status is meaningless by the time the handler gets it. If you do not think there is any useful conversation left to have about this then feel free to close the ticket. |
The bracket mechanism is only designed for resource acquisition/release. There is potentially room for some other control mechanism, but it isn't immediately clear to me yet what that would be based on your goals. |
I am possibly misunderstanding how
generalBracket
works but here is my analysis.My situation is that I want to take an AVar, do some action on the value, then put a value to the AVar and return the action result. The invariant is that if the AVar was taken then a value must be put to it, and if the AVar was not taken then a value must not be put to it. Taking the AVar must be killable.
This first example makes no attempt at bracketing but demonstrates what should happen on the happy path.
There are several places in which a failure or kill breaks the invariant. Adding brackets, first to deal with taking the AVar must be killable:
And now this is stuck. There is no way to return the result from
completed
, so there is no way to continuetransact
given that taking the AVar succeeded.In other words, brackets are not nestable. Say they were, however, this is what could be done:
This assumes the typing:
If there is another way to implement this program I just am not seeing it right now.
The text was updated successfully, but these errors were encountered: