promise-resolve-timeout

Create a Promise which will resolve with the provided value after a timeout.

MIT 6 个版本
安装
npm install promise-resolve-timeout
yarn add promise-resolve-timeout
pnpm add promise-resolve-timeout
bun add promise-resolve-timeout
README

Promise Resolve Timeout

Create a Promise which will resolve with the provided value after a timeout.

Install

npm install promise-resolve-timeout

Usage

If the passed value is a function it will be called and its return value will be the resolved value, otherwise the passed value is the resolved value.

import resolveTimeout from 'promise-resolve-timeout';

// Defaulting to a default value when racing promises

Promise.race ([
  resolveTimeout ( 1000, false ), // Resolving after 1000ms
  resolveTimeout ( 5000, () => 'foo' ), // Resolving after 5000ms
  new Promise ( () => {
    // Something...
  });
]);

// Delaying

resolveTimeout ( 1000 ) // Waiting 1000ms
  .then ( () => {
    // Something...
  });

License

MIT © Fabio Spampinato

版本列表
2.0.1 2025-01-12
2.0.0 2022-04-07
1.2.1 2020-03-22
1.2.0 2019-08-28
1.1.0 2019-08-27
1.0.0 2019-08-27