Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@channel/timers
Advanced tools
This package is experimental!
Cancelable timers, implemented with channels
For more information, visit channel.js.org.
function delay(wait: number): Channel<number>;
delay
returns a channel which yields Date.now()
wait
milliseconds after next
is called. Each call to next
runs an independent timer. All outstanding timers can be canceled by calling return
.
function timeout(wait: number): Channel<undefined>;
timeout
returns a channel which rejects with a TimeoutError
if the channel does not receive another call to next
or return
after the specified wait
. This behavior is useful when you want to place a fixed upper bound on how long each iteration of an async iterator can take with Channel.race
.
import { Channel } from "@channel/channel";
import { timeout } from "@channel/timers";
const chan = new Channel(async (push) => {
await push(1);
await push(2);
await new Promise((resolve) => setTimeout(resolve, 2000));
await push(3);
});
try {
(async () => {
for await (const num of Channel.race([chan, timeout(1000)])) {
console.log(num); // 1, 2
}
})();
} catch (err) {
console.log(err); // TimeoutError: 1000 ms elapsed
}
function interval(wait: number, buffer?: ChannelBuffer<number>): Channel<number>;
interval
returns a channel which resolves with the current timestamp every wait
milliseconds. The timer does not start until you call next
on the returned iterator, and can be canceled by calling return
.
FAQs
Cancelable timers, implemented with channels
We found that @channel/timers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.