Cleanup rust/ts interface a but more w new rustContext (#5848)
* do the rust side Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup ts side Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * typo Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -4,6 +4,7 @@ import {
|
||||
ExecState,
|
||||
execStateFromRust,
|
||||
initPromise,
|
||||
mockExecStateFromRust,
|
||||
} from 'lang/wasm'
|
||||
import { getModule, ModuleType } from 'lib/wasm_lib_wrapper'
|
||||
import { fileSystemManager } from 'lang/std/fileSystemManager'
|
||||
@ -48,6 +49,9 @@ export default class RustContext {
|
||||
// Create a new context instance
|
||||
async create() {
|
||||
this.rustInstance = getModule()
|
||||
// We need this await here, DO NOT REMOVE it even if your editor says it's
|
||||
// unnecessary. The constructor of the module is async and it will not
|
||||
// resolve if you don't await it.
|
||||
this.ctxInstance = await new this.rustInstance.Context(
|
||||
this.engineCommandManager,
|
||||
fileSystemManager
|
||||
@ -87,6 +91,41 @@ export default class RustContext {
|
||||
return Promise.reject(emptyExecState())
|
||||
}
|
||||
|
||||
// Execute a program with in mock mode.
|
||||
async executeMock(
|
||||
node: Node<Program>,
|
||||
settings: DeepPartial<Configuration>,
|
||||
path?: string,
|
||||
usePrevMemory?: boolean
|
||||
): Promise<ExecState> {
|
||||
await this._checkInstance()
|
||||
|
||||
if (this.ctxInstance) {
|
||||
try {
|
||||
if (usePrevMemory === undefined) {
|
||||
usePrevMemory = true
|
||||
}
|
||||
|
||||
const result = await this.ctxInstance.executeMock(
|
||||
JSON.stringify(node),
|
||||
path,
|
||||
JSON.stringify(settings),
|
||||
usePrevMemory
|
||||
)
|
||||
return mockExecStateFromRust(result)
|
||||
} catch (e: any) {
|
||||
return Promise.reject(errFromErrWithOutputs(e))
|
||||
}
|
||||
}
|
||||
|
||||
// You will never get here.
|
||||
return Promise.reject(emptyExecState())
|
||||
}
|
||||
|
||||
async waitForAllEngineCommands() {
|
||||
await this.engineCommandManager.waitForAllCommands()
|
||||
}
|
||||
|
||||
get defaultPlanes() {
|
||||
return this._defaultPlanes
|
||||
}
|
||||
|
Reference in New Issue
Block a user