🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

femur

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

femur

Wrap a function with a timer

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

femur

femur is used to wrap a function so as to provide an execution timer. When wrapping a function with femur, you provide a callback to which femur will pass the function execution duration. As such, make sure your duration callback is asynchronous.

Install

$ npm install femur --save

Usage

Wrapping functions

The main point of femur is to be able to provide an execution duration logger when initially wrapping a function. As such, using femur is pretty simple.

const femur = require('femur');

function durationLogger(duration) {
  console.log(duration);
}

function max(a, b) {
  return Math.max(a, b);
}


// Wrapping synchronous functions is simple.
let wrappedMax = femur.wrap(max, durationLogger);
wrappedMax(4, 5); // returns 5 and logs the duration to the console


// Wrapping asynchronous functions is just as easy.
function asyncMax(a, b, cb) {
  cb(Math.max(a, b));
}

let asyncWrappedMax = femur.wrap(asyncMax, durationLogger);
// As a note on ordering, the below will log the duration to the console first,
// and then it will log 5 to the console.
asyncWrappedMax(4, 5, (val) => {
  console.log(val);
});

Release History

*1.0.0 Initial release.

Keywords

function

FAQs

Package last updated on 12 Oct 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