safecallback

Handle callback errors safely and easily

npm install safecallback
59 downloads in the last day
202 downloads in the last week
898 downloads in the last month

SafeCallback Build Status

Handle asynchronous callback errors safely and easily

Install

Backend

  1. Install Node.js
  2. npm install --save safecallback

Frontend

  1. See Browserify

Usage

JavaScript

// Before
var getFileContentsUpperCased = function(path,next){
    require('fs').readFile(path, function(err,data){
        if(err)  return next(err)  // annoying check
        return next(null, data.toString().toUpperCase())
    })
}

// After
var safeCallback = require('safecallback')
var getFileContentsUpperCased = function(path,next){
    require('fs').readFile(path, safeCallback(next, function(err,data){
        return next(null, data.toString().toUpperCase())
    }))
}

CoffeeScript

# Before
getFileContentsUpperCased = (path,next) ->
    require('fs').readFile path, (err,data) ->
        return next(err)  if err  # annoying check
        return next(null, data.toString().toUpperCase())

# After
safeCallback = require('safecallback')
getFileContentsUpperCased = (path,next) ->
    require('fs').readFile path, safeCallback next, (err,data) ->
        return next(null, data.toString().toUpperCase())

History

You can discover the history inside the History.md file

License

Licensed under the incredibly permissive MIT License
Copyright © 2013+ Bevry Pty Ltd us@bevry.me

npm loves you