batch-iterable
Version:
An abstraction to work with iterables of asyncIterables
43 lines (40 loc) • 892 B
JavaScript
import test from "node:test"
import assert from "node:assert"
import { BatchIterable } from "../index.js"
test("use for await loop", async () => {
const array = [
[ ],
[ ],
]
const batchIterable = new BatchIterable(array)
let i = 0
for await (const item of batchIterable) {
let j = 0
for (const element of item) {
assert.deepStrictEqual(
element,
array[i][j],
"Element should match expected output",
)
j++
}
i++
}
})
test("use toAsyncIterable", async () => {
const array = [
[ ],
[ ],
]
const result = array.flat()
const batchIterable = new BatchIterable(array)
let i = 0
for await (const item of batchIterable.toAsyncIterable()) {
assert.deepStrictEqual(
item,
result[i],
"Element should match expected output",
)
i++
}
})