Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/yoctodelay
Delay a promise a specified amount of time
https://github.com/sindresorhus/yoctodelay
Last synced: about 1 month ago
JSON representation
Delay a promise a specified amount of time
- Host: GitHub
- URL: https://github.com/sindresorhus/yoctodelay
- Owner: sindresorhus
- License: mit
- Created: 2017-10-22T11:18:52.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2021-10-01T08:55:07.000Z (about 3 years ago)
- Last Synced: 2024-04-13T17:56:41.726Z (7 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 114
- Watchers: 4
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- promise-fun - yoctodelay
README
# yoctodelay
> Delay a promise a specified amount of time
It's less than half the size of the [`nanodelay`](https://github.com/ai/nanodelay) module.
**Note:** If you target Node.js 16 or later, you can use the built-in functionality instead:
```js
import {setTimeout as delay} from 'node:timers/promises';await delay(100);
```## Install
```
$ npm install yoctodelay
```## Usage
```js
import delay from 'yoctodelay';foo();
await delay(100);
// Executed 100 milliseconds later
bar();
```## API
### delay(milliseconds)
Delay the promise and then resolve.
#### milliseconds
Type: `number`
The duration to delay the promise.
## FAQ
### What is yocto?
[It's the smallest official unit prefix in the metric system.](https://en.wikipedia.org/wiki/Yocto-) Much smaller than nano.
### Is this a joke?
Partly. The `nanodelay` module was created only because the `delay` module is a tiny bit larger. Well, this module is a tiny bit smaller than the `nanodelay` module. Comparing size at the byte level is super silly. It doesn't matter unless the difference is more than many kilobytes. This is still a fully working module though. Go ahead and use it.
## Related
- [delay](https://github.com/sindresorhus/delay) - Similar to this module but with more features
- [yoctocolors](https://github.com/sindresorhus/yoctocolors) - The smallest and fastest command-line coloring package on the internet
- [More…](https://github.com/sindresorhus/promise-fun)