Skip to content
/ stop.js Public

🐦 The Promise base `setTimeout`, release your callback

Notifications You must be signed in to change notification settings

rwu823/stop.js

Repository files navigation

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])

About

🐦 The Promise base `setTimeout`, release your callback

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published