New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sleep-utils

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sleep-utils

sleep-utils is a utility package for handling asynchronous sleep operations in both JavaScript (JS) and TypeScript (TS) environments. It provides functions to pause the execution of code for a specified amount of time, making it useful in scenarios where

  • 1.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
76
increased by850%
Maintainers
1
Weekly downloads
 
Created
Source

sleep-utils

sleep-utils is a utility package for handling asynchronous sleep operations in both JavaScript (JS) and TypeScript (TS) environments. It provides functions to pause the execution of code for a specified amount of time, making it useful in scenarios where you need to introduce delays or pauses in your applications.

Installation

You can install sleep-utils using npm:

 npm install sleep-utils

Usage

import { sleep, sleepSeconds, sleepMinutes, sleepUntil, sleepRandom } from 'sleep-utils';

async function exampleUsage() {
  await sleep(1000); // sleeps for 1 second
  await sleepSeconds(2); // sleeps for 2 seconds
  await sleepMinutes(5); // sleeps for 5 minutes

  const futureTimestamp = Date.now() + 5000; // 5 seconds from now
  await sleepUntil(futureTimestamp);

  await sleepRandom(1000, 5000); // sleeps for a random time between 1 and 5 seconds
}

exampleUsage();

API

sleep(milliseconds: number): Promise

Delays the execution of the code for the specified number of milliseconds.

sleepSeconds(seconds: number): Promise

Delays the execution of the code for the specified number of seconds.

sleepMinutes(minutes: number): Promise

Delays the execution of the code for the specified number of minutes.

sleepUntil(timestamp: number): Promise

Delays the execution of the code until the specified timestamp (in milliseconds since the Unix epoch).

sleepRandom(min: number, max: number): Promise

Delays the execution of the code for a random amount of time within the specified range.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Keywords

FAQs

Package last updated on 16 Jan 2024

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