1.0.0 • Published 5 years ago

waiiit v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Waiit

When you need to wait for a specified amount of time before doing something or want to show something immediately.

Here is a simple function which does the job based on Promise.

Example

wait() // Returns a promise that resolves immediately.

wait(5000) // Returns a promise that resolves after 5000 milliseconds.

Install

// To install as a development package depencency
npm install -D waiit

// To install as a production package depencency
npm install -P waiit

// To install as a global package
npm install -g waiit

Usage

// Importing the package `waiit`
import wait from 'wait';

//  Using async/await
async function doSomething () {
  console.log ( `Starting....` );
  await wait ( 5000 ); // Returns a promise that resolves after 5000 milliseconds.
  console.log ( `Waiting....` );
  await wait (); // Returns a promise that resolves immediately.
  console.log ( `Finished....` );
}
doSomething ();

// Using instance method .then()
wait ()
  .then ( () => {
    console.log ( `Starting....` );
    return wait ( 5000 ); // Returns a promise that resolves after 5000 milliseconds.
  } )
  .then ( () => {
    console.log ( `Waiting....` );
    return wait ( 2000 ); // Returns a promise that resolves immediately.
  } )
  .then ( () => {
    console.log ( `Finished....` );
  } );