MCPcopy Index your code
hub / github.com/nodejs/node / setImmediate

Function setImmediate

lib/timers/promises.js:94–130  ·  view source on GitHub ↗
(value, options = kEmptyObject)

Source from the content-addressed store, hash-verified

92}
93
94function setImmediate(value, options = kEmptyObject) {
95 try {
96 validateObject(options, 'options');
97
98 if (typeof options?.signal !== 'undefined') {
99 validateAbortSignal(options.signal, 'options.signal');
100 }
101
102 if (typeof options?.ref !== 'undefined') {
103 validateBoolean(options.ref, 'options.ref');
104 }
105 } catch (err) {
106 return PromiseReject(err);
107 }
108
109 const { signal, ref = true } = options;
110
111 if (signal?.aborted) {
112 return PromiseReject(new AbortError(undefined, { cause: signal.reason }));
113 }
114
115 let oncancel;
116 const { promise, resolve, reject } = PromiseWithResolvers();
117 const immediate = new Immediate(resolve, [value]);
118 if (!ref) immediate.unref();
119 if (signal) {
120 oncancel = FunctionPrototypeBind(cancelListenerHandler,
121 immediate, clearImmediate, reject,
122 signal);
123 kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation;
124 signal.addEventListener('abort', oncancel, { __proto__: null, [kResistStopPropagation]: true });
125 }
126 return oncancel !== undefined ?
127 SafePromisePrototypeFinally(
128 promise,
129 () => signal.removeEventListener('abort', oncancel)) : promise;
130}
131
132async function* setInterval(after, value, options = kEmptyObject) {
133 if (typeof after !== 'undefined') {

Callers 15

test-quic-qlog.mjsFile · 0.90
yieldMethod · 0.70
doneMethod · 0.50
doCloseMethod · 0.50
readNextFunction · 0.50
checkForMessagesFunction · 0.50
customizedModuleWorkerFunction · 0.50
handleMessageFunction · 0.50

Calls 5

unrefMethod · 0.95
validateAbortSignalFunction · 0.85
addEventListenerMethod · 0.65
removeEventListenerMethod · 0.65
requireFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…