Skip to content

Latest commit

 

History

History
74 lines (53 loc) · 1.44 KB

README.md

File metadata and controls

74 lines (53 loc) · 1.44 KB

version Build Status codecov

Stop.js

The Promise based setTimeout and setImmediate for the modern browsers and node.

‼️Important

stop.js change to use milliseconds as default unit. #1

Browser Supported

Why

In ES7 async/await is awesome, but that only supported with Promise.

Installation

npm i --save stop.js

Includes babel-polyfill before use async and await

Before

console.log(1)
setTimeout(()=>{
  console.log(2) // slow than 5 secs
}, 5000)

After

import stop from 'stop.js'

async function asyncFunc() {
  console.log(1)
  await stop(5000)
  console.log(2) // slow than 5 secs
}

asyncFunc()

setImmediate

0 is default, it'll call the YuzuJS/setImmediate library

console.log(1)
setImmediate(()=>{
  console.log(2)
})

same as

console.log(1)
await stop(0)
console.log(2)

or pass nothing

console.log(1)
await stop()
console.log(2)

API

stop([ms = 0])