1cedsoda / callbackhell-escape

An easy way to escape the callback-hell.

Home Page:https://www.npmjs.com/package/escape-the-cbh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

escape-the-cbh

An easy way to escape the callback-hell.

Installation

NPM

Usage

const Blocker = require("escape-the-cbh")

// set up a new blocker
let b = new Blocker()

// call a asynchronous function
setTimeout(function() {
    console.log("callback after 1 second")
    // release the blocker at the end of the callback
    b.release()
}, 1000);

//normal codeflow continues
console.log("not synchronized")

// blocking until release() is called
b.wait()
console.log("synchronized")

The Blocker can be (re)activated afterwards:

b.block()

So you can use one blocker to execute multiple asynchronous functions in a single synchronous codeflow.

About

An easy way to escape the callback-hell.

https://www.npmjs.com/package/escape-the-cbh

License:MIT License


Languages

Language:JavaScript 100.0%