Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WGPS progress tracking #35

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
Loading