last-promise
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

last-promise

Creates a function which will only ever resolve the promise of the latest function invocation. Useful to avoid updating UI with outdated data when a prior debounced function call resolves after one that was made after.

import { lastPromise } from "last-promise";

const fetchApiResult = lastPromise(() => {
  return fetch("https://httpbin.org/status/200");
});

// this will never resolve because the same function is called before it resolved
fetchApiResult();

// this will resolve
fetchApiResult();

Readme

Keywords

none

Package Sidebar

Install

npm i last-promise

Weekly Downloads

1

Version

0.0.1

License

ISC

Unpacked Size

12.4 kB

Total Files

16

Last publish

Collaborators

  • robin-drexler