flushable
flushable
is useful in situations where you want to schedule a future operation that might be executed immediately or cancelled. Think setTimeout
with a way of executing the callback immediately.
Installation
yarn add flushable
Usage
Create a pending operation by passing flushable
a callback function and a delay. It returns an object that can be used to check the status of the operation, cancel the operation or execute the operation immediately.
; // prints a message to the console after 1 secondconst operation = ; // true if the callback has not been executedoperation; // stops the callback from being executedoperation; // immediately executes the callbackoperation;
Reference
type Flushable = any delay: number void void boolean;