Replies: 1 comment 1 reply
-
For starters, not that it's particularly relevant here, I do tend to view passing around a
The Since you have background jobs that are meant to outlive the "scope A" in which they were created, there indeed could be a larger "scope B" that they are not meant to outlive at all, i.e. the
Indeed, this is just how the API works (as you know ;)). There's no implicit blocking. It's the caller's responsibility to ensure children threads are allowed to complete before the parent "falls through" the bottom of the But I can provide some motivation for the decision: if there was an implicit block at the end of all race :: IO a -> IO a -> IO a
race action1 action2 =
Ki.scoped \scope -> do
resultVar <- newEmptyMVar
_ <- Ki.fork scope (action1 >>= tryPutMVar resultVar)
_ <- Ki.fork scope (action2 >>= tryPutMVar resultVar)
takeMVar resultVar In this example, we only wait for one thread to
This is an interesting suggestion. My gut reaction is I don't think we should do this, but I'm willing to hear out more thoughts about it. It seems to me that this is getting at the question of responsibility. For example, ought the scope/parent have complete control over when the children it spawns are terminated, as it does now? Or ought some part of the code with a handle to some scope be allowed to spawn a child into it, declaring it immune to being killed prematurely? But to me, as expounded upon above, these two "parties" are one and the same. If you have a handle to a scope, you are the parent thread of that scope. So, it's just as easy to remember to call
I like the ideas you are having. This is another I hadn't heard about before. But my inclination is the same: it seems just as easy to remember to call What do you think? |
Beta Was this translation helpful? Give feedback.
-
We have been (ab-)using
ki
in the following way:Scope
which lives for the lifetime of the job and into which we fork background tasksThis isn't very tidy:
awaitAll
on the scope before you terminate, otherwise you might kill things that need to finishWhat we're doing seems not ideal, but I'm not sure how to do it better.
Ideas:
Scope
could track which ones can be killed and which ones have to be awaited.scoped
functions that createScope
s that behave differently. Maybe these should be different types ofScope
.Beta Was this translation helpful? Give feedback.
All reactions