Provides timing of promises.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
README.md
circle.yml
index.js
package.json

README.md

Circle CI

promise-timer

Provides timing of promises.

  • timeify(func, logFunc, scope) - Returns the function wrapped with timing
  • timeifyAll(target, logFunc, options) - Patches all the target's methods with timing

These have similar definitions to bluebird's promisify:

Examples

npm install promise-timer
var Promise = require('bluebird');
require('promise-timer')(Promise);
var superagent = require('superagent');
var agent = require('superagent-promise')(superagent, Promise);

var API = {
    getUsersAsync: function() { 
        return agent.get('/users/').end();
    },
    getDriversAsync: function() {
        return agent.get('/drivers/').end();
    },
    getDriverAsync: function(driverId) {
        return agent.get('/drivers/' + driverId).end();
    }
};

Promise.timeifyAll(API, function(fnName, timeData) {
    console.log(timeData, "Called " + fnName);
    /*
    e.g. timeData = 
    {
        start: 1453746070761,
        end: 1453746070914,
        elapsed: 153,
        called: "getDriverAsync(100)"
    }
    */
}, /* optional */ {
    suffix: 'Timed', // or leave empty to override methods,
    filter: function(name, func, target, passesDefaultFilter) { // optional filter
        return _.includes(['getUsersAsync', 'getDriversAsync'], name);
    }
});

Or for single functions:

var getDriversAsyncTimed = Promise.timeify(API.getDriversAsync, function(fnName, timeData) {
    console.log(timeData, "Called " + fnName);
}, API);