Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

awesome-only-resolves-last-promise

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

awesome-only-resolves-last-promise

Wraps an async function and ensure only last call will actually resolve/reject

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
89K
decreased by-11.6%
Maintainers
1
Weekly downloads
 
Created
Source

awesome-only-resolves-last-promise

NPM Build Status

Install

npm install --save awesome-only-resolves-last-promise
// or
yarn add awesome-only-resolves-last-promise

Features

  • Wraps an existing async function
  • When calling the wrapped function multiple times consecutively, only the last returned promise will resolve and formerly returned promises will be cancelled (they won't resolve nor reject)

Usage

import { onlyResolvesLast } from 'awesome-only-resolves-last-promise';

const asyncFunction = async (arg: number, arg2: string) => {
  await delay(100);
  return `val ${arg} ${arg2}`;
};

const wrappedAsyncFunction = onlyResolvesLast(asyncFunction);

const promise1 = wrappedAsyncFunction(1, '1');
const promise2 = wrappedAsyncFunction(2, '2');
const promise3 = wrappedAsyncFunction(3, '3');

// promise1 and promise2 will never resolve/reject
// promise3 will resolve in 100ms

Useful as an implementation detail of awesome-debounce-promise.

License

MIT © slorber

Hire a freelance expert

Looking for a React/ReactNative freelance expert with more than 5 years production experience? Contact me from my website or with Twitter.

FAQs

Package last updated on 26 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc