callback-as-promised

    0.0.1 • Public • Published

    callback-as-promised

    Don't make promises you can't keep.

    Develop with promises and expose, both, a callback and a promise interface.

    var callbackAsPromised = require('callback-as-promised');
     
    var CourteousClient = function() {};
     
    CourteousClient.prototype.doSomethingAsync = callbackAsPromised(function(successful) {
      var deferred = new Deferred();
      setTimeout(function() {
        if (successful) {
          deferred.resolve('very successful');
        } else {
          deferred.reject(new Error("wasn't successful"));
        }
      }, 500);
      return deferred.promise;
    });
     
    var courteousClient = new CourteousClient();
     
    courteousClient.doSomethingAsync(true, function(err, result) {
      if (err) {
        // handle error
      }
      // handle success
    });
     
    courteousClient.doSomethingAsync(true).then(function(result) {
      // handle success
    }, function(error) {
      // handle error
    });

    Keywords

    none

    Install

    npm i callback-as-promised

    DownloadsWeekly Downloads

    1

    Version

    0.0.1

    License

    Apache 2

    Last publish

    Collaborators

    • joanc
    • xiao-square
    • jguze-sq
    • square-owner
    • adrw
    • square-developers
    • matahwoosh
    • hirokiosame
    • bmishkin
    • dpapastrat
    • maxbeatty
    • linnea
    • pretzelhammer
    • alexandersmanning
    • steckel