Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-sleep

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-sleep

Sleep based on promise

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34
increased by30.77%
Maintainers
1
Weekly downloads
 
Created
Source

async-sleep Build Status

Promise-based sleep that supports resolve and reject with defined results.

Install

npm i --save async-sleep

Usage:

Use sleep function directly:

import sleep from 'async-sleep'; // var sleep = require('async-sleep') also works 

const mock = {
  message: 'Hello world'
};

sleep(2000, mock).then(console.log); // { message: 'Hello world' }

Use resolve method:

import sleep from 'async-sleep';

const mock = {
  message: 'Hello world'
};

sleep.resolve(2000, mock).then(console.log); // { message: 'Hello world' }

Use reject method:

import sleep from 'async-sleep';

const mock = {
  error: 'Something went wrong...'
};

sleep.reject(2000, mock)
  .then(() => console.log('this message will never be shown'))
  .catch(console.log); // { error: 'Something went wrong...' }

Use randomResolve method:

import sleep from 'async-sleep';

const mock = {
  message: 'Hello world'
};

sleep.randomResolve(100, 1000, mock).then(console.log); // { message: 'Hello world' }

Use randomReject method:

import sleep from 'async-sleep';

const mock = {
  error: 'Something went wrong...'
};

sleep.randomReject(100, 1000, mock)
  .then(() => console.log('this message will never be shown'))
  .catch(console.log); // { error: 'Something went wrong...' }

API

sleep(ms, [result])
sleep.resolve(ms, [result]);
sleep.reject(ms, [error]);
sleep.randomResolve(minMs, maxMs, [result]);
sleep.randomReject(minMs, maxMs, [error]);

Author

Dmitry Pavlovsky

Keywords

FAQs

Package last updated on 03 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc