mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-08-04 22:53:05 -07:00
35 lines
869 B
JavaScript
35 lines
869 B
JavaScript
import { WorkerClient } from "../worker-client.js";
|
|
|
|
const WORKER_URL = import.meta.resolve("./worker.js");
|
|
|
|
export class AskSource {
|
|
#client = new WorkerClient(WORKER_URL, {
|
|
failed: "The source worker failed",
|
|
stopped: "Source search stopped",
|
|
});
|
|
|
|
prewarm() {
|
|
return this.#client.request("prewarm", {});
|
|
}
|
|
|
|
/**
|
|
* @param {string} query
|
|
* @param {string | undefined} path
|
|
* @param {"definition" | "implementation" | "availability" | undefined} focus
|
|
* @param {((progress: { loaded: number, total: number }) => void) | undefined} [onProgress]
|
|
*/
|
|
search(query, path, focus, onProgress) {
|
|
return this.#client.request(
|
|
"search",
|
|
{ query, path, focus },
|
|
onProgress
|
|
? ({ loaded, total }) => onProgress({ loaded, total })
|
|
: undefined,
|
|
);
|
|
}
|
|
|
|
terminate() {
|
|
this.#client.terminate();
|
|
}
|
|
}
|