Comparing version 1.0.0 to 1.0.1
@@ -11,7 +11,11 @@ /** | ||
callback(null, value); | ||
// If there's an error, first run the callback to continue the original error logic | ||
}).catch((err) => { | ||
callback(err); | ||
}); | ||
// Then catch it again and log it to console to prevent unhandled promise rejections. | ||
}).catch((err) => { | ||
console.log(err); | ||
}) | ||
} | ||
module.exports = breakify; |
{ | ||
"name": "breakify", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "The opposite of promisify.", | ||
@@ -5,0 +5,0 @@ "main": "breakify.js", |
# breakify | ||
The opposite of promisify. | ||
Seems silly, right? Except if you're in the middle of converting a project from callbacks to promises and you don't want to try to convert a few hundred files at once, some functions will still have to return their values through callbacks despite it being promises from there on down. | ||
## Usage | ||
``` | ||
const breakify = require('breakify'); | ||
function callbackFunction(callback) { | ||
const wrapper = async () => { | ||
const someFunctionAsync = promisify(someFunction); | ||
const value = await someFunctionAsync(); | ||
if (value === 0) { | ||
throw new Error("You can't have 0, don't you know that?"); | ||
} | ||
return value; | ||
} | ||
breakify(wrapper(), callback); | ||
} | ||
``` | ||
If your `promiseReturningFunction` returns a value, callback is called as `callback(null, value)`, and if it throws an error, it is called as `callback(err)`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2019
18
27