import { RpcTarget, RpcStub, newMessagePortRpcSession } from "capnweb";
interface MyApi extends RpcTarget {
myProp: number;
}
class MyApiImpl extends RpcTarget implements MyApi {
myProp: number = 1;
}
const { port1, port2 } = new MessageChannel();
using stub: RpcStub<MyApi> = newMessagePortRpcSession<MyApi>(port1);
using _sessionFrom2To1 = newMessagePortRpcSession(port2, new MyApiImpl());
const myProp: number = await stub.myProp;
console.log(myProp);
// Expect: 1
// Got: undefined
const myPropStr: string = await stub.myProp.toString();
console.log(myPropStr);
// Expect: "1"
// Got: [object Function]
You can test this by running deno test.ts or node test.ts with Node >= 24