Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/robojones/x-time

setTimeout() with native promises
https://github.com/robojones/x-time

javascript nodejs promise settimeout timeout xtime

Last synced: 23 days ago
JSON representation

setTimeout() with native promises

Awesome Lists containing this project

README

        

# x-time
setTimeout() with native promises

[![Build Status](https://travis-ci.org/robojones/x-time.svg?branch=master)](https://travis-ci.org/robojones/x-time)
[![Test Coverage](https://codeclimate.com/github/robojones/x-time/badges/coverage.svg)](https://codeclimate.com/github/robojones/x-time/coverage)

[![bitHound Code](https://www.bithound.io/github/robojones/x-time/badges/code.svg)](https://www.bithound.io/github/robojones/x-time)
[![bitHound Overall Score](https://www.bithound.io/github/robojones/x-time/badges/score.svg)](https://www.bithound.io/github/robojones/x-time)
[![bitHound Dependencies](https://www.bithound.io/github/robojones/x-time/badges/dependencies.svg)](https://www.bithound.io/github/robojones/x-time/master/dependencies/npm)
[![bitHound Dev Dependencies](https://www.bithound.io/github/robojones/x-time/badges/devDependencies.svg)](https://www.bithound.io/github/robojones/x-time/master/dependencies/npm)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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.