Skip to content
Myr

sequence.js

This file

Path

lib/pipe/sequence.js

24 lines · 926 bytes · JavaScript

Last changed by

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

History of this file

Take it

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 1–4why, one step back
1// Like Bash, we await both processes. This is unlike some other shells which only await the destination process.
2// Like Bash with the `pipefail` option, if either process fails, the whole pipe fails.3// Like Bash, if both processes fail, we return the failure of the destination.4// This ensures both processes' errors are present, using `error.pipedFrom`.

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

line 5why, one step back
5export const waitForBothProcesses = async processPromises => {

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 6–8why, one step back
6 const [
7 {status: sourceStatus, reason: sourceReason, value: sourceResult = sourceReason},8 {status: destinationStatus, reason: destinationReason, value: destinationResult = destinationReason},

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

line 9why, one step back
9 ] = await processPromises;

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 10–24why, one step back
10
11 if (!destinationResult.pipedFrom.includes(sourceResult)) {12 destinationResult.pipedFrom.push(sourceResult);13 }1415 if (destinationStatus === 'rejected') {16 throw destinationResult;17 }1819 if (sourceStatus === 'rejected') {20 throw sourceResult;21 }2223 return destinationResult;24};