Skip to content

Adapter docs for convention-breakers #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,28 @@ Also you can use group with a dynamic number of common tasks.
);

*Note* that we both call `this.group()` and `group()`. The first reserves a slot in the parameters of the next step, then calling `group()` generates the individual callbacks and increments the internal counter.

If the library you're using for asynchronous calls doesn't follow node's convention of function callback(err, res), then you could consider using an adapter like the following:

function adapter(){
var x = this.parallel();
return function(rr){
err = rr.status != 'success' ? rr : null; // Or whatever logic is necessary to ascertain status
x(err, rr);
}
}

Step(
// Two actions in parallel
function loadStuff() {
naughtyLibrary.doSomething(foo, adapter.call(this));
fs.readFile("/etc/passwd", this.parallel());
},
// Show the result when done
function showStuff(err, libRes, users) {
if (err) throw err;
console.log(libRes);
console.log(users);
}
)