Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
octopus-async
Advanced tools
/\
∠___ゝ
)|’ー’| /
(ノノノ从し'
Note: this package is deprecated. If you need to do asynchronous tasks you should use promises and/or async/await syntax which should work in all modern browsers as well as in the latest versions of node.js.
You could achieve the same thing as octopus natively:
const results = await Promise.all([one(), two()]);
// or
const [result1, result2] = await Promise.all([one(), two()]);
const calls = [one, two, three];
let value;
for (const call of calls) {
value = await call(value);
}
Octopus is a couple of simple asynchronous helper functions. It is designed for use in the browser and is < 500 bytes gzipped. It works in node.js as well.
It is available in NPM
npm install octopus-async
There are two calls
Run a bunch of functions in parallel and receive a callback with the results of all of them.
var calls = [
function one(callback) {
setTimeout(function() {
callback(10);
}, 200);
},
function two(callback) {
callback(20);
}
];
octopus.run(calls, function(results) {
console.log(results); // [10, 20]
});
Notice that even though function one finished after function two the results still come back in the order you passed the functions in originally.
You can also pass in an object with names as the keys
var calls = {
one: function(callback) { callback(10); },
two: function(callback) { callback(20); }
};
octopus.run(calls, function(results)) {
console.log(results); // {one: 10, two: 20}
});
Steps through functions one after the other passing the result from one function to the next.
var calls = [
function one(callback) {
callback(10);
},
function two(value, callback) {
callback(value * 2);
},
function three(value, callback) {
callback(value * 3);
}
];
octopus.step(calls, function(result) {
console.log(result); // 60
});
To achieve the same thing with those 3 functions in vanilla Javascript you would have to do something like
one(function(result) {
two(result, function(result) {
three(result, function(result) {
console.log(result);
});
});
});
In node.js the convention is to pass back an error before the actual result in callback functions. To use any of the above examples in node, just be consistent and pass back an error argument as the first argument in your callbacks.
Octopus will stop running and fire the final callback as soon as it receives an
error. In the step
call it will stop after the step that errored. In the
run
call it will fire the callback with the error, but the other calls will
continue running until they finish. There is no easy way to cancel a function
from executing.
FAQs
Simple asynchronous helpers
The npm package octopus-async receives a total of 0 weekly downloads. As such, octopus-async popularity was classified as not popular.
We found that octopus-async 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.