-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsume.js
53 lines (51 loc) · 1.46 KB
/
consume.js
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
43
44
45
46
47
48
49
50
51
52
53
'use strict'
exports.sync = function (queue, iterable, arrayed) {
if (arrayed) {
for (const entries of iterable) {
queue.enqueue(entries)
}
} else {
for (const entry of iterable) {
queue.push(entry)
}
}
}
exports.async = async function (queue, iterable, arrayed) {
if (typeof iterable[Symbol.asyncIterator] == 'function') {
if (arrayed) {
for await (const entries of iterable) {
for (const entry of entries) {
const promise = queue.push(entry)
if (promise != null) {
await promise
}
}
}
} else {
for await (const entry of iterable) {
const promise = queue.push(entry)
if (promise != null) {
await promise
}
}
}
} else {
if (arrayed) {
for (const entries of iterable) {
for (const entry of entries) {
const promise = queue.push(entry)
if (promise != null) {
await promise
}
}
}
} else {
for (const entry of iterable) {
const promise = queue.push(entry)
if (promise != null) {
await promise
}
}
}
}
}