Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
queue-flow
Advanced tools
Readme
For Node.js
npm install queue-flow
For browsers, just copy ./lib/queue-flow.min.js
(generated by UglifyJS)and include it in a <script>
tag.
For developers, npm test
to check your changes (using nodeunit) haven't broken existing functionality.
Tired of this?
stuck(arg, function(err, result) {
if(err) return console.log(err);
In(result, function(err, result) {
if(err) return console.log(err);
callback(result, function(err, result) {
if(err) return console.log(err);
hell(result);
});
});
});
("stuck in callback hell")
What if you could write it like this?
q([arg])
.node(notStuck, 'error')
.node(In, 'error')
.node(callback, 'error')
.each(hell);
q('error')
.each(console.log);
Tired of this?
async.waterfall([
dealing.bind(this, arg),
function With(result, callback) {
if(result.foo == 'branch1') {
async.waterfall([
nested.bind(this, result),
branches
], callback);
} else {
async.waterfall([
making.bind(this, result),
code,
difficult
], callback);
}
},
to.bind(this, 'const1', 'const2')
], function(err, result) {
if(err) return console.log(err);
follow(result);
});
("dealing with nested branches making code difficult to follow")
What if you could write it like this?
q([arg])
.node(dealing, 'error')
.branch(function With(result) {
return result.foo == 'branch1' ? 'branch1' : 'branch2';
});
q('branch1')
.node(nested, 'error')
.node(branches, 'error')
.chain('branchesRejoined');
q('branch2')
.node(making, 'error')
.node(code, 'error')
.node(easy, 'error')
.chain('branchesRejoined');
q('branchesRejoined')
.node(to.bind(this, 'const1', 'const2'), 'error');
.each(follow);
q('error')
.each(console.log);
Tired of this?
someRemoteCall('arg', function recursing(err, result) {
if(err) return console.log(err);
if(result == 'good') {
doSomethingElse();
} else {
someRemoteCall(result, recursing);
// Arg! Stack Overflow!?
// But I can't unroll this recursion because it's an async function, right?
}
});
How about this?
q('recursiveCall')
.node(someRemoteCall, 'error')
.branch(function(result) {
return result == 'good' ? 'doSomethingElse' : 'recursiveCall';
}); // Cannot blow the stack!
q('error')
.each(console.log);
q('doSomethingElse')
...
queue-flow
makes async and sync data processing code easy to read like Fibers
(it doesn't look like fibers code, but it is easy to follow like it) while not altering the Javascript language itself like async
, giving you the best of both worlds, along with some other advantages:
queue-flow
are simply temporary storage for the consuming method "verb" you use. These "verbs" create new, anonymous queues so they can be chained together easily for a terse, easy-to-understand syntax.queue-flow
allows its constructor function to be overridden, and sloppy-queue-flow breaks queue order, turning your queue into essentially a task list of operations to perform on independent data.branch
, and chain
allow you to turn your queues into a flowchart of actions to perform, allowing you to organize your async tasks in easy-to-understand chunks just as functions organize imperative code in easy-to-reuse chunks, and all imperative constructs (if, while, for
) can be replicated with branch
.Still not convinced? Check out more examples on why queue-flow
is better than async
.
Want to learn more? Check out the tutorial for queue-flow
with neat figures explaining the behavior of queue-flow
and its many method verbs. After that, you can read the annotated source code, yourself, which is updated right when new releases of queue-flow
are published (see the nifty prepublish script). (If youre just looking for an API reference, just read the left-hand column and ignore the source code on the right.)
Copyright (C) 2012-2013 by David Ellis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Chainable logic built on named (or not) queues for Javascript and Node.js
The npm package queue-flow receives a total of 201 weekly downloads. As such, queue-flow popularity was classified as not popular.
We found that queue-flow 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.