<commit_before>/* jslint node: true, esnext: true */

'use strict';

const Interceptor = require('./interceptor').Interceptor;

/**
 * Rejects a request if it does not resolve in a given time
 */
class TimeoutInterceptor extends Interceptor {
	static get name() {
		return 'timeout';
	}

	constructor(config, endpoint) {
		super(config, endpoint);

		Object.defineProperty(this, 'timeout', {
			value: config ? config.timeout : 1000
		});
	}

	toJSON() {
		const json = super.toJSON();
		json.timeout = this.timeout;
		return json;
	}

	receive(request) {
		return rejectUnlessResolvedWithin(this.connected.receive(request), this.timeout, this);
	}
}

/**
 *
 */
function rejectUnlessResolvedWithin(promise, timeout, name) {
	if (timeout === 0) return promise;

	return new Promise(function (fullfill, reject) {
		const th = setTimeout(() => {
			reject(new Error(`${name} request not resolved within ${timeout}ms`));
		}, timeout);

		return promise.then(fullfilled => {
			clearTimeout(th);
			fullfill(fullfilled);
		}, rejected => {
			clearTimeout(th);
			reject(rejected);
		});
	});
}


module.exports = TimeoutInterceptor;
<commit_msg>refactor: use arrow functions where possible<commit_after>/* jslint node: true, esnext: true */

'use strict';

const Interceptor = require('./interceptor').Interceptor;

/**
 * Rejects a request if it does not resolve in a given time
 */
class TimeoutInterceptor extends Interceptor {
	static get name() {
		return 'timeout';
	}

	constructor(config, endpoint) {
		super(config, endpoint);

		Object.defineProperty(this, 'timeout', {
			value: config ? config.timeout : 1000
		});
	}

	toJSON() {
		const json = super.toJSON();
		json.timeout = this.timeout;
		return json;
	}

	receive(request) {
		return rejectUnlessResolvedWithin(this.connected.receive(request), this.timeout, this);
	}
}

/**
 *
 */
function rejectUnlessResolvedWithin(promise, timeout, name) {
	if (timeout === 0) return promise;

	return new Promise((fullfill, reject) => {
		const th = setTimeout(() => {
			reject(new Error(`${name} request not resolved within ${timeout}ms`));
		}, timeout);

		return promise.then(fullfilled => {
			clearTimeout(th);
			fullfill(fullfilled);
		}, rejected => {
			clearTimeout(th);
			reject(rejected);
		});
	});
}

module.exports = TimeoutInterceptor;

{'fraction_non_alphanumeric': 0.14502164502164502, 'fraction_numerical': 0.004329004329004329, 'mean_word_length': 4.216704288939052, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '4791137', 'n_tokens_mistral': 796, 'n_tokens_neox': 712, 'n_words': 182}