@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
48 lines • 1.54 kB
JavaScript
/**
* One peer's baseline attempt (R3.C6.4, S07a): the frames of a view frozen at a cut, written in their FIFO
* position before every record queued behind them. `live` is rechecked after every await and before every
* frame, so a stale attempt (detached, replaced, superseded, peer gone) writes nothing further; `end` runs
* once on every path and releases the frozen source.
*/
export class BaselineBarrier {
constructor(cursor, live) {
this.cancelled = false;
this.ended = false;
this.cursor = cursor;
this.live = live;
}
get active() {
return !this.cancelled && !this.ended && this.live();
}
cancel() {
this.cancelled = true;
this.end();
}
end() {
if (this.ended)
return;
this.ended = true;
this.cursor.release();
}
/**
* Writes `head` (a recovery's gap line) once the cursor has fixed its view, then the frames in order; `write`
* resolves once the sink accepted the line.
*/
async deliver(write, head) {
try {
if (!this.active)
return;
let line = await this.cursor.next();
if (head !== undefined && this.active)
await write(head);
while (line !== undefined && this.active) {
await write(line);
line = await this.cursor.next();
}
}
finally {
this.end();
}
}
}
//# sourceMappingURL=socket-baseline-barrier.js.map