Skip to content

Commit

Permalink
feat: worker-relay: add logging to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
v0l committed Dec 21, 2024
1 parent 201f194 commit 609361d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/worker-relay/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventMetadata, NostrEvent, OkResponse, ReqCommand, WorkerMessage, WorkerMessageCommand } from "./types";
import { debugLog, setLogging } from "./debug";
import { EventMetadata, NostrEvent, OkResponse, ReqCommand, WorkerMessage, WorkerMessageCommand, unixNowMs } from "./types";
import { v4 as uuid } from "uuid";

export interface InitAargs {
Expand Down Expand Up @@ -92,6 +93,7 @@ export class WorkerRelayInterface {
}

async debug(v: string) {
setLogging(true);
return await this.#workerRpc<string, boolean>("debug", v);
}

Expand All @@ -102,6 +104,7 @@ export class WorkerRelayInterface {
cmd,
args,
} as WorkerMessage<T>;
const start = unixNowMs();
return await new Promise<R>((resolve, reject) => {
this.#worker.postMessage(msg);
const t = setTimeout(() => {
Expand All @@ -115,6 +118,7 @@ export class WorkerRelayInterface {
reject(cmdReply.args.error);
return;
}
debugLog("interface", `${cmd} took ${(unixNowMs() - start).toFixed(1)}ms`, args);
resolve(cmdReply.args);
});
});
Expand Down

0 comments on commit 609361d

Please sign in to comment.