Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 778 Bytes

File metadata and controls

44 lines (30 loc) · 778 Bytes

delay

Schedule a method to run after a fixed timeout. Unlike debounce, every call is still executed.

Import

import { delay } from "decorator-toolkit/delay";

For legacy TypeScript decorators, import from decorator-toolkit/delay/legacy or import { delay } from decorator-toolkit/legacy.

Signature

delay(delayMs: number)

Example

import { delay } from "decorator-toolkit/delay";

class Notifications {
	readonly events: string[] = [];

	@delay(1_000)
	show(message: string): void {
		this.events.push(message);
	}
}

Notes

  • delay is a method decorator.
  • Each call schedules its own timer.
  • The decorated method becomes fire-and-forget scheduled work.

Related