-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polyfill Promise.withResolvers for node 20 tests
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
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
20 changes: 20 additions & 0 deletions
20
packages/bbrt/src/test/node/util/install-promise-with-resolvers-polyfill.ts
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,20 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// TODO(aomarks) Promise.withResolvers is available in all browsers, and Node | ||
// 22. See if we can update the GitHub Actions runner version to 22, and if so | ||
// we can delete this polyfill. | ||
if (Promise.withResolvers === undefined) { | ||
Promise.withResolvers = <T>(): PromiseWithResolvers<T> => { | ||
let resolve!: (value: T | PromiseLike<T>) => void; | ||
let reject!: (reason?: unknown) => void; | ||
const promise = new Promise<T>((res, rej) => { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
return { promise, resolve, reject }; | ||
}; | ||
} |