https://github.com/binki/promise-delay-ts
Simple Promise-returning delay()
https://github.com/binki/promise-delay-ts
Last synced: about 1 month ago
JSON representation
Simple Promise-returning delay()
- Host: GitHub
- URL: https://github.com/binki/promise-delay-ts
- Owner: binki
- License: mit
- Created: 2018-07-05T04:49:09.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-15T14:56:16.000Z (about 7 years ago)
- Last Synced: 2025-02-11T03:07:40.822Z (over 1 year ago)
- Language: TypeScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Very simple delay with TypeScript typing which may be consumed by JavaScript.
# Usage
This is an ES module which may consumed from TypeScript or JavaScript.
Note that if you are consuming it via commonjs `require()`, the function will be available on the `default` export.
```ts
import delay from 'promise-delay-ts';
(async () => {
console.log(new Date());
await delay(1000);
console.log(new Date());
})();
```
To import in pure nodejs/commonjs, be sure to import the `default` property:
```js
const {
default: delay,
} = require('promise-delay-ts');
(async () => {
console.log(new Date());
await delay(1000);
console.log(new Date());
})();
```
# API
## `delay(delay:number):Promise`:
* `delay`: delay in milliseconds
Returns a `Promise` which will resolve after the delay.
The resolved value will be `undefined`.