36 lines
866 B
TypeScript
36 lines
866 B
TypeScript
import { CallDispatcher } from "../lib/callDispatcher";
|
|
import { EventLayer } from "../lib/communication/eventLayer";
|
|
|
|
const communicationLayer = new EventLayer();
|
|
const local = new CallDispatcher(communicationLayer);
|
|
const remote = new CallDispatcher(communicationLayer);
|
|
|
|
const _functionRemote = async (a: number, b: number, operation: (a: number, b: number) => number) => {
|
|
|
|
return await operation(a, b);
|
|
}
|
|
|
|
remote.registerFunction(_functionRemote, {
|
|
id: '_functionRemote'
|
|
});
|
|
|
|
const main = async () => {
|
|
let res = await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
|
|
console.log('local callback')
|
|
return a + b;
|
|
}]);
|
|
|
|
console.log('1', res)
|
|
|
|
res = await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
|
|
console.log('local callback')
|
|
return a * b;
|
|
}]);
|
|
|
|
console.log('2', res)
|
|
|
|
}
|
|
|
|
main();
|
|
|