Files
SnowLuma/.pnpm-store/v11/files/57/0541715ddb277a585d8cebba4a6b01d23ddc2dcc2a72880329f4601fba52f47d56af746cae5b68888c139819befaf9a5eb26448cb446ceb8d31d21d59fcda5
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

26 lines
808 B
Plaintext

import { StreamingApi } from "../../utils/stream.js";
import { isOldBunVersion } from "./utils.js";
//#region src/helper/streaming/stream.ts
const contextStash = /* @__PURE__ */ new WeakMap();
const stream = (c, cb, onError) => {
const { readable, writable } = new TransformStream();
const stream = new StreamingApi(writable, readable);
if (isOldBunVersion()) c.req.raw.signal.addEventListener("abort", () => {
if (!stream.closed) stream.abort();
});
contextStash.set(stream.responseReadable, c);
(async () => {
try {
await cb(stream);
} catch (e) {
if (e === void 0) {} else if (e instanceof Error && onError) await onError(e, stream);
else console.error(e);
} finally {
stream.close();
}
})();
return c.newResponse(stream.responseReadable);
};
//#endregion
export { stream };