`@push.rocks/smartdelay` is a tiny TypeScript utility for awaitable delays. It turns timer-based waiting into clean `async`/`await` code, supports passing values through delayed flows, can wait for a randomized duration, and exposes a cancellable `Timeout` class for cases where you need direct control over the underlying timer.
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
JavaScript already has `setTimeout`, but it is callback-based and returns a timer handle. `@push.rocks/smartdelay` gives you Promise-based primitives that fit naturally into modern TypeScript applications:
`delayFor` resolves after the requested number of milliseconds. It is useful for polling intervals, backoff windows, test timing, UI pacing, or any flow where a simple awaited pause is cleaner than callback scheduling.
The second argument is returned after the delay. This keeps typed values moving through async chains without adding temporary variables or custom wrappers.
`delayForRandom(minMs, maxMs)` waits for a random number of milliseconds between `minMs` and `maxMs`. This is handy for jitter in retry loops, test simulations, and avoiding synchronized bursts of repeated work.
`cancel()` clears the underlying timer. A cancelled timeout does not resolve its `promise`, so cancellation is best used when you intentionally stop waiting for that timer from another part of your code.
The optional third argument calls `unref()` on Node.js timer handles when available. That means the timer will not keep a Node.js process alive by itself. In browser environments, this is safely ignored because browser timer handles do not expose `unref()`.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.