<commit_before>'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');
}
<commit_msg>simplify implementation<commit_after>'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 callback;
	var promise;
	if (Promise) {
		promise = new Promise(function (resolve, reject) {
			callback = makeResolver(resolve, reject, cb);
		});
		if (cb) {
			// Suppress 'unhandledRejection' events - assume the callback handles them.
			promise.catch(function () {});
		}
	} else if (cb) {
		callback = cb;
	} else {
		throw new Error('No Promise Implementation: Install bluebird, upgrade to Node >= 0.11.13, or use a callback');
	}

	return {
		cb: callback,
		resolve: callback.bind(null, null),
		reject: callback,
		promise: promise
	};
}

{'fraction_non_alphanumeric': 0.14151365875503807, 'fraction_numerical': 0.0044782803403493054, 'mean_word_length': 3.7130801687763713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6084521', 'n_tokens_mistral': 818, 'n_tokens_neox': 742, 'n_words': 211}