Skip to content
0

katanakit-js / useSetTimeout

Function: useSetTimeout() ​

ts
function useSetTimeout<T>(callback, ms): TimeoutControl<T>;

Defined in: src/core/services/timing.service.ts:22

Executes a callback after ms milliseconds, returning a cancellable promise that resolves with the callback's result.

Type Parameters ​

Type ParameterDescription
TThe callback's return type.

Parameters ​

ParameterTypeDescription
callback() => T | Promise<T>Function to execute after the delay.
msnumberDelay in milliseconds.

Returns ​

TimeoutControl<T>

A TimeoutControl with promise and cancel().

Example ​

ts
const { promise, cancel } = useSetTimeout(() => 42, 1000);
cancel(); // rejects the promise with "Timeout cancelled"

Released under the MIT License.