Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/wgps/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class WgpsStatusEvent
extends CustomEvent<{ remaining: number; all: number }> {
constructor(remaining: number, all: number) {
super("status", {
detail: {
remaining,
all,
},
});
}
}
27 changes: 27 additions & 0 deletions src/wgps/range_counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { WillowError } from "../errors.ts";
import { COVERS_NONE } from "./types.ts";

export class RangeCounter {
private count = 0n;
private inProgress = new Set<bigint>();

getNext() {
this.inProgress.add(this.count);
return this.count++;
}

done(covers: bigint | typeof COVERS_NONE) {
if (covers !== COVERS_NONE) {
if (!this.inProgress.delete(covers)) {
throw new WillowError("Answered range without request");
}
}
}

info() {
return {
remaining: BigInt(this.inProgress.size),
all: this.count,
};
}
}
Loading