-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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 support for multiple callbacks in ReactScheduler #12682
Closed
Closed
Commits on May 2, 2018
-
Add support for multiple callbacks in ReactScheduler
**what is the change?:** We want to support calling ReactScheduler multiple times with different callbacks, even if the initial callback hasn't been called yet. There are two possible ways ReactScheduler can handle multiple callbacks, and in one case we know that callbackA depends on callbackB having been called already. For example; callbackA -> updates SelectionState in a textArea callbackB -> processes the deletion of the text currently selected. We want to ensure that callbackA happens before callbackB. For now we will flush callbackB as soon as callbackA is added. In the next commit we'll split this into two methods, which support two different behaviors here. We will support the usual behavior, which would defer both callbackA and callbackB. One issue with this is that we now create a new object to pass to the callback for every use of the scheduler, while before we reused the same object and mutated the 'didExpire' before passing it to each new callback. With multiple callbacks, I think this leads to a risk of mutating the object which is being used by multiple callbacks. **why make this change?:** We want to use this scheduling helper to coordinate between React and non-React scripts. **test plan:** Added and ran a unit test.
Configuration menu - View commit details
-
Copy full SHA for d376543 - Browse repository at this point
Copy the full SHA d376543View commit details -
Configuration menu - View commit details
-
Copy full SHA for fea65d6 - Browse repository at this point
Copy the full SHA fea65d6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5f450b8 - Browse repository at this point
Copy the full SHA 5f450b8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 079bb73 - Browse repository at this point
Copy the full SHA 079bb73View commit details -
Fix case of scheduled callbacks which schedule other callbacks
**what is the change?:** We added support for serial scheduled callbacks to schedule more callbacks, and maintained the order of first-in first-called. **why make this change?:** This is sort of a corner case, but it's totally possible and we do something similar in React. We wouldn't do this with serial callbacks, but with deferred callbacks we do a pattern like this: ``` + + | +--------------------+ +----------------+ | +--------------------------------+ +-------------------------+ | | | | | | | | | | | | main thread blocked| |callback A runs | | | main thread blocked again | |callback A runs again, finishes | +--------------------+ +-----+----------+ | +--------------------------------+ ++------------------------+ v ^ v ^ schedule +------------------------->+ no time left!+----------------------->+ callbackA reschedule | callbackA + to do more work later. ``` **test plan:** Wrote some fun new tests and ran them~ Also ran existing React unit tests. As of this PR they are still directly using this module.
Configuration menu - View commit details
-
Copy full SHA for df6624b - Browse repository at this point
Copy the full SHA df6624bView commit details -
Configuration menu - View commit details
-
Copy full SHA for c1278be - Browse repository at this point
Copy the full SHA c1278beView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8283c95 - Browse repository at this point
Copy the full SHA 8283c95View commit details -
Handle errors thrown by callbacks in
schedule
**what is the change?:** We may call a sequence of callbacks in our `schedule` helper, and this catches any errors and re-throws them later, so we don't get interrupted or left in an invalid state. **why make this change?:** If you have callbacks A, B, and C scheduled, and B throws, we still want C to get called. I would prefer if we could find a way to throw and continue syncronously but for now this approach, of deferring the error, will work. **test plan:** Added a unit test.
Configuration menu - View commit details
-
Copy full SHA for eb0110f - Browse repository at this point
Copy the full SHA eb0110fView commit details -
**what is the change?:** see title **why make this change?:** We are about to add functionality to cIC, where we take an id. This is in preparation for when we support 'deferred' as well as 'serial' callbacks. **test plan:** Run the test.
Configuration menu - View commit details
-
Copy full SHA for 0c47fe2 - Browse repository at this point
Copy the full SHA 0c47fe2View commit details -
Add stronger types and refactoring in
ReactScheduler
**what is the change?:** Some various clean-up changes to pave the way for adding an 'id' for each callback which can be used to cancel the callback. **why make this change?:** To make the next diff easier. **test plan:** Ran the tests.
Configuration menu - View commit details
-
Copy full SHA for e96d0e3 - Browse repository at this point
Copy the full SHA e96d0e3View commit details -
Return an id when scheduling callback; use it for cancelling callback
**what is the change?:** See title. **why make this change?:** When we support multiple callbacks you will need to use the callback id to cancel a specific callback. **test plan:** Tests were updated, ran all tests.
Configuration menu - View commit details
-
Copy full SHA for 26b82c8 - Browse repository at this point
Copy the full SHA 26b82c8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 64b57b1 - Browse repository at this point
Copy the full SHA 64b57b1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8703f21 - Browse repository at this point
Copy the full SHA 8703f21View commit details -
Restructure 'schedule' rIC code for clarity
**what is the change?:** We previously had the following logic: - pull any old callback out of the 'scheduledCallback' variable - put the new callback into 'scheduledCallback' - call the old callback if we had found one. Splitting out the logic for handling the old callback into two blocks was hard to read, so we restructured as so: - if no old callback was found, just put the new callback into the 'scheduledCallback' variable. - Otherwise, if we do find an old callback, then: - pull any old callback out of the 'scheduledCallback' variable - put the new callback into 'scheduledCallback' - call the old callback **why make this change?:** Code clarity **test plan:** Ran the tests
Configuration menu - View commit details
-
Copy full SHA for 5ba093b - Browse repository at this point
Copy the full SHA 5ba093bView commit details
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.