You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
645 B
JavaScript

'use strict';
module.exports = function(timeout = 60) {
let rejections = [];
return {
register: function(errorData) {
rejections.push(errorData);
setTimeout(() => {
this.unregister(errorData);
}, timeout * 1000);
},
unregister: function(errorData) {
let errorIndex = rejections.indexOf(errorData);
if (errorIndex !== -1) {
rejections.splice(errorIndex, 1);
}
},
exists: function(errorData) {
return rejections.some((item) => item.promise === errorData.promise && item.error === errorData.error);
},
find: function(promise) {
return rejections.find((item) => item.promise === promise);
}
}
}