Socket
Socket
Sign inDemoInstall

pipline

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pipline

Pipline is a promise pipeline that can run concurrent functions with a nice to work with api.


Version published
Maintainers
1
Install size
7.33 kB
Created

Readme

Source

pipline

Pipline lets you create pipelines using promises. You give this pipeline the promise returning functions you want in an orderly fashion, set their options so they will behave as you like, and then you can send any data to this pipeline, which will be processed with the order and constraints you gave your promise returning functions with.

Best part of this library is that it uses promises in its internal implementation and there is no magic. It just works! And its easy to work with!

Example

const Pipeline = require('./');

let pipeline = new Pipeline();

// You can also chain #use methods, since #use returns `this`.
pipeline.use(waitAndReturn, { concurrency: 3, timeout: 3500 });
pipeline.use(printAndWait, { concurrency: 1 });

// Create an array containing numbers from 0 to 9, and calls pipeline.start on them.
for(let i = 0; i < 10; i++){
	pipeline.start(i)
		.then((res) => console.log("Result: ", res))
		.catch((err) => console.log("Error: ", err));
}

// Returns a promise that resolves after 3 seconds.
function waitAndReturn(i){
	console.log(`Wait and return called with: ${i}`);
	return new Promise((resolve) => setTimeout(() => resolve(i), 3000));
}

function printAndWait(i){
	return new Promise((resolve) => {
		console.log(`PrintAndWait prints ${i}`);
		setTimeout(() => resolve(i), 1000);
	});	
}

This example function will take 3 + 10 seconds to complete. You can notice the first function that takes 3000 ms, processes the given data in batches of 3.

Keywords

FAQs

Last updated on 08 Aug 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc