-
Notifications
You must be signed in to change notification settings - Fork 179
Lwt.awaken: replace wakeup and wakeup_later #1055
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
base: master
Are you sure you want to change the base?
Conversation
TODO: - documentation - tests
A bit early for a review I suppose, but the right spelling would be immediately, and you might want to use |
@MisterDA thanks! |
proposal: replace the make the type of the two functions distinct: I'm unsure about the type thing. Any comments suggestions ideas? |
proposal: make two distinct functions instead of one with parameter
The idea being: you can either prioritise the currently executing code and delay the resolving to when the scheduler runs or you can prioritise the resolving promise and you have to actuaslly pause the current promise This is a more radical change that makes the semantics clearer (one promise executes and then the scheduler kicks in, not both promise) but also backwards incompatible (you can't express |
Currently unhappy with the interface (the named parameter + constructor is too long). Alternatives:
I'm currently leaning towards this last possibility:
This makes the default case very simple and the complicated cases explicit. |
An issue with delaying the resolution of the promise is that the double-wakening exception has no place to be raised at. It happens asyncly meaning it should be handled by the async exception handler which I'm not keen to place more responsibility on. Still might be necessary. |
{{!t} promise} associated with {{!u} resolver} [r]. This triggers callbacks | ||
attached to the promise. | ||
(** [ordering] indicates a scheduling strategy for fullfilling or rejection of | ||
promnises associated to resolvers. |
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.
promnises associated to resolvers. | |
promises associated to resolvers. |
distinct ways: | ||
|
||
- [Deferred]: Resolves the promise later, after the current code reaches a | ||
pause or some I/O. This is often the behaviour you want. It makes the |
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 sentence got cut off here.
(if !has_happened then | ||
(* Using [Later] for [ordering] causes this branch to be taken *) | ||
print_endline "Current code was prioritised over resolved promise" | ||
else | ||
(* Using [Nested] for [ordering] causes this branch to be taken *) | ||
print_endline "Resolved promise code was prioritised over current"); |
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.
is it not the reverse way? !has_happened
is only true once task1
is resolved.
(* We do not use [~order:Dont_care] here to avoid a stack overflow | ||
when unlocking a lot of threads. *) | ||
Lwt.wakeup_later (Lwt_sequence.take_l m.waiters) () | ||
Lwt.awaken ~order:Dont_care (Lwt_sequence.take_l m.waiters) () |
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 comment disagrees with the code
TODO: