EdgeAIG's picture
download
raw
1.76 kB
/**
* Low-level helpers for adapting push-based SQL row sources into Effect
* streams.
*
* SQL drivers often expose large query results through cursors, event emitters,
* or driver-specific streams that push rows as they arrive. This module
* provides the small interop layer used by SQL integrations to turn those
* producers into `Stream` values for `Statement.stream` and
* `Connection.executeStream`, so callers can process large result sets
* incrementally instead of materializing every row in memory.
*
* @since 4.0.0
*/
import * as Cause from "../../Cause.js";
import * as Effect from "../../Effect.js";
import * as Queue from "../../Queue.js";
import * as Stream from "../../Stream.js";
/**
* Creates a stream from a callback-style producer with pause and resume
* callbacks that are triggered when the internal queue applies backpressure.
*
* @category constructors
* @since 4.0.0
*/
export const asyncPauseResume = (register, bufferSize = 128) => Stream.callback(queue => Effect.suspend(() => {
let cbs;
let paused = false;
const offer = arr => {
if (arr.length === 0) return;
const isFull = Queue.isFullUnsafe(queue);
if (!isFull || isFull && paused) {
return Effect.runFork(Queue.offerAll(queue, arr));
}
paused = true;
cbs.onPause();
return Queue.offerAll(queue, arr).pipe(Effect.tap(() => Effect.sync(() => {
cbs.onResume();
paused = false;
})), Effect.runFork);
};
return Effect.map(register({
single: item => offer([item]),
array: chunk => offer(chunk),
fail: error => Queue.failCauseUnsafe(queue, Cause.fail(error)),
end: () => Queue.endUnsafe(queue)
}), _ => {
cbs = _;
});
}), {
bufferSize
});
//# sourceMappingURL=SqlStream.js.map

Xet Storage Details

Size:
1.76 kB
·
Xet hash:
b94ea40cd7708e0883faee60f45df8313d611af8e192648f9cf940e951eb39a1

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.