femto113 / node-callback-wrappers Goto Github PK
View Code? Open in Web Editor NEWfunction wrappers for callbacks that implement common, simple error handling scenarios
License: MIT License
function wrappers for callbacks that implement common, simple error handling scenarios
License: MIT License
I need to use the nextIfError function but the installed version from npm does not have it...
Here is the snapshot from my node repository
And below is the package.json from the same folder.
Thanks and good work!
{
"name": "callback-wrappers",
"version": "0.2.0",
"description": "wrappers for async callbacks that implement common error handling scenarios",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/femto113/node-callback-wrappers.git"
},
"keywords": [
"callback",
"async"
],
"author": {
"name": "Ken Woodruff",
"email": "[email protected]"
},
"license": "MIT",
"readmeFilename": "README.md",
"readme": "# callback-wrappers\n\nFunction wrappers for async callbacks that implement common, simple error handling scenarios.\n\n## Install\n\nbash\n npm install callback-wrappers\n
\n\n## Description\n\nMost async methods in the node world expect a callback with an (error, data)
signature.\nIn programming scenarios where complex error handling is impossible or unneccessary (for\nexample you can simply log the error and exit the process) this can generate a lot\nof repetitive, boilerplate, error-handling code that can obscure your real logic, e.g.\n\njavascript\nasyncFunction1({ ... }, function (error, data) {\n if (error) {\n console.error(error);\n process.exit(1);\n } else {\n // some real logic here\n asyncFunction2({ ... }, function (error, data) {\n if (error) {\n console.error(error);\n process.exit(2);\n } else {\n // some more real logic here\n }\n });\n }\n});\n
\n\nThis module provides a bunch of wrappers that take a function with just (data)
signature\nand produce a function with the (error, data)
signature and the boiler plate logic in place.\nFor example the exitIfError
wrapper has the exact logic shown above, allowing for us to \ncollapse that example down to\n\njavascript\nvar exitIfError = require(\"callback-wrappers\").exitIfError;\n\nasyncFunction1({ ... }, exitIfError(1, function (data) {\n // some real logic here\n asyncFunction2({ ... }, exitIfError(2, function (data) {\n // some more real logic here\n });\n});\n
\n\n### Function.prototype option\n\nIf messing with built-in objects' prototypes doesn't skeeve you out, you can use\nthe Function()
export to get Function.prototype decorated with all of the wrappers\nand our example can look like\n\njavascript\nrequire(\"callback-wrappers\").Function();\n\nasyncFunction1({ ... }, function (data) {\n // some real logic here\n asyncFunction2({ ... }, function (data) {\n // some more real logic here\n }.exitIfError(2));\n}.exitIfError(1));\n
\n\n### long & short wrapper names\n\nThe wrappers all follow a naming convention of actionIfError
, where\naction is one of log
, abort
, exit
, or throw
. For brevity these\ncan be referenced by the initials l
, a
, x
, and t
, followed by ie
\n(for "If Error"). Note that in all cases the error is logged, and in no case,\nincluding logIfError
, will the wrapped function be called if the \nerror
parameter isn't empty.\n\n## Change Log\n\n- 0.2.0: using Object.defineProperty to make the Function.prototype extensions not enumerable\n- 0.1.0: created\n\n## Acknowledgements\n\nThanks go to the nodejs group for comments and suggestions.\n\n## License\n\nMIT\n",
"_id": "[email protected]",
"dist": {
"shasum": "4ac3776caa21fa9939b80028dddb4bbe36510889",
"tarball": "http://registry.npmjs.org/callback-wrappers/-/callback-wrappers-0.2.0.tgz"
},
"_from": "callback-wrappers@*",
"_npmVersion": "1.2.15",
"_npmUser": {
"name": "femto113",
"email": "[email protected]"
},
"maintainers": [
{
"name": "femto113",
"email": "[email protected]"
}
],
"directories": {},
"_shasum": "4ac3776caa21fa9939b80028dddb4bbe36510889",
"_resolved": "https://registry.npmjs.org/callback-wrappers/-/callback-wrappers-0.2.0.tgz",
"bugs": {
"url": "https://github.com/femto113/node-callback-wrappers/issues"
},
"homepage": "https://github.com/femto113/node-callback-wrappers"
}
The install and example sections of the readme refer to "ec2-instance-data".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.