Stream: wasmtime

Topic: Programmatically Create Resource


view this post on Zulip Ashanti Mutinta (Mar 21 2024 at 11:20):

Is there anyway to do this? I would like to test out my event loop and have mocked out most of the external things. One part that is catching me is I wouod like to create a programmable resource that is pollable? Is it possible? If not I will just mock that as well

view this post on Zulip Alex Crichton (Mar 21 2024 at 14:48):

This sort of depends to the degree to which you're mocking. Arbitrary host resources can be made at any time with Resource::new_{own,borrow}, all you need is a 32-bit number to put in there. If that number never ends up being used, for example the resource is never passed to wasi:io/poll, then it doesn't matter too much what the number is. If you want to create an arbitrary real pollable resource then you'll need to use the same pollable type as wasmtime-wasi, and the crate isn't 100% built for mocking but it should be possible since I think that one is trait-based.

For guest-defined resources there's no way to mock those out, they have to come from the guest

view this post on Zulip Ashanti Mutinta (Mar 21 2024 at 20:33):

Alex Crichton said:

This sort of depends to the degree to which you're mocking. Arbitrary host resources can be made at any time with Resource::new_{own,borrow}, all you need is a 32-bit number to put in there. If that number never ends up being used, for example the resource is never passed to wasi:io/poll, then it doesn't matter too much what the number is. If you want to create an arbitrary real pollable resource then you'll need to use the same pollable type as wasmtime-wasi, and the crate isn't 100% built for mocking but it should be possible since I think that one is trait-based.

For guest-defined resources there's no way to mock those out, they have to come from the guest

Awesome this worked out well for me thank you!


Last updated: Dec 23 2024 at 13:07 UTC