Skip to content

Instantly share code, notes, and snippets.

@snewcomer
Created April 19, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snewcomer/c92251a1069042e1a5d4881d5fc82290 to your computer and use it in GitHub Desktop.
Save snewcomer/c92251a1069042e1a5d4881d5fc82290 to your computer and use it in GitHub Desktop.
Promise timer
let counter = 0;
class MyPromise extends Promise {
constructor(cb) {
const stack = (() => { try { throw new Error(); } catch (e) { return e; } })().stack;
const id = `promise ${counter++}`;
console.time(id);
super(function(resolve, reject) {
return cb.call(
this,
function() {
console.timeLog(id, 'RESOLVE', stack);
return resolve.apply(this, arguments);
},
function() {
console.timeLog(id, 'REJECT', stack);
return reject.apply(this, arguments);
}
);
});
}
}
Promise = MyPromise;
@snewcomer
Copy link
Author

Put at top of bin/www to capture promise times

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment