Get unlimited public & private packages + team-based management with npm Teams.Learn more »

safecallback

1.0.1 • Public • Published

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(nulldata.toString().toUpperCase())
 
# After 
safeCallback = require('safecallback')
getFileContentsUpperCased = (path,next) ->
    require('fs').readFile pathsafeCallback next(err,data) ->
        return next(nulldata.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

Keywords

none

Install

npm i safecallback

DownloadsWeekly Downloads

3,217

Version

1.0.1

License

none

Last publish

Collaborators

  • avatar