Saltar al contenido

Referencia de la API node:timers

API de temporizadores basadas en funciones de retorno y en Promise

En esta página

node:timers exporta temporizadores con funciones de retorno: setTimeout / clearTimeout, setInterval / clearInterval y setImmediate / clearImmediate. Ofrecen la misma API que los globales de temporizador, pero no son los mismos objetos de función JavaScript. No se exponen los métodos heredados active() y unenroll().

node:timers/promises

ExportaciónPropósito
setTimeout(delay?, value?, options?)Se resuelve con value tras el retardo.
setImmediate(value?, options?)Se resuelve en un turno inmediato.
setInterval(delay?, value?, options?)Produce un iterador asíncrono.
schedulerProporciona wait() y yield().

Los temporizadores con Promise aceptan un AbortSignal y se rechazan con AbortError cuando se aborta. Los temporizadores pendientes, con funciones de retorno o con Promise, mantienen vivo un proceso elide run independiente hasta que terminan.

Véase también

Reference

Status: Full · 54 of 57 suite tests pass (94.7%) · since 1.1.0

Exports

ExportKindStatusNotes
setTimeout()functionFullSchedules a callback to be invoked once after delay milliseconds
clearTimeout()functionFullCancels a timeout previously established by setTimeout()
setInterval()functionFullSchedules a callback to be invoked repeatedly every delay milliseconds
clearInterval()functionFullCancels an interval previously established by setInterval()
setImmediate()functionFullSchedules a callback to be invoked asynchronously “immediately” (after I/O events but before timers…
clearImmediate()functionFullCancels an immediate action previously established by setImmediate()

Tests: node-api node:timers: 54 pass, 3 fail, 0 error, 10 skipped. Failing: test-timers-max-duration-warning.js, test-timers-timeout-to-interval.js, test-timers-unenroll-unref-interval.js.

¿Te resultó útil esta página?