This commit is contained in:
2025-05-12 05:38:44 +09:00
parent dced21c3f8
commit 6d78bfa46e
8120 changed files with 1161564 additions and 0 deletions

View File

@ -0,0 +1 @@
export { asyncIterator, type ReadableStreamIteratorOptions, } from "../core/asyncIterator.js";

View File

@ -0,0 +1,89 @@
const a = Object.getPrototypeOf(
Object.getPrototypeOf(
/* istanbul ignore next */
async function* () {
}
).prototype
);
class c {
#t;
#n;
#r = !1;
#e = void 0;
constructor(e, t) {
this.#t = e, this.#n = t;
}
next() {
const e = () => this.#s();
return this.#e = this.#e ? this.#e.then(e, e) : e(), this.#e;
}
return(e) {
const t = () => this.#i(e);
return this.#e ? this.#e.then(t, t) : t();
}
async #s() {
if (this.#r)
return {
done: !0,
value: void 0
};
let e;
try {
e = await this.#t.read();
} catch (t) {
throw this.#e = void 0, this.#r = !0, this.#t.releaseLock(), t;
}
return e.done && (this.#e = void 0, this.#r = !0, this.#t.releaseLock()), e;
}
async #i(e) {
if (this.#r)
return {
done: !0,
value: e
};
if (this.#r = !0, !this.#n) {
const t = this.#t.cancel(e);
return this.#t.releaseLock(), await t, {
done: !0,
value: e
};
}
return this.#t.releaseLock(), {
done: !0,
value: e
};
}
}
const n = Symbol();
function i() {
return this[n].next();
}
Object.defineProperty(i, "name", { value: "next" });
function o(r) {
return this[n].return(r);
}
Object.defineProperty(o, "name", { value: "return" });
const u = Object.create(a, {
next: {
enumerable: !0,
configurable: !0,
writable: !0,
value: i
},
return: {
enumerable: !0,
configurable: !0,
writable: !0,
value: o
}
});
function h({ preventCancel: r = !1 } = {}) {
const e = this.getReader(), t = new c(
e,
r
), s = Object.create(u);
return s[n] = t, s;
}
export {
h as asyncIterator
};

View File

@ -0,0 +1 @@
export { fromAnyIterable } from "../core/fromAnyIterable.js";

View File

@ -0,0 +1,34 @@
function c(n) {
const t = a(n);
return new ReadableStream(
{
async pull(e) {
const { value: r, done: o } = await t.next();
o ? e.close() : e.enqueue(r);
},
async cancel(e) {
if (typeof t.return == "function" && typeof await t.return(e) != "object")
throw new TypeError("return() fulfills with a non-object.");
return e;
}
},
new CountQueuingStrategy({
highWaterMark: 0
})
);
}
function a(n) {
let t = n[Symbol.asyncIterator]?.bind(n);
if (t === void 0) {
const r = n[Symbol.iterator](), o = {
[Symbol.iterator]: () => r
};
t = async function* () {
return yield* o;
};
}
return t();
}
export {
c as fromAnyIterable
};

View File

@ -0,0 +1,2 @@
export * from "./asyncIterator.js";
export * from "./fromAnyIterable.js";

View File

@ -0,0 +1,6 @@
import { asyncIterator as e } from "./asyncIterator.js";
import { fromAnyIterable as a } from "./fromAnyIterable.js";
export {
e as asyncIterator,
a as fromAnyIterable
};