Giter VIP home page Giter VIP logo

awesome-only-resolves-last-promise's Introduction

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.

awesome-only-resolves-last-promise's People

Contributors

slorber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ecostack haigeno1

awesome-only-resolves-last-promise's Issues

index.d.ts missing

In a Next.js project I am working on, the jsconfig.json file is reporting the error below. Suspect it may that I am using a newer version of typescript? At any rate, it seems to be expecting the declaration of the types.

File 'c:/Users/mando/Projects/github.com/unfoldingWord/gateway-admin/node_modules/awesome-only-resolves-last-promise/dist/index.d.js' not found.
  The file is in the program because:
    Root file specified for compilation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.