Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hug

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

hug

Wrap functions with before and after functions to observe system state

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
49
increased by28.95%
Maintainers
1
Weekly downloads
 
Created
Source

Wrap functions with before and after functions in order to perform measurements. This code is written to work using node callback style and assumes that if the last argument passed to a function is a function, then it is a callback function and the wrapped function is an asynchronous function.

var hug = require('hug');
var runCount = 0;

var after = function(start, duration) {
  console.log('This function took '+duration+' ms to run');
  runCount++;
}
var function = someAsyncFunction(callback) {
  // Do Work...
  callback();
}

var wrapped = hug(someAsyncFunction, null, null, after);
wrapped(function() {});

API

hug(fun, context, before, after)

Returns a wrapped function

  • fun - the function to wrap
  • context - the execution context (this)
  • before - function() to run before the wrapped function is executed
  • after - function(start, duration) to run after the wrapped function is executed
    • start is the time when the wrapped function was called
    • duration is the execution time of the wrapped function in ms

Note that while the after function is called after the wrapped function, it is called before the callback when an async function is wrapped.

RUN TESTS

// install mocha
npm install mocha
mocha --reporter spec test/hug.js

FAQs

Package last updated on 19 Nov 2012

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc