Skip to content
Myr

sequence.js

This file

Path

lib/pipe/sequence.js

25 lines · 1.0 KiB · JavaScript

Last changed by

Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d

History of this file

Take it

The walk stopped after 200 commits: lines older than c8a6ed7 point at it.

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 1–8why, one step back
1// Like Bash, we await both subprocesses. This is unlike some other shells which only await the destination subprocess.
2// Like Bash with the `pipefail` option, if either subprocess fails, the whole pipe fails.3// Like Bash, if both subprocesses fail, we return the failure of the destination.4// This ensures both subprocesses' errors are present, using `error.pipedFrom`.5export const waitForBothSubprocesses = async subprocessPromises => {6 const [7 {status: sourceStatus, reason: sourceReason, value: sourceResult = sourceReason},8 {status: destinationStatus, reason: destinationReason, value: destinationResult = destinationReason},

Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d

line 9why, one step back
9 {reason: pipedFromReason, value: pipedFromResult = pipedFromReason},

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 10–11why, one step back
10 ] = await subprocessPromises;
11

Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d

lines 12–13why, one step back
12 if (!destinationResult.pipedFrom.includes(pipedFromResult)) {
13 destinationResult.pipedFrom.push(pipedFromResult);

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 14–25why, one step back
14 }
1516 if (destinationStatus === 'rejected') {17 throw destinationResult;18 }1920 if (sourceStatus === 'rejected') {21 throw sourceResult;22 }2324 return destinationResult;25};