promise-stopwatch

Mesure a Promise resolution duration using Performance API with fallback to new Data()
.
var stopwatch = require('promise-stopwatch');
function resolveInOneSec() {
return new Promise(function(resolve, reject){
setTimeout(function(){
resolve('yay');
}, 1000);
});
}
var settings = {};
stopwatch(settings)(resolveInOneSec)().then(function(response){
var result = response.result;
var duration = response.duration;
var settings = response.settings;
console.log('Resolution took ' + duration + 'ms');
return result;
});
function rejectInOneSec() {
return new Promise(function(resolve, reject){
setTimeout(function(){
reject('nay');
}, 1000);
});
}
stopwatch(settings)(rejectInOneSec)().catch(function(response){
var error = response.error;
var duration = response.duration;
var settings = response.settings;
console.log('Rejection took ' + duration + 'ms');
throw error;
});
Options
None, for now, but it might come, so we keep this signature similar to other promise helper and be able to some without change the API.
See also
promise-stopwatch
composes really well with the following promise helper: