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

Function setInterval

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

Source from the content-addressed store, hash-verified

130}
131
132async function* setInterval(after, value, options = kEmptyObject) {
133 if (typeof after !== 'undefined') {
134 validateNumber(after, 'delay');
135 }
136
137 validateObject(options, 'options');
138
139 if (typeof options?.signal !== 'undefined') {
140 validateAbortSignal(options.signal, 'options.signal');
141 }
142
143 if (typeof options?.ref !== 'undefined') {
144 validateBoolean(options.ref, 'options.ref');
145 }
146
147 const { signal, ref = true } = options;
148
149 if (signal?.aborted) {
150 throw new AbortError(undefined, { cause: signal.reason });
151 }
152
153 let onCancel;
154 let interval;
155 try {
156 let notYielded = 0;
157 let callback;
158 interval = new Timeout(() => {
159 notYielded++;
160 if (callback) {
161 callback();
162 callback = undefined;
163 }
164 }, after, undefined, true, ref);
165 insert(interval, interval._idleTimeout);
166 if (signal) {
167 onCancel = () => {
168 clearInterval(interval);
169 if (callback) {
170 callback(
171 PromiseReject(
172 new AbortError(undefined, { cause: signal.reason })));
173 callback = undefined;
174 }
175 };
176 kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation;
177 signal.addEventListener('abort', onCancel, { __proto__: null, once: true, [kResistStopPropagation]: true });
178 }
179
180 while (!signal?.aborted) {
181 if (notYielded === 0) {
182 await new Promise((resolve) => callback = resolve);
183 }
184 for (; notYielded > 0; notYielded--) {
185 yield value;
186 }
187 }
188 throw new AbortError(undefined, { cause: signal?.reason });
189 } finally {

Callers 5

exitHandlerFunction · 0.50
#startPollingMethod · 0.50
#startPollingMethod · 0.50
constructorMethod · 0.50
refFunction · 0.50

Calls 7

validateAbortSignalFunction · 0.85
insertFunction · 0.85
clearIntervalFunction · 0.85
addEventListenerMethod · 0.65
removeEventListenerMethod · 0.65
callbackFunction · 0.50
requireFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…