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

sleep-promise

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sleep-promise

Resolves a promise after a specified delay.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
191K
decreased by-13.84%
Maintainers
1
Weekly downloads
 
Created

What is sleep-promise?

The 'sleep-promise' npm package provides a simple way to pause the execution of asynchronous code for a specified duration. It returns a promise that resolves after the given time, making it useful for delaying operations in a non-blocking manner.

What are sleep-promise's main functionalities?

Basic Sleep

This feature allows you to pause the execution of your code for a specified duration. In this example, the code pauses for 2 seconds between logging 'Start' and 'End'.

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

async function example() {
  console.log('Start');
  await sleep(2000); // Sleep for 2 seconds
  console.log('End');
}

example();

Sleep with Error Handling

This feature demonstrates how to handle errors that might occur during the sleep operation. Although 'sleep-promise' itself does not throw errors, this pattern is useful for more complex scenarios where other asynchronous operations might fail.

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

async function example() {
  try {
    console.log('Start');
    await sleep(2000); // Sleep for 2 seconds
    console.log('End');
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

example();

Other packages similar to sleep-promise

Keywords

FAQs

Package last updated on 07 Apr 2018

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