Skip to content

fabiospampinato/promise-resolve-timeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promise Resolve Timeout

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

Install

npm install --save 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published