Giter Site home page Giter Site logo

node-callme's Introduction

node-callme

* Abandoned *

Hey I just met you, and this is crazy, but here's my callback, so definitely call it once, and once only.

This tiny module is meant to help debug pesky asynchronous code by making sure your callbacks are called just once. It also checks if the given callback is undefined or if it's called in the same event loop.

This is meant to be used during testing, not production code. But could be used to help debug.

Build Status Dependency Status

Usage

var callme = require('callme');

function asyncMethod(a, b, callback) {
  callback = callme(callback);

  someIO(a, b, function(err, result) {
    if (err) callback(err);
    
    result = permuteTheResult(result);

    // this will throw if there is an error since it will be
    // the second time the callback is called.
    // a `return` was forgotten on the error check above.
    callback(err, result);
  });
}

The callme function returned is also an instance of EventEmitter. If you prefer to listen to the error event instead, you can do so.

function asyncMethod(a, b, callback) {
  callback = callme(callback);
  callback.on('error', function(err) {
    // do something with `err`
  });

  someIO(a, b, function() {
    // etc
  });
}

It also supports a timeout option, make sure your callbacks are definitely called.

function asyncMethod(a, b, callback) {
  callback = callme(callback, 2000); // set timeout to 2 seconds

  callback.on('error', function(err) {
    // this will fire in 2 seconds since `callback` is never called
  });
}

Install

npm install callme

Tests

Tests are written with mocha

npm test

License

MIT

node-callme's People

Contributors

fent avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.