-
Notifications
You must be signed in to change notification settings - Fork 578
/
promises.ts
42 lines (40 loc) · 881 Bytes
/
promises.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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();
}
},
);
});
}