UNPKG

la-cosa-nostra

Version:

A Mafia bot designed to run in Discord - beware the traitors and the lies!

39 lines (27 loc) 746 B
module.exports = function (runnable, refuse, check=500, max=50) { if (typeof runnable !== "function") { var err = new Error("Runnable should be a function!"); throw err; }; if (!Array.isArray(refuse)) { var err = new Error("Refuse should be an array"); throw err; } return new Promise(function(resolve, reject) { var counts = 0; var interval = setInterval(function () { // Check if value is out var current = runnable(); if (!refuse.includes(current)) { clearInterval(interval); resolve(current); } else { counts++; if (counts > max) { clearInterval(interval); resolve(undefined); }; }; }, check); }); };