Skip to content

Commit

Permalink
Polyfill Promise.withResolvers for node 20 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aomarks committed Dec 20, 2024
1 parent 8c64fcb commit 3c25579
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/bbrt/src/test/node/util/fake-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
BBRTDriverSendOptions,
} from "../../../drivers/driver-interface.js";
import type { TurnChunk } from "../../../state/turn-chunk.js";
import "./install-promise-with-resolvers-polyfill.js";

type SyncHandler = (opts: BBRTDriverSendOptions) => TurnChunk[];
type AsyncHandler = (opts: BBRTDriverSendOptions) => AsyncIterable<TurnChunk>;
Expand Down
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 };
};
}

0 comments on commit 3c25579

Please sign in to comment.