1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/std/node/_stream/promises.ts

43 lines
881 B
TypeScript
Raw Normal View History

// Copyright Node.js contributors. All rights reserved. MIT License.
import pl from "./pipeline.ts";
import type { PipelineArguments } from "./pipeline.ts";
import eos from "./end_of_stream.ts";
import type {
FinishedOptions,
StreamImplementations as FinishedStreams,
} from "./end_of_stream.ts";
export function pipeline(...streams: PipelineArguments) {
return new Promise((resolve, reject) => {
pl(
...streams,
(err, value) => {
if (err) {
reject(err);
} else {
resolve(value);
}
},
);
});
}
export function finished(
stream: FinishedStreams,
opts?: FinishedOptions,
) {
return new Promise<void>((resolve, reject) => {
eos(
stream,
opts || null,
(err) => {
if (err) {
reject(err);
} else {
resolve();
}
},
);
});
}