(after, value, options = kEmptyObject)
| 51 | } |
| 52 | |
| 53 | function setTimeout(after, value, options = kEmptyObject) { |
| 54 | try { |
| 55 | if (typeof after !== 'undefined') { |
| 56 | validateNumber(after, 'delay'); |
| 57 | } |
| 58 | |
| 59 | validateObject(options, 'options'); |
| 60 | |
| 61 | if (typeof options?.signal !== 'undefined') { |
| 62 | validateAbortSignal(options.signal, 'options.signal'); |
| 63 | } |
| 64 | |
| 65 | if (typeof options?.ref !== 'undefined') { |
| 66 | validateBoolean(options.ref, 'options.ref'); |
| 67 | } |
| 68 | } catch (err) { |
| 69 | return PromiseReject(err); |
| 70 | } |
| 71 | |
| 72 | const { signal, ref = true } = options; |
| 73 | |
| 74 | if (signal?.aborted) { |
| 75 | return PromiseReject(new AbortError(undefined, { cause: signal.reason })); |
| 76 | } |
| 77 | |
| 78 | let oncancel; |
| 79 | const { promise, resolve, reject } = PromiseWithResolvers(); |
| 80 | const timeout = new Timeout(resolve, after, [value], false, ref); |
| 81 | insert(timeout, timeout._idleTimeout); |
| 82 | if (signal) { |
| 83 | oncancel = FunctionPrototypeBind(cancelListenerHandler, |
| 84 | timeout, clearTimeout, reject, signal); |
| 85 | kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation; |
| 86 | signal.addEventListener('abort', oncancel, { __proto__: null, [kResistStopPropagation]: true }); |
| 87 | } |
| 88 | return oncancel !== undefined ? |
| 89 | SafePromisePrototypeFinally( |
| 90 | promise, |
| 91 | () => signal.removeEventListener('abort', oncancel)) : promise; |
| 92 | } |
| 93 | |
| 94 | function setImmediate(value, options = kEmptyObject) { |
| 95 | try { |
no test coverage detected