Stream: wasmtime

Topic: Callback Examples?


view this post on Zulip Nathan Bedell (Aug 09 2025 at 17:29):

Hey all, I'm trying to mess around with hacking together some WIT interfaces / worlds for reactive user interfaces. Since async / streams are not currently stable (and I'm also not sure whether or not they are the most appropriate API for my use case anyway), I'm trying to hack something together using callbacks for right now.

I've gotten pretty far, but I'm running into a wasm trap: cannot enter component instance and I'm unsure how to proceed. So I was wondering if there were any examples already out there of what I'm trying to do.

Basically to hack callbacks in the current component model, I'm importing a register callback function (add-on-update-handler: func(callback-id: callback-id);), and exporting a function to actually call the callback in the guest (call-callback: func(callback-id: callback-id, arg: any);).

view this post on Zulip Ramon Klass (Aug 09 2025 at 21:10):

it sounds like you're just running into the reentrancy problem. You are probably calling a guest function which in turn asks a host function for an asynchronous response, but your host function tries to respond immediately. In js I do setImmediate(() => { respond(id, data) }) so that the respond guest function is called the next frame instead of directly reentering

view this post on Zulip Ramon Klass (Aug 09 2025 at 21:13):

wasm only has one stack. The guest has called your host function and the stack is alive at least until your host function returns. If your host function now wouold call another wasm function, then wasm would have to create a second stack that is independent from the first stack and that is not allowed

view this post on Zulip Nathan Bedell (Aug 09 2025 at 21:22):

Hmm... Ok, I guess I'll play around with when the callbacks are invoked to see if I can get around that.


Last updated: Dec 06 2025 at 06:05 UTC