
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
alternative for js promises. Wire defined outside of function and then passed into
l
l
l
mo-wire
Wire() - is alternative for js Promise(). Wire defined outside of function and then passed into.
Purpose:
Wire:
var Wire = require('../mo-wire/mo-wire');
Wire.defaults = { resultArg: 1 };
function preparePostData(postId, done) {
var l = new Wire();
posts.getPost(postId, l.branch('article'));
comments.getPostComments(postId, l.branch('comments'));
l.success(done);
}
Promises:
Enthusiasts are welcomed to write this example using promises
Async:
Enthusiasts are welcomed to write this example using async
Note: you can predefine full list of branches with branches
method.
This will ensure, that success
won't trigger before all of them resolved.
var l = new Wire();
l.branches('article', 'comments');
posts.getPost(postId, l['article']);
bonds.getPostComments(postId, function (err, rows) {
var processedRows = rows.map(function (r) { ... });
l['bonds'].resolve(processedRows);
});
l.success(...);
var l = new Wire();
l.mapInSeries(postIds, function(postId) {
posts.doHeavyCalculationOfRating(postId, someOptions, l);
});
l.success(function(results) {
// [] Array with result of each call
});
You can call wire instance itself - it is a function. This is equal:
l()
l.resolve()
So you can pass wire to functions, which awaits for callback - and it will work.
success
, any amount of argumentsfailure
, any amount of argumentsresolve
and reject
will trigger corresponding callback only once.
If reject
already called, resolve
won't do anything.
But you can call reject
after resolve
, for example:
var l = new Wire();
doSomethingAsync(l);
l.success(function(result){
if (result == 'crap')
return l.reject({ dealWithIt: result });
...
});
l.failure(function(data){
washOff(data);
});
Constructor has optinal parameter: new Wire(options)
options {}:
resolve(...)
as resultFor example, when architecture of project uses
callbacks function (err, result)
we are able to omit passing { resultArg: 1 }
for each branch,
and just set for whole library to await argument by default from exact place using:
require('mo-wire').defaults = {
resultArg: 1
};
Need to cover code with tests
Array of failure / success handlers instead of single var
The MIT License (MIT) Copyright (c) 2015 garmoshka-mo
FAQs
alternative for js promises. Wire defined outside of function and then passed into
The npm package mo-wire receives a total of 1 weekly downloads. As such, mo-wire popularity was classified as not popular.
We found that mo-wire 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.