JSPM

  • Created
  • Published
  • Downloads 15159795
  • Score
    100M100P100Q207578F
  • License MIT

A minimal and fast promise/deferred implementation

Package Exports

  • lie

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lie) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lie

Promises/A+ logo

lie is a JavaScript promise/deferred implementation, implementing the Promises/A+ spec.

A fork of Ruben Verborgh's library called promiscuous. Which takes advantage of my immediate library, uses object constructors, and with a name I can actually consistently spell. Plus if I learned anything from catiline (formally communist) it's that you don't want to pick an even mildly offensive name.

API

by defailt adds a function called 'deferred' to the global scope (or if you grab the noConflict version than one called lie)

return a promise

function waitAwhile
    var def = deferred();

    setTimeout(function(){
        def.resolve('DONE!');
    },10000);//resolve it in 10 secons

    return def.promise//return the promise
}

Create a resolved promise

var one = deferred.resolve("one");
one.then(console.log);
/* one */

Create a rejected promise

var none = deferred.reject("error");
none.then(console.log, console.error);
/* error */

Write a function turns node style callback to promises

function denodify(func) {
  return function(){
    var args = Array.prototype.concat.apply([],arguments);
    var def = deferred();
    args.push(function(err,success){
        if(err) {
            def.reject(err);
        } else {
            def.resolve(success);
        }
    });
    function.apply(undefined,args);
    return def.promise;
  }
}

##node

install with npm install lie, exactly the same as above but

var deferred = require('lie');
var resolve = deferred.resolve;
var reject = deferred.reject;