/ proof-of-concept / plate-dynamics-lab
Sign in
proof-of-concept / plate-dynamics-lab
plate-dynamics-lab / packages / core / src / runner / nodeRunner.ts
33 lines · 1.0 KBBlameHistoryRaw
1import type { BackendInfo, RunRequest, RunResult, Runner } from "./types";
2import { numblVersion } from "./execute";
3import { executeRequest, type GpuProvider } from "./executeGpu";
5/**
6 * Runs numbl in the current Node process. Used by tests and scripts; cannot
7 * cancel. Pass `gpu` to run the ported time loop on a WebGPU device (the
8 * optional `webgpu` package, Google Dawn, provides one under Node).
9 */
10export class NodeRunner implements Runner {
11 private readonly info: BackendInfo = {
12 engine: "numbl",
13 version: numblVersion(),
14 optimization: "1",
15 host: "node",
16 };
17 readonly backend = Promise.resolve(this.info);
18 private readonly gpu?: GpuProvider;
20 constructor(opts: { gpu?: GpuProvider } = {}) {
21 this.gpu = opts.gpu;
22 }
24 run(req: RunRequest, onOutput?: (text: string) => void): Promise<RunResult> {
25 return executeRequest(req, this.info, onOutput, this.gpu);
26 }
27 cancel(): void {
28 /* synchronous host: nothing in flight between awaits */
29 }
30 dispose(): void {
31 /* nothing to release */
32 }
↑↓ move↵openescclose