Giter VIP home page Giter VIP logo

sleep-utils's Introduction

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

sleep-utils's People

Contributors

adarshhatkar avatar

Stargazers

Rushikesh Manjre avatar  avatar Vijay Hiwale avatar Vaibhav Nimkarde avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.