Compare commits

..

6 Commits

3 changed files with 23 additions and 3 deletions

View File

@ -82,6 +82,7 @@ export default class Go {
private exited = false; private exited = false;
private _resolveCallbackPromise?: () => void; private _resolveCallbackPromise?: () => void;
importObject: ImportObject; importObject: ImportObject;
private _pendingEvent?: any;
constructor() { constructor() {
this._callbackTimeouts = new Map(); this._callbackTimeouts = new Map();
@ -437,6 +438,16 @@ export default class Go {
} }
this._inst.exports.resume(); this._inst.exports.resume();
} }
_makeFuncWrapper(id) {
const go = this;
return function () {
const event = { id: id, this: this, args: arguments };
go._pendingEvent = event;
go._resume();
// @ts-ignore
return event.result;
};
}
} }
if ( if (

View File

@ -89,7 +89,7 @@ func start() int {
return callbackId return callbackId
} }
// exit write //export exit
func exit() { func exit() {
exitChan <- true exitChan <- true
} }

View File

@ -12,6 +12,13 @@ export async function getVerifiableStream(
const reader = new VariableChunkStream(data); const reader = new VariableChunkStream(data);
let bytesToRead; let bytesToRead;
if (root instanceof ArrayBuffer) {
root = new Uint8Array(root);
}
if (proof instanceof ArrayBuffer) {
proof = new Uint8Array(proof);
}
const getNextBytes = async () => { const getNextBytes = async () => {
bytesToRead = getWasmProperty(wasmId, "write_promise"); bytesToRead = getWasmProperty(wasmId, "write_promise");
bytesToRead = await bytesToRead; bytesToRead = await bytesToRead;
@ -67,9 +74,9 @@ export async function getVerifiableStream(
const result = getWasmProperty(wasmId, "result"); const result = getWasmProperty(wasmId, "result");
const wasmDone = result === undefined; const wasmDone = result !== undefined;
if (result === undefined) { if (!wasmDone) {
await getNextBytes(); await getNextBytes();
} }
@ -84,6 +91,8 @@ export async function getVerifiableStream(
done(controller); done(controller);
} }
} }
controller.enqueue(chunk.value);
}, },
async cancel(reason: any) { async cancel(reason: any) {
await reader.cancel(reason); await reader.cancel(reason);