import _ from '@/assets/scripts/lodash';

function InterceptorManager() {
	this.handlers = [];
}

InterceptorManager.prototype.add = function (resolveFn, rejectFn) {
	this.handlers.push({
		resolve: resolveFn,
		reject: rejectFn
	});
	return this.handlers.length - 1;
}

InterceptorManager.prototype.remove = function (id) {
	if (this.handlers[id]) {
		this.handlers[id] = null;
	}
}

InterceptorManager.prototype.forEach = function (fn) {
	_.forEach(this.handlers, (handler) => {
		if (handler !== null) {
			fn(handler);
		}
	});
}

export default InterceptorManager;