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 fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 1–8why, one step back1// 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 back9 {reason: pipedFromReason, value: pipedFromResult = pipedFromReason},100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 10–11why, one step back10 ] = await subprocessPromises;11Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
lines 12–13why, one step back12 if (!destinationResult.pipedFrom.includes(pipedFromResult)) {13 destinationResult.pipedFrom.push(pipedFromResult);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 14–25why, one step back14 }1516 if (destinationStatus === 'rejected') {17 throw destinationResult;18 }1920 if (sourceStatus === 'rejected') {21 throw sourceResult;22 }2324 return destinationResult;25};