24 lines
525 B
TypeScript
24 lines
525 B
TypeScript
const awaitStream = <T>(
|
|
inputSteam: any,
|
|
outputStream: any,
|
|
allStreamsToErrorCatch: any[]
|
|
) => {
|
|
return new Promise<T>((resolve, reject) => {
|
|
allStreamsToErrorCatch.forEach((currentStream: any) => {
|
|
currentStream.on("error", (e: Error) => {
|
|
reject({
|
|
message: "Await Stream Input Error",
|
|
code: 500,
|
|
error: e,
|
|
});
|
|
});
|
|
});
|
|
|
|
inputSteam.pipe(outputStream).on("finish", (data: T) => {
|
|
resolve(data);
|
|
});
|
|
});
|
|
};
|
|
|
|
export default awaitStream;
|