Skip to content

bidirectional invocation support #848

@tarasglek

Description

@tarasglek

Hi,
it's currently really hard to do async callbacks in wasm. I think wrpc is an almost perfect alternative. However it does not seem like wit can provide "server" functionality from client.

Suppose we would like to implement hello() in wasi using go and we need to fetch some data for internet. For this we could use the following interface

package wrpc-examples:hello;

interface callback {
    use wrpc:rpc/error@0.1.0.{error};
    fetch: func(url: string) -> result<list<u8>, error>;
}

interface handler {
    hello: func() -> string;
}

world client {
    import handler;
    export callback;
}

world server {
    export handler;
    import  callback;
}

So now node.js can export fetch(), call wasi "business logic that needs to fetch data from net" giving it a way to get to net. This could also be used to expose databases, etc.

sequenceDiagram
    participant Client as Client (Node.js)
    participant Server as Server (WASI)

    Client->>Server: hello()
    activate Server
    Server->>Client: fetch(url)
    activate Client
    Client-->>Server: result<list<u8>, error>
    deactivate Client
    Server-->>Client: Processed result (string)
    deactivate Server
Loading

Is this something that wrpc would support? It looks like currently code doesn't preclude such things.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions