flushable
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/flushable package

1.0.0 • Public • Published

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.

import flushable from "flushable";
 
// prints a message to the console after 1 second
const operation = flushable(flushed => {
  console.log(`I completed ${flushed ? "early" : "on time"}`);
}, 1000);
 
// true if the callback has not been executed
operation.pending();
 
// stops the callback from being executed
operation.cancel();
 
// immediately executes the callback
operation.flush();

Reference

type Flushable = (
  (flushed: boolean) => any,
  delay: number
) => {
  cancel: () => void,
  flush: () => void,
  pending: () => boolean
};

Readme

Keywords

none

Package Sidebar

Install

npm i flushable

Weekly Downloads

4,993

Version

1.0.0

License

MIT

Unpacked Size

194 kB

Total Files

15

Last publish

Collaborators

  • petegleeson