Skip to content

jimf/timeout-as-promise

Repository files navigation

timeout-as-promise

setTimeout as a native Promise.

npm Version Build Status Test Coverage Dependency Status

Installation

Install using npm:

$ npm install timeout-as-promise

Usage

const delay = require('timeout-as-promise');

delay().then(function() {
    console.log('nextTick!');
});

delay(5000).then(function() {
    console.log('5 seconds have passed!');
});

delay(5000, 'Jim').then(function(value) {
    console.log('my name is ' + value);
});

Promise.resolve(42)
    .then(function(result) {
        return delay(150, result);
    })
    .then(function(result) {
        console.log('result is ' + result); //=> 42
    });

Or using async/await

const delay = require('timeout-as-promise');

async function stop() {
    console.log('starting up');
    await delay(2000);
    console.log('2 seconds have passed');
}

stop();

License

MIT

About

setTimeout as a native Promise

Resources

License

Stars

Watchers

Forks

Packages

No packages published