
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
Is alternative for js promises. Wire defined outside of function and then passed into.
Purpose:
npm i mo-wire --save
Wire:
Promises:
Enthusiasts are welcomed to write this example using promises
Async:
Enthusiasts are welcomed to write this example using async
Notes:
branches
method.
This will ensure, that success
won't trigger before all of them resolved.l.branch('some')
or l['some']
var l = new Wire();
l.branches('article', 'comments');
posts.getPostFromCacheOrDB(postId, l['article']);
bonds.getPostComments(postId, function (err, rows) {
var processedComments = rows.map(function (r) { ... });
l['comments'].resolve(processedComments);
});
l.success(...);
function getDataFromUrl(l, url) {
download(l.mediator(formatResult), url);
function formatResult(result) {
l.resolve(body.title + ': ' + body.description);
}
}
l
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 traditional callback - and it will work.
resolve(...)
- triggers success
, with any amount of arguments
reject(...)
- triggers failure
, with any amount of arguments
branch(name, options)
- creates new Wire, which translates failure to parent immediately
or accumulates resolutions of all branches to single parent's success. Second argument is options for this new wire. Both arguments are optional.
branches('branch1', 'branch2', ...)
- to predefine list of branches at one step
mediator(callback, options)
- creates new Wire, which translates failure to parent immediately
or calls callback on success. Options are optional.
success(function() {})
failure(function() {})
push(func, arg1, arg2, ...)
- add task to the end of series queue. Queue will be launched once you set success(..) callback
mapInSeries
resolve
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 (isCrap(result))
return l.reject(result);
...
});
l.failure(function(data){
washOff(data);
});
Constructor has optinal parameter: new Wire(options)
options {}:
resolve(...)
as resultFor example, when architecture of project uses
such callbacks: function (err, result)
- we are able to omit passing branch('bla', { resultArg: 1 })
for each branch,
and just set for whole library to await argument from exact place:
require('mo-wire').defaults = {
resultArg: 1
};
Enthusiasts are welcomed to participate project:
Array of failure / success handlers instead of single var
For convenient attaching to promise-based code
Would be nice to cover code with tests
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.