Feature: join handle + waker #171
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goes with: hyperware-ai/hyperprocess-macro#51
Join Handle:
Previous behavior of
spawnwas to just add a future to the spawn queue, and return no handle. Now it spawns a task which takes that future and awaits it. It sends the result back via a oneshot channel. The JoinHandle is a struct wrapping around the receiver of the oneshot channel.Waker:
New struct
ExecutorWakeFlagis basically a flag which tells us whether a waker has been called, and if it has, poll all the pending tasks again (amongst which there is that one task which called the waker in the first place).The AtomicBool, ArcWake, swap, wake_by_ref, are all there to ensure that we can pass a waker reference to many tasks at the same time, and check from the outer loop if one of them had called the waker:
let was_woken = wake_flag.take();Note - previously we used a no-op waker, which doesn't work if we want to have handles for tasks, i.e. repoll once a future has completed. No-op waker would cause us to depend on the main event loop to receive a message from somewhere to repoll all tasks.
Example hyperapp code using join handles: