https://github.com/robojones/x-time
setTimeout() with native promises
https://github.com/robojones/x-time
javascript nodejs promise settimeout timeout xtime
Last synced: 27 days ago
JSON representation
setTimeout() with native promises
- Host: GitHub
- URL: https://github.com/robojones/x-time
- Owner: robojones
- License: mit
- Created: 2016-12-04T11:15:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-16T14:51:52.000Z (over 8 years ago)
- Last Synced: 2025-09-14T05:35:49.286Z (9 months ago)
- Topics: javascript, nodejs, promise, settimeout, timeout, xtime
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/x-time
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# x-time
setTimeout() with native promises
[](https://travis-ci.org/robojones/x-time)
[](https://codeclimate.com/github/robojones/x-time/coverage)
[](https://www.bithound.io/github/robojones/x-time)
[](https://www.bithound.io/github/robojones/x-time)
[](https://www.bithound.io/github/robojones/x-time/master/dependencies/npm)
[](https://www.bithound.io/github/robojones/x-time/master/dependencies/npm)
[](https://opensource.org/licenses/MIT)
## Installation
```
npm install x-time --save
```
## Example
```javascript
const xTime = require('x-time')
xTime(1000, 'one').then(value => {
console.log(`waited ${value} second`)
})
```
You can also `await` the x-time promise:
```javascript
await xTime(1000)
```
## Import in Typescript
The default import syntax of TypeScript does not work with this module because it exports a function directly.
You need to use the following syntax in order to get completions:
```typescript
import xTime = require('x-time')
```
## Function: xTime(time[, value])
- __time__ `` duration of timeout in ms
- __value__ `` value to resolve the promise with
Returns a promise that gets resolved to the __value__ when the __time__ has passed.