chore(system): add polyfill for Promise.withResolvers #5210
This commit is contained in:
@@ -399,3 +399,22 @@ export function areSetsEqual(a: Set<string>, b: Set<string>) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Polyfill for Promise.withResolvers until we can use it in all browsers
|
||||
* @internal
|
||||
*/
|
||||
export function withResolvers<T>(): {
|
||||
promise: Promise<T>;
|
||||
resolve: (value: T | PromiseLike<T>) => void;
|
||||
reject: (reason?: unknown) => void;
|
||||
} {
|
||||
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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user