brummelte / Sleep Promise
Licence: mit
Resolves a promise after a specified delay.
Stars: ✭ 60
Programming Languages
javascript
184084 projects - #8 most used programming language
Labels
Projects that are alternatives of or similar to Sleep 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
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
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (-43.33%)
Mutual labels: promise
Assertive
Assertive is a terse yet expressive assertion library
Stars: ✭ 21 (-65%)
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
sleep-promise
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
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].