Skip to content
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

Add Lwt_condition.broadcast_exn #241

Closed
wants to merge 1 commit into from
Closed

Add Lwt_condition.broadcast_exn #241

wants to merge 1 commit into from

Conversation

nojb
Copy link
Contributor

@nojb nojb commented May 9, 2016

No description provided.

@aantron
Copy link
Collaborator

aantron commented May 10, 2016

Thanks! Looks reasonable, but, being new to maintaining Lwt, I will ponder this for a little while.

@aantron
Copy link
Collaborator

aantron commented May 12, 2016

By the way, can you sketch out, at your leisure, your use case for this function?

@nojb
Copy link
Contributor Author

nojb commented May 12, 2016

When you have a set of listeners waiting on a condition the only way there is to signal failure to all of them is to introduce an auxiliary thread stopper and instead of using Lwt_condition.wait use something like:

let stopper, stop = Lwt.wait ()
let wait_with_cancellation cond =
  Lwt.pick [Lwt_condition.wait cond; stopper]

Then you can fail all waiting threads with exception exn by doing Lwt.wakeup_exn stop exn. If then you want to do this again, you need to introduce a new stopper, etc. It just seemed cleaner to offer this idiom from inside Lwt_condition.

@aantron aantron closed this in a44d7a0 Jun 21, 2016
@aantron
Copy link
Collaborator

aantron commented Jun 21, 2016

Committed as a44d7a0. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants