Sha256: 196e21cb454cec9bbf929ef232dbf422c4ab09576ee252b20f5093a4bb410284

Contents?: true

Size: 1.6 KB

Versions: 25

Compression:

Stored size: 1.6 KB

Contents

"use strict";
module.exports = function(Promise) {
var util = require("./util.js");
var async = require("./async.js");
var tryCatch = util.tryCatch;
var errorObj = util.errorObj;

function spreadAdapter(val, nodeback) {
    var promise = this;
    if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
    var ret =
        tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
    if (ret === errorObj) {
        async.throwLater(ret.e);
    }
}

function successAdapter(val, nodeback) {
    var promise = this;
    var receiver = promise._boundValue();
    var ret = val === undefined
        ? tryCatch(nodeback).call(receiver, null)
        : tryCatch(nodeback).call(receiver, null, val);
    if (ret === errorObj) {
        async.throwLater(ret.e);
    }
}
function errorAdapter(reason, nodeback) {
    var promise = this;
    if (!reason) {
        var target = promise._target();
        var newReason = target._getCarriedStackTrace();
        newReason.cause = reason;
        reason = newReason;
    }
    var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
    if (ret === errorObj) {
        async.throwLater(ret.e);
    }
}

Promise.prototype.asCallback =
Promise.prototype.nodeify = function (nodeback, options) {
    if (typeof nodeback == "function") {
        var adapter = successAdapter;
        if (options !== undefined && Object(options).spread) {
            adapter = spreadAdapter;
        }
        this._then(
            adapter,
            errorAdapter,
            undefined,
            this,
            nodeback
        );
    }
    return this;
};
};

Version data entries

25 entries across 19 versions & 6 rubygems

Version Path
ilog-0.4.1 node_modules/bluebird/js/main/nodeify.js
ilog-0.4.0 node_modules/bluebird/js/main/nodeify.js
ilog-0.3.3 node_modules/bluebird/js/main/nodeify.js
proxy_chain_rb-0.1.2 lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
proxy_chain_rb-0.1.0 lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
browsed-0.3.1 lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
browsed-0.3.0 lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
browsed-0.2.9 lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
browsed-0.2.8 lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
browsed-0.2.7 lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
browsed-0.2.6 lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/bluebird/js/main/nodeify.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/bluebird/js/main/nodeify.js
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/fsevents/node_modules/node-pre-gyp/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/nodeify.js
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/bluebird/js/main/nodeify.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/bluebird/js/main/nodeify.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/fsevents/node_modules/node-pre-gyp/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/nodeify.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/bluebird/js/main/nodeify.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/fsevents/node_modules/node-pre-gyp/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/nodeify.js
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/bluebird/js/main/nodeify.js