-
Notifications
You must be signed in to change notification settings - Fork 70
Add Control.Concurrent.Async.Warden #168
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
Conversation
Control/Concurrent/Async/Warden.hs
Outdated
| this <- fixIO $ \this -> mask_ $ Async.asyncWithUnmask $ \unmask -> | ||
| action unmask `finally` forget (Warden v) this | ||
| return (Just $ HashSet.insert (void this) asyncs, this) | ||
| Nothing -> (,) Nothing <$> Async.async (throwIO Async.AsyncCancelled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that if I don't wait the resulting async, I'll never notice that I'm trying to spawn into an already shut warden? Is there any specific reason why not just fail immediately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think we could throw here.
| -- | A more flexible way to create 'Async's and have them automatically | ||
| -- cancelled when the 'Warden' is shut down. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what's your use case, but this is an example of a more general pattern, see e.g. https://hackage.haskell.org/package/io-region
(For the record: I'm not suggesting anything, just my 2c.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use case I have is Glean (https://github.com/facebookincubator/Glean/blob/main/glean/db/Glean/Database/Env.hs#L102) and this also came up in a discussion on discourse https://discourse.haskell.org/t/multitasking-a-new-concurrency-library/12409/1
I think it's simple enough that we don't need to implement it in terms of anything else, but thanks for the pointer.
No description provided.