math.mojom
is the definition of the servicemath.ts
is auto-generated code based on Mojo definition: it gives a stub and a type definition of an implementationmathImpl.ts
is an actual implementation of Math service.mathRPC.ts
is the necessary code to call a remote implementation of Math service via JSON-RPC (using a RPCPeer). It can be auto-generated as well.
In the best world, dev just have to define math.mojom
and implement mathImpl.ts
, the logic of the service. The rest is code-generated.
import { Math } from './math.ts'
import { MathImpl } from './MathImpl'
const math = new Math(new MathImpl());
const { sum } = await math.add({a: 1, b: 2});
// sum is 3
In process A (server):
import { Math } from './math.ts'
import { MathImpl } from './mathRPC.ts'
const rpcPeer = getRPCPeer();
const math = new Math(new MathImpl(rpcPeer));
const { sum } = await math.add({a: 1, b: 2});
// sum is 3
In process B (usage):
import { MathImpl } from './MathImpl'
import { bindImpl } from './mathRPC.ts'
const rpcPeer = getRPCPeer();
bindImpl(rpcPeer, new MathImpl());