Created
April 19, 2020 20:44
-
-
Save snewcomer/c92251a1069042e1a5d4881d5fc82290 to your computer and use it in GitHub Desktop.
Promise timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put at top of bin/www to capture promise times