@yume-chan/stream-extra 2.5.3 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/esm/buffered-transform.d.ts +2 -2
- package/esm/buffered-transform.d.ts.map +1 -1
- package/esm/buffered-transform.js +1 -1
- package/esm/buffered-transform.js.map +1 -1
- package/esm/buffered.d.ts +1 -1
- package/esm/buffered.d.ts.map +1 -1
- package/esm/buffered.js.map +1 -1
- package/esm/concat.d.ts +25 -16
- package/esm/concat.d.ts.map +1 -1
- package/esm/concat.js +124 -93
- package/esm/concat.js.map +1 -1
- package/esm/consumable/readable.d.ts +2 -2
- package/esm/consumable/readable.d.ts.map +1 -1
- package/esm/consumable/readable.js +1 -1
- package/esm/consumable/readable.js.map +1 -1
- package/esm/consumable/wrap-byte-readable.d.ts +5 -2
- package/esm/consumable/wrap-byte-readable.d.ts.map +1 -1
- package/esm/consumable/wrap-byte-readable.js +12 -6
- package/esm/consumable/wrap-byte-readable.js.map +1 -1
- package/esm/consumable/wrap-writable.d.ts +1 -1
- package/esm/consumable/wrap-writable.d.ts.map +1 -1
- package/esm/consumable/wrap-writable.js +1 -1
- package/esm/consumable/wrap-writable.js.map +1 -1
- package/esm/consumable/writable.d.ts +2 -2
- package/esm/consumable/writable.d.ts.map +1 -1
- package/esm/consumable/writable.js +1 -1
- package/esm/consumable/writable.js.map +1 -1
- package/esm/consumable.d.ts +4 -0
- package/esm/consumable.d.ts.map +1 -1
- package/esm/consumable.js +5 -0
- package/esm/consumable.js.map +1 -1
- package/esm/distribution.d.ts +1 -1
- package/esm/distribution.d.ts.map +1 -1
- package/esm/distribution.js +1 -1
- package/esm/distribution.js.map +1 -1
- package/esm/duplex.d.ts +2 -2
- package/esm/duplex.d.ts.map +1 -1
- package/esm/duplex.js +1 -1
- package/esm/duplex.js.map +1 -1
- package/esm/global/abort-signal.d.ts +87 -0
- package/esm/global/abort-signal.d.ts.map +1 -0
- package/esm/global/abort-signal.js +4 -0
- package/esm/global/abort-signal.js.map +1 -0
- package/esm/global/compression.d.ts +15 -0
- package/esm/global/compression.d.ts.map +1 -0
- package/esm/global/compression.js +4 -0
- package/esm/global/compression.js.map +1 -0
- package/esm/global/encoding.d.ts +25 -0
- package/esm/global/encoding.d.ts.map +1 -0
- package/esm/global/encoding.js +4 -0
- package/esm/global/encoding.js.map +1 -0
- package/esm/global/event.d.ts +191 -0
- package/esm/global/event.d.ts.map +1 -0
- package/esm/global/event.js +4 -0
- package/esm/global/event.js.map +1 -0
- package/esm/global/index.d.ts +7 -0
- package/esm/global/index.d.ts.map +1 -0
- package/esm/global/index.js +7 -0
- package/esm/global/index.js.map +1 -0
- package/esm/{types.d.ts → global/streams.d.ts} +136 -222
- package/esm/global/streams.d.ts.map +1 -0
- package/esm/{stream.js → global/streams.js} +16 -8
- package/esm/global/streams.js.map +1 -0
- package/esm/global/timer.d.ts +13 -0
- package/esm/global/timer.d.ts.map +1 -0
- package/esm/global/timer.js +4 -0
- package/esm/global/timer.js.map +1 -0
- package/esm/global/utils.d.ts +9 -0
- package/esm/global/utils.d.ts.map +1 -0
- package/esm/global/utils.js +5 -0
- package/esm/global/utils.js.map +1 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/inspect.d.ts +6 -2
- package/esm/inspect.d.ts.map +1 -1
- package/esm/inspect.js +10 -4
- package/esm/inspect.js.map +1 -1
- package/esm/maybe-consumable/wrap-writable.d.ts +1 -1
- package/esm/maybe-consumable/wrap-writable.d.ts.map +1 -1
- package/esm/maybe-consumable/wrap-writable.js +1 -1
- package/esm/maybe-consumable/wrap-writable.js.map +1 -1
- package/esm/maybe-consumable/writable.d.ts +2 -2
- package/esm/maybe-consumable/writable.d.ts.map +1 -1
- package/esm/maybe-consumable/writable.js +1 -1
- package/esm/maybe-consumable/writable.js.map +1 -1
- package/esm/pipe-from.d.ts +3 -3
- package/esm/pipe-from.d.ts.map +1 -1
- package/esm/pipe-from.js +1 -1
- package/esm/pipe-from.js.map +1 -1
- package/esm/push-readable.d.ts +20 -3
- package/esm/push-readable.d.ts.map +1 -1
- package/esm/push-readable.js +180 -180
- package/esm/push-readable.js.map +1 -1
- package/esm/split-string.d.ts +6 -2
- package/esm/split-string.d.ts.map +1 -1
- package/esm/split-string.js +28 -7
- package/esm/split-string.js.map +1 -1
- package/esm/struct-deserialize.js.map +1 -1
- package/esm/struct-serialize.d.ts +1 -1
- package/esm/struct-serialize.d.ts.map +1 -1
- package/esm/struct-serialize.js +1 -1
- package/esm/struct-serialize.js.map +1 -1
- package/esm/task-queue.d.ts +8 -0
- package/esm/task-queue.d.ts.map +1 -0
- package/esm/task-queue.js +50 -0
- package/esm/task-queue.js.map +1 -0
- package/esm/try-close.d.ts +3 -5
- package/esm/try-close.d.ts.map +1 -1
- package/esm/try-close.js.map +1 -1
- package/esm/wrap-readable.d.ts +2 -2
- package/esm/wrap-readable.d.ts.map +1 -1
- package/esm/wrap-readable.js +1 -1
- package/esm/wrap-readable.js.map +1 -1
- package/esm/wrap-writable.d.ts +2 -2
- package/esm/wrap-writable.d.ts.map +1 -1
- package/esm/wrap-writable.js +1 -1
- package/esm/wrap-writable.js.map +1 -1
- package/package.json +8 -8
- package/src/buffered-transform.ts +8 -7
- package/src/buffered.ts +4 -1
- package/src/concat.ts +161 -118
- package/src/consumable/readable.ts +2 -2
- package/src/consumable/wrap-byte-readable.ts +20 -7
- package/src/consumable/wrap-writable.ts +1 -1
- package/src/consumable/writable.ts +2 -2
- package/src/consumable.ts +8 -0
- package/src/distribution.ts +1 -1
- package/src/duplex.ts +2 -2
- package/src/global/abort-signal.ts +129 -0
- package/src/global/compression.ts +28 -0
- package/src/global/encoding.ts +36 -0
- package/src/global/event.ts +221 -0
- package/src/global/index.ts +6 -0
- package/src/{types.ts → global/streams.ts} +266 -244
- package/src/global/timer.ts +18 -0
- package/src/global/utils.ts +14 -0
- package/src/index.ts +2 -2
- package/src/inspect.ts +18 -4
- package/src/maybe-consumable/wrap-writable.ts +1 -1
- package/src/maybe-consumable/writable.ts +3 -3
- package/src/pipe-from.ts +2 -2
- package/src/push-readable.ts +226 -198
- package/src/split-string.ts +41 -7
- package/src/struct-deserialize.ts +1 -1
- package/src/struct-serialize.ts +1 -1
- package/src/task-queue.ts +69 -0
- package/src/try-close.ts +0 -12
- package/src/wrap-readable.ts +2 -2
- package/src/wrap-writable.ts +5 -2
- package/tsconfig.build.json +1 -6
- package/CHANGELOG.md +0 -102
- package/esm/encoding.d.ts +0 -21
- package/esm/encoding.d.ts.map +0 -1
- package/esm/encoding.js +0 -4
- package/esm/encoding.js.map +0 -1
- package/esm/stream.d.ts +0 -25
- package/esm/stream.d.ts.map +0 -1
- package/esm/stream.js.map +0 -1
- package/esm/types.d.ts.map +0 -1
- package/esm/types.js +0 -3
- package/esm/types.js.map +0 -1
- package/src/encoding.ts +0 -39
- package/src/stream.ts +0 -106
- package/tsconfig.build.tsbuildinfo +0 -1
package/esm/push-readable.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
-
import { AbortController, ReadableStream } from "./
|
|
1
|
+
import { isPromiseLike, PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { AbortController, ReadableStream } from "./global/index.js";
|
|
3
|
+
import { TaskQueue } from "./task-queue.js";
|
|
3
4
|
export class PushReadableStream extends ReadableStream {
|
|
4
5
|
/**
|
|
5
6
|
* Create a new `PushReadableStream` from a source.
|
|
@@ -9,196 +10,194 @@ export class PushReadableStream extends ReadableStream {
|
|
|
9
10
|
* @param strategy
|
|
10
11
|
*/
|
|
11
12
|
constructor(source, strategy, logger) {
|
|
12
|
-
let
|
|
13
|
+
let controller;
|
|
14
|
+
const tasks = new TaskQueue();
|
|
13
15
|
let zeroHighWaterMarkAllowEnqueue = false;
|
|
16
|
+
// Resolves when consumer calls `reader.read`.
|
|
17
|
+
// Rejects when producer calls `controller.close` or `controller.error`,
|
|
18
|
+
// or consumer calls `reader.cancel`.
|
|
19
|
+
let waterMarkLow;
|
|
14
20
|
const abortController = new AbortController();
|
|
21
|
+
// Whether either the consumer has called `stream.cancel()`,
|
|
22
|
+
// or the producer has called `controller.close` or `controller.error`.
|
|
23
|
+
let stopped = false;
|
|
24
|
+
const enqueue = (chunk) => {
|
|
25
|
+
logger?.({
|
|
26
|
+
source: "producer",
|
|
27
|
+
operation: "enqueue",
|
|
28
|
+
value: chunk,
|
|
29
|
+
phase: "start",
|
|
30
|
+
});
|
|
31
|
+
if (abortController.signal.aborted) {
|
|
32
|
+
// In original `ReadableStream`, calling `enqueue` or `close`
|
|
33
|
+
// on an cancelled stream will throw an error,
|
|
34
|
+
//
|
|
35
|
+
// But in `PushReadableStream`, `enqueue` is an async function,
|
|
36
|
+
// the producer can't just check `abortSignal.aborted`
|
|
37
|
+
// before calling `enqueue`, as it might change when waiting
|
|
38
|
+
// for the backpressure to be reduced.
|
|
39
|
+
//
|
|
40
|
+
// So IMO it's better to handle this for the producer
|
|
41
|
+
// by simply ignoring the `enqueue` call.
|
|
42
|
+
//
|
|
43
|
+
// Note that we check `abortSignal.aborted` instead of `stopped`,
|
|
44
|
+
// as it's not allowed for the producer to call `enqueue` after
|
|
45
|
+
// they called `close` or `error`.
|
|
46
|
+
//
|
|
47
|
+
// Obviously, the producer should listen to the `abortSignal` and
|
|
48
|
+
// stop producing, but most pushing data sources don't support that.
|
|
49
|
+
logger?.({
|
|
50
|
+
source: "producer",
|
|
51
|
+
operation: "enqueue",
|
|
52
|
+
value: chunk,
|
|
53
|
+
phase: "ignored",
|
|
54
|
+
});
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (controller.desiredSize === null) {
|
|
58
|
+
// `desiredSize` being `null` means the stream is in error state,
|
|
59
|
+
// `controller.enqueue` will throw an error for us.
|
|
60
|
+
controller.enqueue(chunk);
|
|
61
|
+
// istanbul ignore next
|
|
62
|
+
throw new Error("unreachable");
|
|
63
|
+
}
|
|
64
|
+
if (zeroHighWaterMarkAllowEnqueue) {
|
|
65
|
+
// When `highWaterMark` is set to `0`,
|
|
66
|
+
// `controller.desiredSize` will always be `0`,
|
|
67
|
+
// even if the consumer has called `reader.read()`.
|
|
68
|
+
// (in this case, each `reader.read()`/`pull`
|
|
69
|
+
// should allow one `enqueue` of any size)
|
|
70
|
+
//
|
|
71
|
+
// If the consumer has already called `reader.read()`,
|
|
72
|
+
// before the producer tries to `enqueue`,
|
|
73
|
+
// `controller.desiredSize` is `0` and normal `waterMarkLow` signal
|
|
74
|
+
// will never trigger,
|
|
75
|
+
// (because `ReadableStream` prevents reentrance of `pull`)
|
|
76
|
+
// The stream will stuck.
|
|
77
|
+
//
|
|
78
|
+
// So we need a special signal for this case.
|
|
79
|
+
zeroHighWaterMarkAllowEnqueue = false;
|
|
80
|
+
controller.enqueue(chunk);
|
|
81
|
+
logger?.({
|
|
82
|
+
source: "producer",
|
|
83
|
+
operation: "enqueue",
|
|
84
|
+
value: chunk,
|
|
85
|
+
phase: "complete",
|
|
86
|
+
});
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (controller.desiredSize <= 0) {
|
|
90
|
+
logger?.({
|
|
91
|
+
source: "producer",
|
|
92
|
+
operation: "enqueue",
|
|
93
|
+
value: chunk,
|
|
94
|
+
phase: "waiting",
|
|
95
|
+
});
|
|
96
|
+
waterMarkLow = new PromiseResolver();
|
|
97
|
+
return waterMarkLow.promise.then(() => {
|
|
98
|
+
controller.enqueue(chunk);
|
|
99
|
+
logger?.({
|
|
100
|
+
source: "producer",
|
|
101
|
+
operation: "enqueue",
|
|
102
|
+
value: chunk,
|
|
103
|
+
phase: "complete",
|
|
104
|
+
});
|
|
105
|
+
return true;
|
|
106
|
+
}, () => {
|
|
107
|
+
// Only ignore this in-flight `enqueue` call
|
|
108
|
+
// future calls will trigger `desiredSize === null` and throw
|
|
109
|
+
logger?.({
|
|
110
|
+
source: "producer",
|
|
111
|
+
operation: "enqueue",
|
|
112
|
+
value: chunk,
|
|
113
|
+
phase: "ignored",
|
|
114
|
+
});
|
|
115
|
+
return false;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
controller.enqueue(chunk);
|
|
119
|
+
logger?.({
|
|
120
|
+
source: "producer",
|
|
121
|
+
operation: "enqueue",
|
|
122
|
+
value: chunk,
|
|
123
|
+
phase: "complete",
|
|
124
|
+
});
|
|
125
|
+
return true;
|
|
126
|
+
};
|
|
127
|
+
const close = (explicit) => {
|
|
128
|
+
logger?.({
|
|
129
|
+
source: "producer",
|
|
130
|
+
operation: "close",
|
|
131
|
+
explicit,
|
|
132
|
+
phase: "start",
|
|
133
|
+
});
|
|
134
|
+
// Allow calling `controller.close` on cancelled stream as `enqueue` does
|
|
135
|
+
// Ignore implicit close on any stopped state
|
|
136
|
+
// But don't allow calling `controller.close` multiple times
|
|
137
|
+
if (abortController.signal.aborted || (stopped && !explicit)) {
|
|
138
|
+
logger?.({
|
|
139
|
+
source: "producer",
|
|
140
|
+
operation: "close",
|
|
141
|
+
explicit,
|
|
142
|
+
phase: "ignored",
|
|
143
|
+
});
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// This will throw for us if the stream is not in `readable` state
|
|
147
|
+
controller.close();
|
|
148
|
+
stopped = true;
|
|
149
|
+
// Wake up pending `enqueue`
|
|
150
|
+
waterMarkLow?.reject();
|
|
151
|
+
logger?.({
|
|
152
|
+
source: "producer",
|
|
153
|
+
operation: "close",
|
|
154
|
+
explicit,
|
|
155
|
+
phase: "complete",
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
const error = (error, explicit) => {
|
|
159
|
+
logger?.({
|
|
160
|
+
source: "producer",
|
|
161
|
+
operation: "error",
|
|
162
|
+
explicit,
|
|
163
|
+
phase: "start",
|
|
164
|
+
});
|
|
165
|
+
stopped = true;
|
|
166
|
+
// `controller.error` won't throw on closed/errored/cancelled stream
|
|
167
|
+
// so don't need any checks
|
|
168
|
+
controller.error(error);
|
|
169
|
+
// Wake up pending `enqueue`
|
|
170
|
+
waterMarkLow?.reject();
|
|
171
|
+
logger?.({
|
|
172
|
+
source: "producer",
|
|
173
|
+
operation: "error",
|
|
174
|
+
explicit,
|
|
175
|
+
phase: "complete",
|
|
176
|
+
});
|
|
177
|
+
};
|
|
15
178
|
super({
|
|
16
|
-
start: (
|
|
179
|
+
start: (controller_) => {
|
|
180
|
+
controller = controller_;
|
|
17
181
|
const result = source({
|
|
18
182
|
abortSignal: abortController.signal,
|
|
19
|
-
enqueue: async (chunk) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
value: chunk,
|
|
24
|
-
phase: "start",
|
|
25
|
-
});
|
|
26
|
-
if (abortController.signal.aborted) {
|
|
27
|
-
// In original `ReadableStream`, calling `enqueue` or `close`
|
|
28
|
-
// on an cancelled stream will throw an error,
|
|
29
|
-
//
|
|
30
|
-
// But in `PushReadableStream`, `enqueue` is an async function,
|
|
31
|
-
// the producer can't just check `abortSignal.aborted`
|
|
32
|
-
// before calling `enqueue`, as it might change when waiting
|
|
33
|
-
// for the backpressure to be reduced.
|
|
34
|
-
//
|
|
35
|
-
// So IMO it's better to handle this for the producer
|
|
36
|
-
// by simply ignoring the `enqueue` call.
|
|
37
|
-
//
|
|
38
|
-
// Note that we check `abortSignal.aborted` instead of `stopped`,
|
|
39
|
-
// as it's not allowed for the producer to call `enqueue` after
|
|
40
|
-
// they called `close` or `error`.
|
|
41
|
-
//
|
|
42
|
-
// Obviously, the producer should listen to the `abortSignal` and
|
|
43
|
-
// stop producing, but most pushing data sources don't support that.
|
|
44
|
-
logger?.({
|
|
45
|
-
source: "producer",
|
|
46
|
-
operation: "enqueue",
|
|
47
|
-
value: chunk,
|
|
48
|
-
phase: "ignored",
|
|
49
|
-
});
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (controller.desiredSize === null) {
|
|
53
|
-
// `desiredSize` being `null` means the stream is in error state,
|
|
54
|
-
// `controller.enqueue` will throw an error for us.
|
|
55
|
-
controller.enqueue(chunk);
|
|
56
|
-
// istanbul ignore next
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (zeroHighWaterMarkAllowEnqueue) {
|
|
60
|
-
// When `highWaterMark` is set to `0`,
|
|
61
|
-
// `controller.desiredSize` will always be `0`,
|
|
62
|
-
// even if the consumer has called `reader.read()`.
|
|
63
|
-
// (in this case, each `reader.read()`/`pull`
|
|
64
|
-
// should allow one `enqueue` of any size)
|
|
65
|
-
//
|
|
66
|
-
// If the consumer has already called `reader.read()`,
|
|
67
|
-
// before the producer tries to `enqueue`,
|
|
68
|
-
// `controller.desiredSize` is `0` and normal `waterMarkLow` signal
|
|
69
|
-
// will never trigger,
|
|
70
|
-
// (because `ReadableStream` prevents reentrance of `pull`)
|
|
71
|
-
// The stream will stuck.
|
|
72
|
-
//
|
|
73
|
-
// So we need a special signal for this case.
|
|
74
|
-
zeroHighWaterMarkAllowEnqueue = false;
|
|
75
|
-
controller.enqueue(chunk);
|
|
76
|
-
logger?.({
|
|
77
|
-
source: "producer",
|
|
78
|
-
operation: "enqueue",
|
|
79
|
-
value: chunk,
|
|
80
|
-
phase: "complete",
|
|
81
|
-
});
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (controller.desiredSize <= 0) {
|
|
85
|
-
logger?.({
|
|
86
|
-
source: "producer",
|
|
87
|
-
operation: "enqueue",
|
|
88
|
-
value: chunk,
|
|
89
|
-
phase: "waiting",
|
|
90
|
-
});
|
|
91
|
-
waterMarkLow = new PromiseResolver();
|
|
92
|
-
await waterMarkLow.promise;
|
|
93
|
-
// Recheck consumer cancellation after async operations.
|
|
94
|
-
if (abortController.signal.aborted) {
|
|
95
|
-
logger?.({
|
|
96
|
-
source: "producer",
|
|
97
|
-
operation: "enqueue",
|
|
98
|
-
value: chunk,
|
|
99
|
-
phase: "ignored",
|
|
100
|
-
});
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
controller.enqueue(chunk);
|
|
105
|
-
logger?.({
|
|
106
|
-
source: "producer",
|
|
107
|
-
operation: "enqueue",
|
|
108
|
-
value: chunk,
|
|
109
|
-
phase: "complete",
|
|
110
|
-
});
|
|
111
|
-
},
|
|
183
|
+
enqueue: async (chunk) =>
|
|
184
|
+
// Run `enqueue`s in serial
|
|
185
|
+
// Use `async/await` to always return a `Promise`
|
|
186
|
+
await tasks.enqueue(() => enqueue(chunk)),
|
|
112
187
|
close() {
|
|
113
|
-
|
|
114
|
-
source: "producer",
|
|
115
|
-
operation: "close",
|
|
116
|
-
explicit: true,
|
|
117
|
-
phase: "start",
|
|
118
|
-
});
|
|
119
|
-
// Since `enqueue` on an cancelled stream won't throw an error,
|
|
120
|
-
// so does `close`.
|
|
121
|
-
if (abortController.signal.aborted) {
|
|
122
|
-
logger?.({
|
|
123
|
-
source: "producer",
|
|
124
|
-
operation: "close",
|
|
125
|
-
explicit: true,
|
|
126
|
-
phase: "ignored",
|
|
127
|
-
});
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
controller.close();
|
|
131
|
-
logger?.({
|
|
132
|
-
source: "producer",
|
|
133
|
-
operation: "close",
|
|
134
|
-
explicit: true,
|
|
135
|
-
phase: "complete",
|
|
136
|
-
});
|
|
188
|
+
close(true);
|
|
137
189
|
},
|
|
138
190
|
error(e) {
|
|
139
|
-
|
|
140
|
-
source: "producer",
|
|
141
|
-
operation: "error",
|
|
142
|
-
explicit: true,
|
|
143
|
-
phase: "start",
|
|
144
|
-
});
|
|
145
|
-
// Calling `error` on an already closed or errored stream is a no-op.
|
|
146
|
-
controller.error(e);
|
|
147
|
-
logger?.({
|
|
148
|
-
source: "producer",
|
|
149
|
-
operation: "error",
|
|
150
|
-
explicit: true,
|
|
151
|
-
phase: "complete",
|
|
152
|
-
});
|
|
191
|
+
error(e, true);
|
|
153
192
|
},
|
|
154
193
|
});
|
|
155
|
-
if (
|
|
194
|
+
if (!stopped && isPromiseLike(result)) {
|
|
156
195
|
// If `source` returns a `Promise`,
|
|
157
196
|
// close the stream when the `Promise` is resolved,
|
|
158
197
|
// and error the stream when the `Promise` is rejected.
|
|
159
198
|
// The producer can return a never-settling `Promise`
|
|
160
199
|
// to disable this behavior.
|
|
161
|
-
result.then(() =>
|
|
162
|
-
logger?.({
|
|
163
|
-
source: "producer",
|
|
164
|
-
operation: "close",
|
|
165
|
-
explicit: false,
|
|
166
|
-
phase: "start",
|
|
167
|
-
});
|
|
168
|
-
try {
|
|
169
|
-
controller.close();
|
|
170
|
-
logger?.({
|
|
171
|
-
source: "producer",
|
|
172
|
-
operation: "close",
|
|
173
|
-
explicit: false,
|
|
174
|
-
phase: "complete",
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
logger?.({
|
|
179
|
-
source: "producer",
|
|
180
|
-
operation: "close",
|
|
181
|
-
explicit: false,
|
|
182
|
-
phase: "ignored",
|
|
183
|
-
});
|
|
184
|
-
// The stream is already closed by the producer,
|
|
185
|
-
// Or cancelled by the consumer.
|
|
186
|
-
}
|
|
187
|
-
}, (e) => {
|
|
188
|
-
logger?.({
|
|
189
|
-
source: "producer",
|
|
190
|
-
operation: "error",
|
|
191
|
-
explicit: false,
|
|
192
|
-
phase: "start",
|
|
193
|
-
});
|
|
194
|
-
controller.error(e);
|
|
195
|
-
logger?.({
|
|
196
|
-
source: "producer",
|
|
197
|
-
operation: "error",
|
|
198
|
-
explicit: false,
|
|
199
|
-
phase: "complete",
|
|
200
|
-
});
|
|
201
|
-
});
|
|
200
|
+
result.then(() => close(false), (e) => error(e, false));
|
|
202
201
|
}
|
|
203
202
|
},
|
|
204
203
|
pull: () => {
|
|
@@ -208,7 +207,8 @@ export class PushReadableStream extends ReadableStream {
|
|
|
208
207
|
phase: "start",
|
|
209
208
|
});
|
|
210
209
|
if (waterMarkLow) {
|
|
211
|
-
waterMarkLow.resolve();
|
|
210
|
+
waterMarkLow.resolve(undefined);
|
|
211
|
+
waterMarkLow = undefined;
|
|
212
212
|
}
|
|
213
213
|
else if (strategy?.highWaterMark === 0) {
|
|
214
214
|
zeroHighWaterMarkAllowEnqueue = true;
|
|
@@ -225,9 +225,9 @@ export class PushReadableStream extends ReadableStream {
|
|
|
225
225
|
operation: "cancel",
|
|
226
226
|
phase: "start",
|
|
227
227
|
});
|
|
228
|
+
stopped = true;
|
|
228
229
|
abortController.abort(reason);
|
|
229
|
-
|
|
230
|
-
waterMarkLow?.resolve();
|
|
230
|
+
waterMarkLow?.reject();
|
|
231
231
|
logger?.({
|
|
232
232
|
source: "consumer",
|
|
233
233
|
operation: "cancel",
|
package/esm/push-readable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push-readable.js","sourceRoot":"","sources":["../src/push-readable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"push-readable.js","sourceRoot":"","sources":["../src/push-readable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAOlE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsD5C,MAAM,OAAO,kBAAsB,SAAQ,cAAiB;IACxD;;;;;;OAMG;IACH,YACI,MAAmC,EACnC,QAA6B,EAC7B,MAA8B;QAE9B,IAAI,UAA+C,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,SAAS,EAAE,CAAC;QAE9B,IAAI,6BAA6B,GAAG,KAAK,CAAC;QAC1C,8CAA8C;QAC9C,wEAAwE;QACxE,qCAAqC;QACrC,IAAI,YAAoD,CAAC;QAEzD,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,4DAA4D;QAC5D,uEAAuE;QACvE,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,MAAM,OAAO,GAAG,CAAC,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AAM;oBACjB,KAAK,EAAE,UAAU;iBACpB,CAAC,CAAC;YACP,CAAC;YACD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;gBACf,MAAM,EAAE,CAAC;oBACL,MAAM,EAAE,UAAU;oBAClB,SAAS,EAAE,QAAQ;oBACnB,KAAK,EAAE,OAAO;iBACjB,CAAC,CAAC;gBAEH,OAAO,GAAG,IAAI,CAAC;gBACf,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC9B,YAAY,EAAE,MAAM,EAAE,CAAC;gBAEvB,MAAM,EAAE,CAAC;oBACL,MAAM,EAAE,UAAU;oBAClB,SAAS,EAAE,QAAQ;oBACnB,KAAK,EAAE,UAAU;iBACpB,CAAC,CAAC;YACP,CAAC;SACJ,EACD,QAAQ,CACX,CAAC;IACN,CAAC;CACJ"}
|
package/esm/split-string.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { TransformStream } from "./
|
|
1
|
+
import { TransformStream } from "./global/index.js";
|
|
2
2
|
export declare class SplitStringStream extends TransformStream<string, string> {
|
|
3
|
-
constructor(separator: string
|
|
3
|
+
constructor(separator: string, options?: {
|
|
4
|
+
trim?: boolean | undefined;
|
|
5
|
+
trimEnd?: boolean | undefined;
|
|
6
|
+
skipEmpty?: boolean | undefined;
|
|
7
|
+
});
|
|
4
8
|
}
|
|
5
9
|
//# sourceMappingURL=split-string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-string.d.ts","sourceRoot":"","sources":["../src/split-string.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"split-string.d.ts","sourceRoot":"","sources":["../src/split-string.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,iBAAkB,SAAQ,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC;gBAE9D,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;QACN,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC9B,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KACnC;CAwDR"}
|
package/esm/split-string.js
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
|
-
import { TransformStream } from "./
|
|
1
|
+
import { TransformStream } from "./global/index.js";
|
|
2
2
|
export class SplitStringStream extends TransformStream {
|
|
3
|
-
constructor(separator) {
|
|
3
|
+
constructor(separator, options) {
|
|
4
4
|
let remaining = undefined;
|
|
5
|
+
const separatorLength = separator.length;
|
|
6
|
+
if (separatorLength === 0) {
|
|
7
|
+
throw new Error("separator must not be empty");
|
|
8
|
+
}
|
|
9
|
+
const trim = !!options?.trim;
|
|
10
|
+
const trimEnd = !!options?.trimEnd;
|
|
11
|
+
const skipEmpty = !!options?.skipEmpty;
|
|
12
|
+
const enqueue = (controller, value) => {
|
|
13
|
+
if (trim) {
|
|
14
|
+
value = value.trim();
|
|
15
|
+
}
|
|
16
|
+
else if (trimEnd) {
|
|
17
|
+
value = value.trimEnd();
|
|
18
|
+
}
|
|
19
|
+
if (value || !skipEmpty) {
|
|
20
|
+
controller.enqueue(value);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
5
23
|
super({
|
|
6
24
|
transform(chunk, controller) {
|
|
7
|
-
if (remaining) {
|
|
25
|
+
if (remaining !== undefined) {
|
|
8
26
|
chunk = remaining + chunk;
|
|
9
27
|
remaining = undefined;
|
|
10
28
|
}
|
|
@@ -12,16 +30,19 @@ export class SplitStringStream extends TransformStream {
|
|
|
12
30
|
while (start < chunk.length) {
|
|
13
31
|
const index = chunk.indexOf(separator, start);
|
|
14
32
|
if (index === -1) {
|
|
33
|
+
// `remaining` can't be an empty string
|
|
34
|
+
// because `start` is less than `chunk.length`
|
|
15
35
|
remaining = chunk.substring(start);
|
|
16
36
|
break;
|
|
17
37
|
}
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
const value = chunk.substring(start, index);
|
|
39
|
+
enqueue(controller, value);
|
|
40
|
+
start = index + separatorLength;
|
|
20
41
|
}
|
|
21
42
|
},
|
|
22
43
|
flush(controller) {
|
|
23
|
-
if (remaining) {
|
|
24
|
-
|
|
44
|
+
if (remaining !== undefined) {
|
|
45
|
+
enqueue(controller, remaining);
|
|
25
46
|
}
|
|
26
47
|
},
|
|
27
48
|
});
|
package/esm/split-string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-string.js","sourceRoot":"","sources":["../src/split-string.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"split-string.js","sourceRoot":"","sources":["../src/split-string.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,OAAO,iBAAkB,SAAQ,eAA+B;IAClE,YACI,SAAiB,EACjB,OAIC;QAED,IAAI,SAAS,GAAuB,SAAS,CAAC;QAC9C,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC;QACzC,IAAI,eAAe,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC;QAC7B,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC;QACnC,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC;QACvC,MAAM,OAAO,GAAG,CACZ,UAAoD,EACpD,KAAa,EACf,EAAE;YACA,IAAI,IAAI,EAAE,CAAC;gBACP,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;iBAAM,IAAI,OAAO,EAAE,CAAC;gBACjB,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;YAC5B,CAAC;YAED,IAAI,KAAK,IAAI,CAAC,SAAS,EAAE,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AAM,EAAE,EAAE;YACb,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"struct-deserialize.js","sourceRoot":"","sources":["../src/struct-deserialize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAElE,MAAM,OAAO,uBAA2B,SAAQ,uBAA0B;IACtE,YAAY,MAA6B;QACrC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YACb,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StructInit, StructSerializer } from "@yume-chan/struct";
|
|
2
|
-
import { TransformStream } from "./
|
|
2
|
+
import { TransformStream } from "./global/index.js";
|
|
3
3
|
export declare class StructSerializeStream<T extends StructSerializer<unknown>> extends TransformStream<StructInit<T>, Uint8Array> {
|
|
4
4
|
constructor(struct: T);
|
|
5
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct-serialize.d.ts","sourceRoot":"","sources":["../src/struct-serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"struct-serialize.d.ts","sourceRoot":"","sources":["../src/struct-serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,qBAAqB,CAC9B,CAAC,SAAS,gBAAgB,CAAC,OAAO,CAAC,CACrC,SAAQ,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;gBACpC,MAAM,EAAE,CAAC;CAOxB"}
|
package/esm/struct-serialize.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct-serialize.js","sourceRoot":"","sources":["../src/struct-serialize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"struct-serialize.js","sourceRoot":"","sources":["../src/struct-serialize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,OAAO,qBAEX,SAAQ,eAA0C;IAChD,YAAY,MAAS;QACjB,KAAK,CAAC;YACF,SAAS,CAAC,KAAK,EAAE,UAAU;gBACvB,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YAChD,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MaybePromise, MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
+
export declare class TaskQueue {
|
|
3
|
+
#private;
|
|
4
|
+
enqueue<T extends MaybePromiseLike<unknown>>(task: () => T, bail?: boolean): T;
|
|
5
|
+
enqueue<T>(task: () => T, bail?: boolean): MaybePromise<T>;
|
|
6
|
+
dispose(): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=task-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.d.ts","sourceRoot":"","sources":["../src/task-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGvE,qBAAa,SAAS;;IAIlB,OAAO,CAAC,CAAC,SAAS,gBAAgB,CAAC,OAAO,CAAC,EACvC,IAAI,EAAE,MAAM,CAAC,EACb,IAAI,CAAC,EAAE,OAAO,GACf,CAAC;IACJ,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC;IAsD1D,OAAO;CAGV"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isPromiseLike } from "@yume-chan/async";
|
|
2
|
+
export class TaskQueue {
|
|
3
|
+
#ready;
|
|
4
|
+
#disposed = false;
|
|
5
|
+
enqueue(task, bail = false) {
|
|
6
|
+
if (this.#disposed) {
|
|
7
|
+
throw new Error("TaskQueue is disposed");
|
|
8
|
+
}
|
|
9
|
+
if (!this.#ready) {
|
|
10
|
+
// Init state or all previous tasks are synchronous
|
|
11
|
+
try {
|
|
12
|
+
const result = task();
|
|
13
|
+
if (isPromiseLike(result)) {
|
|
14
|
+
this.#ready = result.then(() => { }, (e) => {
|
|
15
|
+
if (bail) {
|
|
16
|
+
throw e;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
if (bail) {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
25
|
+
const promise = Promise.reject(e);
|
|
26
|
+
// Suppress unhandled-rejection without resolving `#ready`
|
|
27
|
+
void promise.catch(() => { });
|
|
28
|
+
this.#ready = promise;
|
|
29
|
+
}
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const result = this.#ready.then(() => {
|
|
34
|
+
if (this.#disposed) {
|
|
35
|
+
throw new Error("TaskQueue is disposed");
|
|
36
|
+
}
|
|
37
|
+
return task();
|
|
38
|
+
});
|
|
39
|
+
this.#ready = result.then(() => { }, (e) => {
|
|
40
|
+
if (bail || this.#disposed) {
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
dispose() {
|
|
47
|
+
this.#disposed = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=task-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AI,CAAC,SAAS,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CACrB,GAAG,EAAE,GAAE,CAAC,EACR,CAAC,CAAC,EAAE,EAAE;YACF,IAAI,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACzB,MAAM,CAAC,CAAC;YACZ,CAAC;QACL,CAAC,CACJ,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,OAAO;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;CACJ"}
|
package/esm/try-close.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { BufferedReadableStream } from "./buffered.js";
|
|
2
|
-
import type { ReadableStream, ReadableStreamDefaultReader } from "./stream.js";
|
|
3
1
|
export declare function tryClose(value: {
|
|
4
2
|
close(): PromiseLike<void>;
|
|
5
3
|
}): Promise<boolean>;
|
|
6
4
|
export declare function tryClose(value: {
|
|
7
5
|
close(): void;
|
|
8
6
|
}): boolean;
|
|
9
|
-
export declare function tryCancel(stream:
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export declare function tryCancel(stream: {
|
|
8
|
+
cancel(): Promise<void>;
|
|
9
|
+
}): Promise<boolean>;
|
|
12
10
|
//# sourceMappingURL=try-close.d.ts.map
|
package/esm/try-close.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"try-close.d.ts","sourceRoot":"","sources":["../src/try-close.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"try-close.d.ts","sourceRoot":"","sources":["../src/try-close.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC5B,KAAK,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;CAC9B,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AACrB,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAAE,KAAK,IAAI,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC;AAgB5D,wBAAsB,SAAS,CAAC,MAAM,EAAE;IACpC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnB"}
|