-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52e38d8
commit 5cb5cfc
Showing
4 changed files
with
33 additions
and
69 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export async function raceWithSignal<T>( | ||
promise: Promise<T>, | ||
signal?: AbortSignal | ||
): Promise<T> { | ||
if (signal === undefined) { | ||
return promise; | ||
} | ||
if (signal.aborted) { | ||
throw new Error("AbortError"); | ||
} | ||
return Promise.race([ | ||
promise, | ||
new Promise<never>((_, reject) => { | ||
signal.addEventListener("abort", () => reject(new Error("Aborted"))); | ||
}), | ||
]); | ||
} |
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