Skip to content

Commit dc3f769

Browse files
committed
docs: add docs on abortsignal.timeout polyfill
1 parent e387d09 commit dc3f769

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,20 @@ From node 20.x onwards the WebCrypto API is available on globalThis, versions be
4141
globalThis.crypto = require("node:crypto").webcrypto;
4242
}
4343
```
44+
45+
### Old browsers might need a AbortSignal.timeout() polyfill
46+
47+
Old browsers might not have AbortSignal.timeout() available. We do not support these versions but you can add a polyfill using the following code:
48+
49+
```typescript
50+
// Polyfill for AbortSignal.timeout() for older browsers
51+
if (typeof AbortSignal !== "undefined" && !AbortSignal.timeout) {
52+
AbortSignal.timeout = function timeout(ms: number) {
53+
const controller = new AbortController();
54+
setTimeout(() => controller.abort(), ms);
55+
return controller.signal;
56+
};
57+
}
58+
59+
export {};
60+
```

0 commit comments

Comments
 (0)