All Projects → brummelte → Sleep Promise

brummelte / Sleep Promise

Licence: mit
Resolves a promise after a specified delay.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Sleep Promise

Promise
Promise-在Java中以同步的方式异步编程
Stars: ✭ 20 (-66.67%)
Mutual labels:  promise
Breeze
Javascript async flow control manager
Stars: ✭ 38 (-36.67%)
Mutual labels:  promise
Before After Hook
wrap methods with before/after hooks
Stars: ✭ 49 (-18.33%)
Mutual labels:  promise
Franticapparatus
Type and memory safe promises for Swift, supports cancellation
Stars: ✭ 27 (-55%)
Mutual labels:  promise
Bluebird Api
Bluebird compatible API on top of native promises.
Stars: ✭ 36 (-40%)
Mutual labels:  promise
Node Qiniu Sdk
七牛云SDK,使用 ES2017 async functions 来操作七牛云,接口名称与官方接口对应,轻松上手,文档齐全
Stars: ✭ 44 (-26.67%)
Mutual labels:  promise
Tiny Qiniu
A tiny qiniu sdk for uploading file.
Stars: ✭ 15 (-75%)
Mutual labels:  promise
Ws Wrapper
Lightweight WebSocket lib with socket.io-like event handling, requests, and channels
Stars: ✭ 58 (-3.33%)
Mutual labels:  promise
Fritzbox.js
☎️ The leading AVM Fritz!Box API for NodeJS and JavaScript.
Stars: ✭ 36 (-40%)
Mutual labels:  promise
Fs Readfile Promise
Promisified version of fs.readFile
Stars: ✭ 48 (-20%)
Mutual labels:  promise
Promise.hpp
C++ asynchronous promises like a Promises/A+
Stars: ✭ 31 (-48.33%)
Mutual labels:  promise
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (-43.33%)
Mutual labels:  promise
School Kr
🍚🍴 전국 교육청 급식, 학사일정 파싱 라이브러리
Stars: ✭ 44 (-26.67%)
Mutual labels:  promise
Assertive
Assertive is a terse yet expressive assertion library
Stars: ✭ 21 (-65%)
Mutual labels:  promise
Download
Download and extract files
Stars: ✭ 1,064 (+1673.33%)
Mutual labels:  promise
Zcoil
Elegant access to data
Stars: ✭ 20 (-66.67%)
Mutual labels:  promise
Node Pg Async
PostgreSQL 🐘 client for node.js designed for easy use with ES7 async/await based on node-postgres
Stars: ✭ 41 (-31.67%)
Mutual labels:  promise
Angular1 Async Filter
Angular2 async pipe implemented as Angular 1 filter to handle promises & RxJS observables
Stars: ✭ 59 (-1.67%)
Mutual labels:  promise
Gollback
Go asynchronous simple function utilities, for managing execution of closures and callbacks
Stars: ✭ 55 (-8.33%)
Mutual labels:  promise
Emacs Async Await
Async/Await for Emacs
Stars: ✭ 47 (-21.67%)
Mutual labels:  promise

sleep-promise License NPM version NPM downloads Build Coverage

sleep-promise resolves a promise after a specified delay.

Installation

node.js

npm install sleep-promise

Usage async / await

import sleep from 'sleep-promise';

(async () => {
    await sleep(2000);
    console.log('2 seconds later …');
})();

Usage ES5

var sleep = require('sleep-promise');

sleep(2000).then(function() {
    console.log('2 seconds later …');
});

Usage in a promise chain

import sleep from 'sleep-promise';

let trace = value => {
    console.log(value);
    return value;
};

sleep(2000)
    .then(() => 'hello')
    .then(trace)
    .then(sleep(1000))
    .then(value => value + ' world')
    .then(trace)
    .then(sleep(500))
    .then(value => value + '!')
    .then(trace);

// [2 seconds sleep]
// hello
// [1 second sleep]
// hello world
// [500 ms sleep]
// hello world!

Usage in a test file that mocks setTimeout

import sinon from 'sinon';
import sleep from 'sleep-promise';

const clock = sinon.useFakeTimers();

(async () => {
    // 2 seconds faked by sinon
    const sleepPromise = sleep(2000);
    clock.tick(2000);
    await sleepPromise;
    console.log('instant');

    // Caches global setTimeout before sinon replaced it
    const sleepPromise2 = sleep(2000, { useCachedSetTimeout: true });
    clock.tick(2000);
    await sleepPromise2;
    console.log('2 seconds later');
})();

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].