Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add invokeSync method #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

nikpivkin
Copy link

This PR adds an invokeSync method that is similar to invoke, only executed synchronously.

The need for a synchronous method appeared for calling a WASM function from another WASM module. A small example:

async function main() {
    buffer = await fs.readFile(path.join(__dirname, 'wasm', 'main.wasm'));
    const host = await instantiate(buffer);

    const policyWasm = await fs.readFile("policy.wasm");
    const policy = await loadPolicy(policyWasm, {}, {
        "greet": () => (msg) => {
            console.log("Message: ", msg);
            const payload = encode(msg);
            console.log("Payload: ", payload);
    
            res = host.invokeSync('greet', payload)
            return result = decode(res);
        }
    })

    const result = policy.evaluate({});
    console.log(JSON.stringify(result, null, 2));
}

Signed-off-by: Nikita Pivkin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant