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

p-pipe

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-pipe

Compose promise-returning & async functions into a reusable pipeline

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is p-pipe?

The p-pipe npm package allows you to compose promise-returning & async functions into a pipeline. It is useful for creating a sequence of asynchronous operations where the output of one function is passed as the input to the next.

What are p-pipe's main functionalities?

Basic Pipeline

This feature allows you to create a basic pipeline of asynchronous functions. In this example, the `add` function increments the input by 1, and the `multiply` function doubles the result. The pipeline processes the input `5` to produce the output `12`.

const pPipe = require('p-pipe');

const add = async x => x + 1;
const multiply = async x => x * 2;

const pipeline = pPipe(add, multiply);

pipeline(5).then(result => console.log(result)); // 12

Error Handling

This feature demonstrates how p-pipe handles errors in the pipeline. If any function in the pipeline throws an error, the pipeline will stop executing and return the error. In this example, the `throwError` function throws an error, which is caught and logged.

const pPipe = require('p-pipe');

const add = async x => x + 1;
const throwError = async x => { throw new Error('Something went wrong'); };
const multiply = async x => x * 2;

const pipeline = pPipe(add, throwError, multiply);

pipeline(5).catch(error => console.error(error.message)); // 'Something went wrong'

Synchronous Functions

This feature shows that p-pipe can also handle synchronous functions. The pipeline processes the input `5` to produce the output `12`, similar to the asynchronous example.

const pPipe = require('p-pipe');

const add = x => x + 1;
const multiply = x => x * 2;

const pipeline = pPipe(add, multiply);

pipeline(5).then(result => console.log(result)); // 12

Other packages similar to p-pipe

Keywords

FAQs

Package last updated on 08 Apr 2021

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