🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

promise-timer

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-timer

Provides timing of promises.

1.0.0
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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);

FAQs

Package last updated on 26 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts