Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 771 Bytes

README.md

File metadata and controls

29 lines (21 loc) · 771 Bytes

pinkyPromise

pinkyPromise is an ultra-bare-bones promises library intended to provide insight into the inner workings of JavaScript promises. It is not spec-compliant or meant for production use.

The original blog post: pinkyPromise: JavaScript Promises in 45 Lines of Code.

Usage

//  take an async function
function incrementAsync(n, cb) {  
    setTimeout(function() {
        cb(n + 1);
    }, 100);
}

// pinkyPromise it!
var incrementAsyncPromise = pinkyPromise(incrementAsync);

var data = 1;

incrementAsyncPromise(data)  
    .then(incrementAsyncPromise)
    .then(incrementAsyncPromise)
    .then(function(n) {
        console.log(n) // => 4
    });