-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwasmedge-demo.mjs
More file actions
53 lines (47 loc) · 1.07 KB
/
wasmedge-demo.mjs
File metadata and controls
53 lines (47 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import path from "node:path";
import { access } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { loadModule } from "../../src/index.js";
const currentDir = path.dirname(fileURLToPath(import.meta.url));
const artifactPath = path.join(
currentDir,
"generated",
"dist",
"isomorphic",
"module.wasm",
);
await access(artifactPath);
const harness = await loadModule({
wasmSource: artifactPath,
runtimeKind: "wasmedge",
enableThreads: false,
});
try {
const response = await harness.invoke({
methodId: "echo",
inputs: [
{
portId: "request",
typeRef: {
schemaName: "Blob.fbs",
fileIdentifier: "BLOB",
},
payload: new TextEncoder().encode("hello from WasmEdge"),
},
],
});
console.log(
JSON.stringify(
{
artifactPath,
runtime: harness.runtime,
responseStatusCode: response.statusCode,
echoedText: new TextDecoder().decode(response.outputs[0].payload),
},
null,
2,
),
);
} finally {
await harness.destroy();
}