mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
web/polyfills: add polyfill for AbortSignal.timeout
This commit is contained in:
parent
819c7a4fa0
commit
5ba83f3d56
2 changed files with 11 additions and 0 deletions
|
@ -1 +1,2 @@
|
||||||
import "./polyfills/user-activation";
|
import "./polyfills/user-activation";
|
||||||
|
import "./polyfills/abortsignal-timeout";
|
||||||
|
|
10
web/src/lib/polyfills/abortsignal-timeout.ts
Normal file
10
web/src/lib/polyfills/abortsignal-timeout.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { browser } from "$app/environment";
|
||||||
|
|
||||||
|
if (browser && 'AbortSignal' in window && !window.AbortSignal.timeout) {
|
||||||
|
window.AbortSignal.timeout = (milliseconds: number) => {
|
||||||
|
const controller = new AbortController();
|
||||||
|
setTimeout(() => controller.abort("timed out"), milliseconds);
|
||||||
|
|
||||||
|
return controller.signal;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue