{"size": 647, "ext": "js", "max_stars_repo_path": "lib/callback-list.js", "max_stars_repo_name": "pachet/pirc", "max_stars_repo_stars_event_min_datetime": "2018-03-27T17:02:04.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T16:09:51.000Z", "max_issues_repo_path": "lib/callback-list.js", "max_issues_repo_name": "pachet/pirc", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/callback-list.js", "max_forks_repo_name": "pachet/pirc", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 15.0465116279, "max_line_length": 46, "alphanum_fraction": 0.6537867079}

var
	_add    = require('./utility/add'),
	_remove = require('./utility/remove'),
	extend  = require('./utility/extend');


class CallbackList {

	add(callback) {
		_add(callback).to(this.getCallbacks());
	}

	remove(callback) {
		_remove(callback).from(this.getCallbacks());
	}

	dispatch(error, result) {
		var callbacks = this.getCallbacks();

		this.callbacks = [ ];

		callbacks.forEach(function each(callback) {
			callback(error, result);
		});
	}

	getCallbacks() {
		if (!this.callbacks) {
			this.callbacks = [ ];
		}

		return this.callbacks;
	}

}

extend(CallbackList.prototype, {
	callbacks: null
});

module.exports = CallbackList;
