https://github.com/fabiospampinato/promise-resolve-timeout
Create a Promise which will resolve with the provided value after a timeout.
https://github.com/fabiospampinato/promise-resolve-timeout
promise resolve timeout
Last synced: 9 months ago
JSON representation
Create a Promise which will resolve with the provided value after a timeout.
- Host: GitHub
- URL: https://github.com/fabiospampinato/promise-resolve-timeout
- Owner: fabiospampinato
- License: mit
- Created: 2019-08-27T12:54:08.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-01-12T18:38:26.000Z (over 1 year ago)
- Last Synced: 2025-07-27T16:51:06.662Z (10 months ago)
- Topics: promise, resolve, timeout
- Language: JavaScript
- Size: 11.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Promise Resolve Timeout
Create a Promise which will resolve with the provided value after a timeout.
## Install
```sh
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.
```ts
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