feat: progress bar and incremental PoW generation

This commit is contained in:
Aravinth Manivannan
2023-10-29 06:28:05 +05:30
parent ad4582cc16
commit 9dfb0713ad
8 changed files with 221 additions and 137 deletions

View File

@@ -6,17 +6,31 @@
import log from "../logger";
import prove from "./prove";
import { PoWConfig, ServiceWorkerWork } from "./types";
import { PoWConfig, ServiceWorkerMessage, ServiceWorkerWork } from "./types";
log.log("worker registered");
onmessage = async (e) => {
console.debug("message received at worker");
const config: PoWConfig = e.data;
const work = await prove(config);
const res: ServiceWorkerWork = {
const progressCallback = (nonce: number) => {
const res: ServiceWorkerMessage = {
type: "progress",
nonce: nonce,
};
postMessage(res);
};
const work = await prove(config, progressCallback);
const w: ServiceWorkerWork = {
work,
};
const res: ServiceWorkerMessage = {
type: "work",
value: w,
};
postMessage(res);
};