Skip to content

Instantly share code, notes, and snippets.

@Muscipular
Created November 8, 2016 02:47
Show Gist options
  • Save Muscipular/ee10f903d9ad460d086bc534361b9f69 to your computer and use it in GitHub Desktop.
Save Muscipular/ee10f903d9ad460d086bc534361b9f69 to your computer and use it in GitHub Desktop.
window.execEx = function(fn, maxTime) {
return new Promise(function (resolve, reject) {
var timer = setTimeout(function () {
if(timer) {
timer = false;
console.log('reject');
reject();
}
}, maxTime);
var f = function() {
if(timer) {
timer = false;
console.log('resolve')
resolve();
clearTimeout(timer);
}
};
fn(f);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment