ct-engine is an entry point consisting of sandboxing, and eventual(?) query planning and scheduling. Initial focus is on web bindings. Some notes:
Simple case takes ~1ms for execution
This should be wrapped in a worker. We can expose an interface here that just postMessage's methods to the worker containing CTEngine. Doubly so after removing async handling!
Internals:
Handful of future cleanups like normalizing the marshaling of types from wasm-bindgen and providing different module/instance lifetimes (TBD on what we'll want)
Host callback now implemented via closures, with generics removed from Runtime.
import init, { CTEngine } from './ct_engine.js';
// Only needed once, call the default export function
// to fetch and setup the web assembly artifact.
await init();
// Host callback invoked by the VM via `globalThis.hostCallback()`
const hostCallback = (input) => {
switch (input.command) {
case "sum":
return Array.prototype.reduce.call(input.value, (acc, v) => {
acc += v;
return acc;
}, 0);
}
return {};
};
// Instantiate an engine
const engine = new CTEngine(hostCallback);
// Define a module definition
const definition = `
export const run = (input) => {
input.foo = input.foo + 1;
input.bar = globalThis.hostCallback({
command: "sum",
value: [1, 2, 3],
});
return input;
};
`;
// Instantiate the module.
let id = engine.define(definition);
// Call the module function.
var output = engine.run(id, { foo: 9 });
console.log("Output:", output);
console.assert(output.foo === 10);
console.assert(output.bar === 6);
ct-engine
is an entry point consisting of sandboxing, and eventual(?) query planning and scheduling. Initial focus is on web bindings. Some notes:postMessage
's methods to the worker containingCTEngine
. Doubly so after removing async handling!Internals:
Runtime
.