@hazae41/bobine 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,6 +24,11 @@ export class RpcWorkerServer {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
async #route(request) {
|
|
27
|
+
if (request.method === "ping") {
|
|
28
|
+
const _ = request.params;
|
|
29
|
+
// NOOP
|
|
30
|
+
return "pong";
|
|
31
|
+
}
|
|
27
32
|
if (request.method === "setup") {
|
|
28
33
|
const _ = request.params;
|
|
29
34
|
await this.runner.setup();
|
|
@@ -63,5 +68,6 @@ async function main() {
|
|
|
63
68
|
const json = refs.toJSON();
|
|
64
69
|
self.postMessage(json);
|
|
65
70
|
}, { passive: true });
|
|
71
|
+
self.postMessage({ id: null, result: "pong" });
|
|
66
72
|
}
|
|
67
73
|
await main();
|
|
@@ -2,7 +2,7 @@ export declare class RpcWorkerClient {
|
|
|
2
2
|
#private;
|
|
3
3
|
readonly worker: Worker;
|
|
4
4
|
constructor(worker: Worker);
|
|
5
|
-
static spawn(uuid: string, path: string): RpcWorkerClient
|
|
5
|
+
static spawn(uuid: string, path: string): Promise<RpcWorkerClient>;
|
|
6
6
|
setup(): Promise<Uint8Array<ArrayBuffer>>;
|
|
7
7
|
create(code: Uint8Array<ArrayBuffer>, salt: Uint8Array<ArrayBuffer>): Promise<string>;
|
|
8
8
|
execute(module: string, method: string, params: Uint8Array<ArrayBuffer>, sparks: bigint): Promise<Uint8Array<ArrayBuffer>>;
|
|
@@ -50,18 +50,20 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
50
50
|
var e = new Error(message);
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
|
-
import { RpcResponse } from "@hazae41/jsonrpc";
|
|
53
|
+
import { RpcRequest, RpcResponse } from "@hazae41/jsonrpc";
|
|
54
54
|
export class RpcWorkerClient {
|
|
55
55
|
worker;
|
|
56
56
|
constructor(worker) {
|
|
57
57
|
this.worker = worker;
|
|
58
58
|
}
|
|
59
|
-
static spawn(uuid, path) {
|
|
60
|
-
const url = new URL(import.meta.resolve("./bin.
|
|
59
|
+
static async spawn(uuid, path) {
|
|
60
|
+
const url = new URL(import.meta.resolve("./bin.js"));
|
|
61
61
|
url.searchParams.set("uuid", uuid);
|
|
62
62
|
url.searchParams.set("path", path);
|
|
63
63
|
const worker = new Worker(url, { type: "module" });
|
|
64
|
-
|
|
64
|
+
const client = new RpcWorkerClient(worker);
|
|
65
|
+
await client.#request({ id: null, method: "ping" });
|
|
66
|
+
return client;
|
|
65
67
|
}
|
|
66
68
|
async setup() {
|
|
67
69
|
return await this.#request({ method: "setup" });
|
|
@@ -75,15 +77,20 @@ export class RpcWorkerClient {
|
|
|
75
77
|
async simulate(module, method, params, sparks) {
|
|
76
78
|
return await this.#request({ method: "simulate", params: [module, method, params, sparks] });
|
|
77
79
|
}
|
|
78
|
-
async #request(
|
|
80
|
+
async #request(init) {
|
|
79
81
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
80
82
|
try {
|
|
83
|
+
const { id = crypto.randomUUID(), method, params } = init;
|
|
81
84
|
const stack = __addDisposableResource(env_1, new DisposableStack(), false);
|
|
82
85
|
const future = Promise.withResolvers();
|
|
83
86
|
const aborter = new AbortController();
|
|
84
87
|
stack.defer(() => aborter.abort());
|
|
88
|
+
const request = new RpcRequest(id, method, params);
|
|
85
89
|
this.worker.addEventListener("message", (event) => {
|
|
86
|
-
RpcResponse.from(event.data)
|
|
90
|
+
const response = RpcResponse.from(event.data);
|
|
91
|
+
if (response.id !== request.id)
|
|
92
|
+
return;
|
|
93
|
+
response.inspectSync(future.resolve).inspectErrSync(future.reject);
|
|
87
94
|
}, { signal: aborter.signal });
|
|
88
95
|
this.worker.addEventListener("error", (event) => {
|
|
89
96
|
future.reject(event.error);
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@hazae41/bobine",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "WebAssembly-based metered chain of compute",
|
|
6
6
|
"repository": "github:hazae41/bobine",
|
|
7
7
|
"author": "hazae41",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"examine": "deno lint ./src && deno check ./src && deno test -R ./src",
|
|
11
|
-
"prepack": "rm -rf ./out && tsc && tscousin"
|
|
12
|
-
"produce": "deno run -A ./src/mod.ts serve --data=./local --uuid=7d07d60d-cb47-4b6f-ad1d-f2650610ce67",
|
|
13
|
-
"develop": "deno run -A ./src/mod.ts serve --data=./local --uuid=7d07d60d-cb47-4b6f-ad1d-f2650610ce67 --dev"
|
|
11
|
+
"prepack": "rm -rf ./out && tsc && tscousin"
|
|
14
12
|
},
|
|
15
13
|
"files": [
|
|
16
14
|
"./out"
|