lib/promised-node.js
function rebuildAsPromise(_thisObject, name, fn) {
    // if is a regular function, that has an async correspondent also make it promiseable
    if (!isFunctionAsync(_thisObject, name, fn)) {
        return function() {
            var that = this,
                args = arguments;

            return blinkts.lang.promiseCode(function() {
                return fn.apply(that, args);
            });
        };
    }

    // if it's an async function, make it promiseable.
    return function() {
		var args = Array.prototype.slice.apply(arguments),
			that = this;

		return new blinkts.lang.Promise(function(fulfill, reject) {
			args.push(function(err, r) {
				if (err) {
					reject(err);
				}

				if (arguments.length > 2) { // if the callback received multiple arguments, put them into an array.
					fulfill(Array.prototype.slice.call(arguments, 1));
				} else {
					fulfill(r);
				}
			});

			try {
				var result = fn.apply(that, args);
			} catch (e) { // if the function failed, so we don't get a chance to get our callback called.
				reject(e);
			}
		});
    };
}
function rebuildAsPromise(_thisObject, name, fn) {
    // if is a regular function, that has an async correspondent also make it promiseable
    if (!isFunctionAsync(_thisObject, name, fn)) {
        return function() {
            var that = this,
                args = arguments;

            return blinkts.lang.promiseCode(function() {
                return fn.apply(that, args);
            });
        };
    }

    // if it's an async function, make it promiseable.
    return function() {
		var args = Array.prototype.slice.apply(arguments),
			that = this;

		return new blinkts.lang.Promise(function(fulfill, reject) {
			args.push(function(err, r) {
				if (err) {
					reject(err);
				}

				if (arguments.length > 2) { // if the callback received multiple arguments, put them into an array.
					fulfill(Array.prototype.slice.call(arguments, 1));
				} else {
					fulfill(r);
				}
			});

			try {
				var result = fn.apply(that, args);
			} catch (e) { // if the function failed, so we don't get a chance to get our callback called.
				reject(e);
			}
		});
    };
}
function rebuildAsPromise ( _thisObject , name , fn ) { // if is a regular function, that has an async correspondent also make it promiseable if ( ! isFunctionAsync ( _thisObject , name , fn ) ) { return function ( ) { var that = this , args = arguments ; return blinkts . lang . promiseCode ( function ( ) { return fn . apply ( that , args ) ; } ) ; } ; } // if it's an async function, make it promiseable. return function ( ) { var args = Array . prototype . slice . apply ( arguments ) , that = this ; return new blinkts . lang . Promise ( function ( fulfill , reject ) { args . push ( function ( err , r ) { if ( err ) { reject ( err ) ; } if ( arguments . length > 2 ) { // if the callback received multiple arguments, put them into an array. fulfill ( Array . prototype . slice . call ( arguments , 1 ) ) ; } else { fulfill ( r ) ; } } ) ; try { var result = fn . apply ( that , args ) ; } catch ( e ) { // if the function failed, so we don't get a chance to get our callback called. reject ( e ) ; } } ) ; } ; }
Takes the current function and wraps it around a promise.
Takes the current function and wraps it around a promise .