Skip to content

Commit f758cb6

Browse files
committed
pw
1 parent a99837f commit f758cb6

4 files changed

Lines changed: 56 additions & 14 deletions

File tree

build/index.cjs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ var Queue = class _Queue {
159159
const r = callback(v);
160160
if (r !== void 0) outQueue.push(r);
161161
};
162-
this.map(c).then(outQueue.end);
162+
void this.map(c).then(outQueue.end);
163163
return outQueue;
164164
};
165165
/**
@@ -174,7 +174,7 @@ var Queue = class _Queue {
174174
const r = await callback(v);
175175
if (r !== void 0) outQueue.push(r);
176176
};
177-
this[n === Infinity ? "map" : "mapParallel"](c, n).then(outQueue.end);
177+
void this[n === Infinity ? "map" : "mapParallel"](c, n).then(outQueue.end);
178178
return outQueue;
179179
};
180180
/**
@@ -191,7 +191,7 @@ var Queue = class _Queue {
191191
else if (index === 1) q2.push(value);
192192
else throw new Error("Invalid index");
193193
};
194-
this.map(c).then(() => {
194+
void this.map(c).then(() => {
195195
q1.end();
196196
q2.end();
197197
});
@@ -205,7 +205,7 @@ var Queue = class _Queue {
205205
batch = (n) => {
206206
const outQueue = new _Queue();
207207
let buffer = [];
208-
this.map((v) => {
208+
void this.map((v) => {
209209
buffer.push(v);
210210
if (buffer.length === n) {
211211
outQueue.push(buffer);
@@ -223,7 +223,7 @@ var Queue = class _Queue {
223223
*/
224224
flat = () => {
225225
const outQueue = new _Queue();
226-
this.map((v) => {
226+
void this.map((v) => {
227227
if (v instanceof Array) outQueue.push(...v);
228228
else throw new Error("Value is not an array");
229229
}).then(outQueue.end);
@@ -246,7 +246,7 @@ var Queue = class _Queue {
246246
else if (index === 1) q2.push(value);
247247
else throw new Error("Invalid index");
248248
};
249-
this[n === Infinity ? "map" : "mapParallel"](c, n).then(() => {
249+
void this[n === Infinity ? "map" : "mapParallel"](c, n).then(() => {
250250
q1.end();
251251
q2.end();
252252
});
@@ -259,9 +259,24 @@ var Queue = class _Queue {
259259
*/
260260
umerge = (q) => {
261261
const outQueue = new _Queue();
262-
Promise.all([this, q].map((q2) => q2.map(outQueue.push))).then(outQueue.end);
262+
void Promise.all([this, q].map((q2) => q2.map(outQueue.push))).then(
263+
outQueue.end
264+
);
263265
return outQueue;
264266
};
267+
/**
268+
* Creates multiple clones of the queue.
269+
* @param count The number of clone queues to create (default: 1).
270+
* @returns An array of cloned queues.
271+
*/
272+
clone = (count = 1) => {
273+
if (count < 1) throw new Error("Count must be at least 1");
274+
const queues = Array.from({ length: count }, () => new _Queue());
275+
void this.map((v) => queues.map((q) => q.push(v))).then(
276+
() => queues.map((q) => q.end())
277+
);
278+
return queues;
279+
};
265280
/**
266281
* Collects all the values in the queue into an array.
267282
* @returns A promise that resolves to an array containing all the values in the queue.

build/index.d.cts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ declare class Queue<T> {
102102
* @returns A new queue containing the merged values.
103103
*/
104104
umerge: (q: Queue<T>) => Queue<T>;
105+
/**
106+
* Creates multiple clones of the queue.
107+
* @param count The number of clone queues to create (default: 1).
108+
* @returns An array of cloned queues.
109+
*/
110+
clone: (count?: number) => Queue<T>[];
105111
/**
106112
* Collects all the values in the queue into an array.
107113
* @returns A promise that resolves to an array containing all the values in the queue.

build/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ declare class Queue<T> {
102102
* @returns A new queue containing the merged values.
103103
*/
104104
umerge: (q: Queue<T>) => Queue<T>;
105+
/**
106+
* Creates multiple clones of the queue.
107+
* @param count The number of clone queues to create (default: 1).
108+
* @returns An array of cloned queues.
109+
*/
110+
clone: (count?: number) => Queue<T>[];
105111
/**
106112
* Collects all the values in the queue into an array.
107113
* @returns A promise that resolves to an array containing all the values in the queue.

build/index.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var Queue = class _Queue {
135135
const r = callback(v);
136136
if (r !== void 0) outQueue.push(r);
137137
};
138-
this.map(c).then(outQueue.end);
138+
void this.map(c).then(outQueue.end);
139139
return outQueue;
140140
};
141141
/**
@@ -150,7 +150,7 @@ var Queue = class _Queue {
150150
const r = await callback(v);
151151
if (r !== void 0) outQueue.push(r);
152152
};
153-
this[n === Infinity ? "map" : "mapParallel"](c, n).then(outQueue.end);
153+
void this[n === Infinity ? "map" : "mapParallel"](c, n).then(outQueue.end);
154154
return outQueue;
155155
};
156156
/**
@@ -167,7 +167,7 @@ var Queue = class _Queue {
167167
else if (index === 1) q2.push(value);
168168
else throw new Error("Invalid index");
169169
};
170-
this.map(c).then(() => {
170+
void this.map(c).then(() => {
171171
q1.end();
172172
q2.end();
173173
});
@@ -181,7 +181,7 @@ var Queue = class _Queue {
181181
batch = (n) => {
182182
const outQueue = new _Queue();
183183
let buffer = [];
184-
this.map((v) => {
184+
void this.map((v) => {
185185
buffer.push(v);
186186
if (buffer.length === n) {
187187
outQueue.push(buffer);
@@ -199,7 +199,7 @@ var Queue = class _Queue {
199199
*/
200200
flat = () => {
201201
const outQueue = new _Queue();
202-
this.map((v) => {
202+
void this.map((v) => {
203203
if (v instanceof Array) outQueue.push(...v);
204204
else throw new Error("Value is not an array");
205205
}).then(outQueue.end);
@@ -222,7 +222,7 @@ var Queue = class _Queue {
222222
else if (index === 1) q2.push(value);
223223
else throw new Error("Invalid index");
224224
};
225-
this[n === Infinity ? "map" : "mapParallel"](c, n).then(() => {
225+
void this[n === Infinity ? "map" : "mapParallel"](c, n).then(() => {
226226
q1.end();
227227
q2.end();
228228
});
@@ -235,9 +235,24 @@ var Queue = class _Queue {
235235
*/
236236
umerge = (q) => {
237237
const outQueue = new _Queue();
238-
Promise.all([this, q].map((q2) => q2.map(outQueue.push))).then(outQueue.end);
238+
void Promise.all([this, q].map((q2) => q2.map(outQueue.push))).then(
239+
outQueue.end
240+
);
239241
return outQueue;
240242
};
243+
/**
244+
* Creates multiple clones of the queue.
245+
* @param count The number of clone queues to create (default: 1).
246+
* @returns An array of cloned queues.
247+
*/
248+
clone = (count = 1) => {
249+
if (count < 1) throw new Error("Count must be at least 1");
250+
const queues = Array.from({ length: count }, () => new _Queue());
251+
void this.map((v) => queues.map((q) => q.push(v))).then(
252+
() => queues.map((q) => q.end())
253+
);
254+
return queues;
255+
};
241256
/**
242257
* Collects all the values in the queue into an array.
243258
* @returns A promise that resolves to an array containing all the values in the queue.

0 commit comments

Comments
 (0)