Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

How to identify resources? #5

@vwkd

Description

@vwkd

Currently we identify resources using an ID which we pass across components and the API boundary. Is there a better way?

Having to maintain an ID is painful. We need to resolve the ID to the resource each time we cross a boundary.

Should we instead pass a resource handle? Currently this seems to be a Rust reference &. Does this introduce lifetime issues? Also, what if a smart pointers like Arc would be better suited than a reference? For example, a state component could export a delete function to delete an item which drops the Arc, but any dependency components can still use as long as needed.

But we'll ultimately need some sort of ID when leaving the component cloud and pass the API boundary to the frontend.

Currently we use a increasing u64 and use it as index into a Vec. The advantage over a string is to have a natural order, not worry about generating a unique one without conflicts, and to not need to allocate every time we cross a boundary. The disadvantage is that Vec wants a platform-dependent usize which Wasm doesn't support, so using a u64 limits us to 64-bit and we panic if we run anywhere else. Also, we need to worry about never remove an item from the Vec or otherwise mutate the sequence which would change the IDs. Since we can't really delete, we can at most store an Option and replace the value with None, at the cost of complicating error handling.

Maybe some sort of hybrid between the two? Resource handles for internal cross-component boundaries, IDs for the API boundary?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions