-
Notifications
You must be signed in to change notification settings - Fork 12.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
feat(lib/es2020): Add Promise.allSettled(…)
#34065
Merged
DanielRosenwasser
merged 7 commits into
microsoft:master
from
ExE-Boss:lib/es2020/add-promise-allsettled
Jan 3, 2020
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
04fcd7b
feat(lib/es2020): Add `Promise.allSettled(…)`
ExE-Boss ee3df7f
test(lib): Update tests to account for `es2020.promise`
ExE-Boss 829f973
fix(lib/es2020): `Promise.allSettled(…)` takes `Iterable` argument
ExE-Boss 1b6c771
refactor(lib/es2020): Rename `Promise.allSettled(…)` return type
ExE-Boss be97a6b
feat(lib/es2020): Simplify `Promise.allSettled(…)` type declaration
ExE-Boss 926c561
Merge branch 'master' into lib/es2020/add-promise-allsettled
ExE-Boss 2929aad
refactor(lib/es2020): Improve naming of `Promise.allSettled(…)` types
ExE-Boss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/// <reference lib="es2019" /> | ||
/// <reference lib="es2020.promise" /> | ||
/// <reference lib="es2020.string" /> | ||
/// <reference lib="es2020.symbol.wellknown" /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interface PromiseResolvedResult<T> { | ||
status: "fulfilled"; | ||
value: T; | ||
} | ||
|
||
interface PromiseRejectedResult { | ||
status: "rejected"; | ||
reason: any; | ||
ExE-Boss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
type PromiseSettledResult<T> = PromiseResolvedResult<T> | PromiseRejectedResult; | ||
|
||
interface PromiseConstructor { | ||
/** | ||
* Creates a Promise that is resolved with an array of results when all | ||
* of the provided Promises resolve or reject. | ||
* @param values An array of Promises. | ||
* @returns A new Promise. | ||
*/ | ||
allSettled<T extends readonly any[] | readonly [any]>(values: T): Promise<{ -readonly [P in keyof T]: PromiseSettledResult<T[P] extends PromiseLike<infer U> ? U : T[P]> }>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make these |
||
|
||
/** | ||
* Creates a Promise that is resolved with an array of results when all | ||
* of the provided Promises resolve or reject. | ||
* @param values An array of Promises. | ||
* @returns A new Promise. | ||
*/ | ||
allSettled<T>(values: Iterable<T>): Promise<PromiseSettledResult<T extends PromiseLike<infer U> ? U : T>[]>; | ||
} |
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
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
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.
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.
Hi. Drive-by code review here. Shouldn’t this be named something like
PromiseFulfilledResult
to adhere to the states and fates terminology? I think the reason calling itPromiseResolvedResult
is incorrect here is that while all fulfilled promises are resolved, not all resolved promises are fulfilled. A promise can be resolved to a pending promise, in which case it has not settled, and it can also be resolved to a rejected promise, in which case it has not fulfilled.If my interpretation of states and fates terminology is correct, shouldn’t the correct name of this interface be
PromiseFulfilledResult
?