![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
double-done
Advanced tools
[]
(https://travis-ci.org/iccicci/double-done)
[
]
(https://codeclimate.com/github/iccicci/double-done)
[
]
(https://codeclimate.com/github/iccicci/double-done/coverage)
[
]
(https://david-dm.org/iccicci/double-done)
[
]
(https://david-dm.org/iccicci/double-done?type=dev)
I have always liked JavaScript, but when I deeply understood its power, I have fallen in love with it!
One of the greatest aspect of JavaScript is that, thanks to its other strenght points, it helps saving the most expensive resource of the whole software life cycle: developers time.
From now on: SD
In my experience I found that so often I have to write an async function which has to call some other async functions to achieve its ojective. Many of the functions I wrote look like:
function myAsyncFunctionSD(param1, done) {
otherAsyncFunction1(function(err, param2) {
if(err)
return done(err);
otherAsyncFunction2(param1, param2, function(err, param3) {
if(err)
return done(err);
otherAsyncFunction3(param1, param3, function(err, param4) {
if(err)
return done(err);
done(null, param2, param4);
});
});
});
}
After written some functions I found that continuously repeated block
if(err)
return done(err);
was just a time waster, both when writing and reading the code.
From now on: HDD
An environment where async functions accept two done functions, one called in case of error and one called in case of success could help saving that time. My same async function would appear so:
function myAsyncFunctionHDD(param1, doneErr, doneOk) {
otherAsyncFunction1HDD(doneErr, function(param2) {
otherAsyncFunction2HDD(param1, param2, doneErr, function(param3) {
otherAsyncFunction3HDD(param1, param3, doneErr, function(param4) {
doneOk(param2, param4);
});
});
});
}
or simply: Double Done design pattern
From now on: SDD or simply: DD
I immediately realized that changing myAsyncFunctionSD in myAsyncFunctionHDD would be a breaking change. More than this I had to considerate that not always calling an HDD async function is more confortable than calling a SD async function (i.e.: when we have to do something both in cases of error or success).
For these two reasons I decided to write this package which may help us writing DD async funciotns.
A DD async funciotn should be documentete as follows:
# myAsyncFunctionDD(param1, done[, doneOk])
in case of error, done will be called with the error as first parameter; in case of success, if the caller have not passed a doneOk function, (as in SD design pattern) done function will be called with null as first parameter followed by other parameters (which are the myAsyncFunctionDD result), otherwise doneOk function will be called passing to it only the parameters which are the myAsyncFunctionDD result.
Back to: top - Table of contents
require('doble-done');
Returns the double-done utility function.
Returns the doneOk function which must be called in case of success regardless if the caller passed it or not.
function myAsyncFunctionDD(param1, done, doneOk) {
doneOk = dd(done, doneOk);
From now on done and doneOk are the functions to call respectively in case of error or success.
Lets us to call an SD async function writing only the callbackOk function, if the called async function gets an error, doneOk.dd makes it calling the original done function.
function myAsyncFunctionDD(param1, done, doneOk) {
doneOk = dd(done, doneOk);
otherAsyncFunction1SD(doneOk.dd(function(param2) {
// if otherAsyncFunction1SD gets an error, done will be called
// otherwise this function is executed
}));
Back to: top - Table of contents
Do not hesitate to report any bug or consideration @github.
FAQs
Double Done design pattern
We found that double-done demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.