'use strict';
module.exports = makeResolver;
module.exports.defer = defer;
var bluebird = require('native-or-bluebird/promise');

function makeResolver(resolve, reject, cb) {
	var called = false;
	return function (err, result) {
		if (called) {
			return;
		}
		called = true;
		if (err && reject) {
			reject(err);
		} else if (resolve) {
			resolve(result);
		}
		if (cb) {
			cb.apply(null, arguments);
		}
	};
}

function defer(cb, Promise) {
	Promise = Promise || bluebird;
	var resolve = null;
	var reject = null;
	var promise;
	if (Promise) {
		promise = new Promise(function (_resolve, _reject) {
			resolve = _resolve;
			reject = _reject;
		});
	} else if (!cb) {
		noPromise();
	}
	var callback = makeResolver(resolve, reject, cb);
	if (cb && promise) {
		// Suppress 'unhandledRejection' events - assume the callback handles them.
		promise.catch(function () {});
	}
	return {
		cb: callback,
		resolve: callback.bind(null, null),
		reject: callback.bind(null),
		promise: promise
	};
}

function noPromise() {
	throw new Error('No Promise Implementation: Install bluebird, upgrade to Node >= 0.11.13, or use a callback');
}

@@ -481,42 +481,16 @@
 var 
-resolve = null;%0A%09var reject = null
+callback
 ;%0A%09v
@@ -551,17 +551,16 @@
 nction (
-_
 resolve,
@@ -560,17 +560,16 @@
 esolve, 
-_
 reject) 
@@ -577,97 +577,8 @@
 %0A%09%09%09
-resolve = _resolve;%0A%09%09%09reject = _reject;%0A%09%09%7D);%0A%09%7D else if (!cb) %7B%0A%09%09noPromise();%0A%09%7D%0A%09var 
 call
@@ -624,29 +624,26 @@
 );%0A%09
-if (cb && promise
+%09%7D);%0A%09%09if (cb
 ) %7B%0A
+%09
 %09%09//
@@ -718,16 +718,17 @@
 them.%0A%09%09
+%09
 promise.
@@ -750,19 +750,182 @@
 () %7B%7D);%0A
+%09%09%7D%0A%09%7D else if (cb) %7B%0A%09%09callback = cb;%0A%09%7D else %7B%0A%09%09throw new Error('No Promise Implementation: Install bluebird, upgrade to Node %3E= 0.11.13, or use a callback');%0A
 %09%7D%0A
+%0A
 %09return 
@@ -1002,19 +1002,8 @@
 back
-.bind(null)
 ,%0A%09%09
@@ -1029,142 +1029,4 @@
 ;%0A%7D%0A
-%0Afunction noPromise() %7B%0A%09throw new Error('No Promise Implementation: Install bluebird, upgrade to Node %3E= 0.11.13, or use a callback');%0A%7D%0A

simplify implementation