Formalize the Wakeable and Thenable types#18391
Merged
sebmarkbage merged 3 commits intofacebook:masterfrom Mar 25, 2020
Merged
Conversation
We use two subsets of Promises throughout React APIs. This introduces the smallest subset - Wakeable. It's the thing that you can throw to suspend. It's something that can ping. I also use a shared type for Thenable in the cases where we expect a value so we can be a bit more rigid with our us of them.
This value is just going from here to React so we can keep it a lighter abstraction throughout.
Details of bundled changes.Comparing: a6924d7...a910e62 react-flight-dom-webpack
react-flight-dom-relay
react-client
Size changes (stable) |
sebmarkbage
commented
Mar 25, 2020
|
|
||
| // The subset of a Thenable required by things thrown by Suspense. | ||
| // This doesn't require a value to be passed to either handler. | ||
| export interface Wakeable { |
Contributor
Author
There was a problem hiding this comment.
Thenable is called that way because you can call then on it.
Maybe this should be Waker or something. The walkable thing is what you pass to the then method. Something that can be woken.
Contributor
Author
There was a problem hiding this comment.
I guess in Rust, a Waker is the thing you call to then (essentially). It's the thing to be woken up.
So I guess Wakeable is fine. It's the thing that will at some point trigger to wake up the Waker.
Details of bundled changes.Comparing: a6924d7...a910e62 react-flight-dom-webpack
react-client
react-flight-dom-relay
Size changes (experimental) |
sebmarkbage
commented
Mar 25, 2020
| if (chunk._status === RESOLVED) { | ||
| return chunk._value; | ||
| } else if (chunk._status === PENDING) { | ||
| // eslint-disable-next-line no-throw-literal |
Contributor
Author
There was a problem hiding this comment.
Btw this seems like a bug in the no-throw-literal lint. It gets confused by the Flow annotation.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

We use two subsets of Promises throughout React APIs. This introduces the smallest subset - Wakeable. It's the thing that you can throw to suspend. It's something that can ping.
I also use a shared type for Thenable in the cases where we expect a value so we can be a bit more rigid with our us of them.
I also made Flight use fake Promises as the Wakeable that it throws.