Skip to content

timer

Creates an observable that emits 0 after a specified delay and then completes.

// Timeline:
//
// Time(ms) 0 ... 1000
// delayed$ X (emits and completes)
//
// Explanation:
// - timer emits once after the specified delay, then completes
// - Useful for delayed actions or timeouts
const delayed$ = timer(100);
const valueHistory: number[] = [];
await new Promise<void>((resolve) => {
delayed$.subscribe(
() => {
valueHistory.push(1);
},
() => {
resolve();
},
);
});
assert.deepStrictEqual(valueHistory, [1]);

View source on GitHub