<commit_before>module.exports = function (tasks, options) {
	// validate the paramaters for basic sanity
	!options && (options = {});

	var /**
		 * Keep a track whether standard async flow was interrupted by time.
		 * @type {boolean}
		 */
		interrupted = false,
		/**
		 * Options for configuring the module.
		 * @type {object}
		 */
		opts = {
			protect: ('protect' in options) ? !!options.protect : true,
			timeout: isNaN(options.timeout) ? 2000 : Number(options.timeout),
			distribution: 'equal'
		};

	// iterate through all tasks and return an array of alternate tasks that can keep track of time.
	return tasks.map(function (task) {
		// instead of the original task, map the array to return wrapper functions.
		return function () {
			var args = Array.prototype.slice.call(arguments), // copy array
				done = args.length && args[args.length - 1],
				waiting; // flag to keep track of timer id

			// check whether there is actually a callback function. there should be one, but still edge-case validation
			// is to be done.
			if (done) {
				// if it is marked that the flow has been interrupted, then we exit waterfall with an error. this is 
				// unlikely to happen on first run, but may happen subsequently.
				if (interrupted) {
					return done(new Error('async interrupt timeout'));
				}

				// start a timeout and execute callback in it
				waiting = setTimeout(function () {
					waiting = null;
					done(new Error('async interrupt timeout'));
				}, opts.timeout); // @todo: add other time distribution types

				// modify the callback passed to the actual task so that the timeout can be stopped and original 
				// callback be called.
				args[args.length - 1] = function () {
					// if upon call of this wrapper callback, the timeout has already passed, then we do not call the 
					// actual callback and back off.
					if (!waiting) {
						// mark the interruption
						interrupted = true;
						return;
					}

					// at this point, timeout has not yet reached, hence we clear it and execute the callback while
					// passing on the original arguments.
					waiting = clearTimeout(waiting);
					done.apply(this, arguments);
				};
			}

			// if execution protection is turned on, we execute the task within a try block and then pass on the<commit_msg>Added secondary failsafe check to prevent double callback<commit_after>module.exports = function (tasks, options) {
	// validate the paramaters for basic sanity
	!options && (options = {});

	var /**
		 * Keep a track whether standard async flow was interrupted by time.
		 * @type {boolean}
		 */
		interrupted = false,
		/**
		 * Options for configuring the module.
		 * @type {object}
		 */
		opts = {
			protect: ('protect' in options) ? !!options.protect : true,
			timeout: isNaN(options.timeout) ? 2000 : Number(options.timeout),
			distribution: 'equal'
		};

	// iterate through all tasks and return an array of alternate tasks that can keep track of time.
	return tasks.map(function (task) {
		// instead of the original task, map the array to return wrapper functions.
		return function () {
			var args = Array.prototype.slice.call(arguments), // copy array
                // super ensure no double callback by wrapping the callback
                done = args.length && (function (cb) {
                    var once = false; // track call.
                    return function () {
                        !once && ((once = true), cb.apply(this, arguments));
                    };
                }(args[args.length - 1])),
                // flag to keep track of timer id
                waiting;

			// check whether there is actually a callback function. there should be one, but still edge-case validation
			// is to be done.
			if (done) {
				// if it is marked that the flow has been interrupted, then we exit waterfall with an error. this is
				// unlikely to happen on first run, but may happen subsequently.
				if (interrupted) {
					return done(new Error('async interrupt timeout'));
				}

				// start a timeout and execute callback in it
				waiting = setTimeout(function () {
					waiting = null;
					done(new Error('async interrupt timeout'));
				}, opts.timeout); // @todo: add other time distribution types

				// modify the callback passed to the actual task so that the timeout can be stopped and original
				// callback be called.
				args[args.length - 1] = function () {
					// if upon call of this wrapper callback, the timeout has already passed, then we do not call the
					// actual callback and back off.
					if (!waiting) {
						// mark the interruption
						interrupted = true;
						return;
					}

					// at this point, timeout has not yet reached, hence we clear it and execute the callback while
					// passing on the original arguments.
					waiting = clearTimeout(waiting);
					done.apply(this, arguments);
				};
			}

			// if execution protection is turned on, we execute the task within a try block and then pass on the
{'fraction_non_alphanumeric': 0.09294871794871795, 'fraction_numerical': 0.002403846153846154, 'mean_word_length': 2.5236414961185605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1485902', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1253, 'n_words': 587}