safecallback

Handle callback errors safely and easily

SafeCallback

Handle asynchronous callback errors safely and easily

  1. Install Node.js
  2. npm install --save safecallback
  1. See Browserify
// Before 
var getFileContentsUpperCased = function(path,next){
    require('fs').readFile(path, function(err,data){
        if(err)  return next(err)
        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())
    }))
}
# Before 
getFileContentsUpperCased = (path,next) ->
    require('fs').readFile path(err,data) ->
        return next(err)  if err
        return next(nulldata.toString().toUpperCase())
 
# After 
safeCallback = require('safecallback')
getFileContentsUpperCased = (path,next) ->
    require('fs').readFile pathsafeCallback next(err,data) ->
        return next(nulldata.toString().toUpperCase())

You can discover the history inside the History.md file

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