0.0.1 • Published 3 years ago

last-promise v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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();