Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20be5e2

Browse filesBrowse files
mfdebianruyadorno
authored andcommitted
doc: add esm examples to node:timers
PR-URL: #55857 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 97458ad commit 20be5e2
Copy full SHA for 20be5e2

File tree

Expand file treeCollapse file tree

1 file changed

+36
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+36
-2
lines changed
Open diff view settings
Collapse file

‎doc/api/timers.md‎

Copy file name to clipboardExpand all lines: doc/api/timers.md
+36-2Lines changed: 36 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,24 @@ returned Promises will be rejected with an `'AbortError'`.
292292

293293
For `setImmediate()`:
294294

295-
```js
295+
```mjs
296+
import { setImmediate as setImmediatePromise } from 'node:timers/promises';
297+
298+
const ac = new AbortController();
299+
const signal = ac.signal;
300+
301+
// We do not `await` the promise so `ac.abort()` is called concurrently.
302+
setImmediatePromise('foobar', { signal })
303+
.then(console.log)
304+
.catch((err) => {
305+
if (err.name === 'AbortError')
306+
console.error('The immediate was aborted');
307+
});
308+
309+
ac.abort();
310+
```
311+
312+
```cjs
296313
const { setImmediate: setImmediatePromise } = require('node:timers/promises');
297314

298315
const ac = new AbortController();
@@ -310,7 +327,24 @@ ac.abort();
310327

311328
For `setTimeout()`:
312329

313-
```js
330+
```mjs
331+
import { setTimeout as setTimeoutPromise } from 'node:timers/promises';
332+
333+
const ac = new AbortController();
334+
const signal = ac.signal;
335+
336+
// We do not `await` the promise so `ac.abort()` is called concurrently.
337+
setTimeoutPromise(1000, 'foobar', { signal })
338+
.then(console.log)
339+
.catch((err) => {
340+
if (err.name === 'AbortError')
341+
console.error('The timeout was aborted');
342+
});
343+
344+
ac.abort();
345+
```
346+
347+
```cjs
314348
const { setTimeout: setTimeoutPromise } = require('node:timers/promises');
315349

316350
const ac = new AbortController();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.