-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Make Poll
an async iterable
#386
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Maybe add those notes to the README for polling? |
I was going to ask "what README?" but the question answers itself 🤣 |
blink1073
approved these changes
Aug 31, 2022
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.
Nice, thanks!
fcollonval
reviewed
Sep 1, 2022
Co-authored-by: Frédéric Collonval <[email protected]>
fcollonval
approved these changes
Sep 2, 2022
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.
Thanks
This was referenced Sep 5, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
In this PR, the
IPoll
interface and thePoll
class extendAsyncIterable
(by implementing aSymbol.asyncIterator
method) to supportfor-await...of
loops.This PR also adds a
README.md
file for the@lumino/polling
package.This functionality may be a natural fit for streams of events from the new Jupyter event system, other
WebSocket
connections, or other stream sources.cc: @Zsailer @andrii-i @davidbrochart @3coins @vidartf (since you all have some interest in events and/or iterators)
Example usage
The tests in this PR are illustrative. Here is one of them with some annotation:
Here, we set up the testing state variables and create a new
Poll
instance.Then the poll is started:
Instead of connecting to the
ticked
signal or awaiting thetick
promise, we can now use afor-await...of
loop:And we check to make sure the results are as expected:
Note for consumers of async iterators
The
Poll
class itself only usesES6
(andDOM
) types in itslib
collection but in order to usefor-await...of
loops in TypeScript, you will need to useES2018
or above in yourlib
array intsconfig.json
.Fixes #385
cf. partially addresses #339