safecallback
v1.0.1
Published
Handle callback errors safely and easily
Downloads
6,150
Readme
SafeCallback
Handle asynchronous callback errors safely and easily
Install
Backend
- Install Node.js
npm install --save safecallback
Frontend
Usage
JavaScript
// 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())
}))
}
CoffeeScript
# Before
getFileContentsUpperCased = (path,next) ->
require('fs').readFile path, (err,data) ->
return next(err) if err
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 [email protected]