Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cargo-ship

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cargo-ship

Parallel execution of tasks with a shared namespace

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

cargo-ship

Parallel execution of tasks with a shared namespace

npm version Travis Coveralls

The extremly well-known parallel execution of tasks, but with a cargo, a shared object where tasks can store data. It's like a cargo ship, cranes (tasks) storing cargo (data). Each task writing to the shared object.

It's very useful when you need to call a bunch of functions in parallel and store the results in a common place.

var cranes = [
  function (cargo, done) {
    cargo.a = 1;
    done();
  },
  function (cargo, done) {
    cargo.b = 2;
    done();
  },
  function (cargo, done) {
    cargo.c = 3;
    done();
  }
];

ship.load(cranes, function (err, cargo) {
  // cargo { a: 1, b: 2, c: 3 }
});

It's basically the same behaviour as the async.parallel() but with a sightly! and slightly different interface.

module.load(cranes[, cargo], callback) : undefined

Executes all tasks in parallel.

cranes is an array of functions to run in parallel. Each function has the signature function(cargo, done), where cargo is the shared object and done the function to call when the task finishes. As usual, pass an error to done() to abort the execution of the tasks. This is the error returned by the load() function. Because aborting asynchronous parallel tasks is not possible once they begin, the callback is guaranteed to be called only once with the first error occurred.

A cargo can be passed from outside. Use the second parameter to initialize the cargo with data.

var cranes = [
  function (cargo, done) {
    cargo.b = 2;
    done();
  },
  function (cargo, done) {
    cargo.c = 3;
    done();
  }
];

ship.load(cranes, { a: 1 }, function (err, cargo) {
  // cargo { a: 1, b: 2, c: 3 }
});

Keywords

FAQs

Package last updated on 06 Feb 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc