imaginary example
This commit is contained in:
parent
df18b029f7
commit
332a9e5eab
@ -1,15 +1,36 @@
|
|||||||
|
import {KittenIPC} from '../../lib/ts/lib.js';
|
||||||
|
import GoIpcApi from './goapi.gen.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @kittenipc api
|
* @kittenipc api
|
||||||
*/
|
*/
|
||||||
class TsIpcApi {
|
class TsIpcApi {
|
||||||
Div(a: number, b: number): number {
|
Div(a: number, b: number): number {
|
||||||
|
if (b === 0) {
|
||||||
|
throw new Error('division by zero');
|
||||||
|
}
|
||||||
return a / b;
|
return a / b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const localApi = new TsIpcApi();
|
||||||
|
const ipc = new KittenIPC(localApi);
|
||||||
|
const goApi = new GoIpcApi(ipc);
|
||||||
|
|
||||||
function main() {
|
await ipc.start();
|
||||||
|
|
||||||
|
console.log(`12/3=${await goApi.Div(12, 3)}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await goApi.Div(10, 0);
|
||||||
|
} catch (e) {
|
||||||
|
console.trace(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
await ipc.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main().catch(e => {
|
||||||
|
console.trace(e);
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user