File tree Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -288,7 +288,24 @@ returned Promises will be rejected with an `'AbortError'`.
288288
289289For ` setImmediate() ` :
290290
291- ``` js
291+ ``` mjs
292+ import { setImmediate as setImmediatePromise } from ' node:timers/promises' ;
293+
294+ const ac = new AbortController ();
295+ const signal = ac .signal ;
296+
297+ // We do not `await` the promise so `ac.abort()` is called concurrently.
298+ setImmediatePromise (' foobar' , { signal })
299+ .then (console .log )
300+ .catch ((err ) => {
301+ if (err .name === ' AbortError' )
302+ console .error (' The immediate was aborted' );
303+ });
304+
305+ ac .abort ();
306+ ```
307+
308+ ``` cjs
292309const { setImmediate: setImmediatePromise } = require (' node:timers/promises' );
293310
294311const ac = new AbortController ();
@@ -306,7 +323,24 @@ ac.abort();
306323
307324For ` setTimeout() ` :
308325
309- ``` js
326+ ``` mjs
327+ import { setTimeout as setTimeoutPromise } from ' node:timers/promises' ;
328+
329+ const ac = new AbortController ();
330+ const signal = ac .signal ;
331+
332+ // We do not `await` the promise so `ac.abort()` is called concurrently.
333+ setTimeoutPromise (1000 , ' foobar' , { signal })
334+ .then (console .log )
335+ .catch ((err ) => {
336+ if (err .name === ' AbortError' )
337+ console .error (' The timeout was aborted' );
338+ });
339+
340+ ac .abort ();
341+ ```
342+
343+ ``` cjs
310344const { setTimeout: setTimeoutPromise } = require (' node:timers/promises' );
311345
312346const ac = new AbortController ();
You can’t perform that action at this time.
0 commit comments