From 806201951dccb27b9d44f3f7d8aa5ea3b61f8aae Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 17 May 2024 11:41:54 +0900 Subject: [PATCH] Add `.gitattributes` --- .gitattributes | 1 + .github/FUNDING.yml | 1 + README.md | 54 ++++++++++++++---------------------- website/pages/docs/index.mdx | 53 ++++++++++++++--------------------- 4 files changed, 44 insertions(+), 65 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/FUNDING.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b3d788c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.mdx linguist-detectable=false \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..9b7af34 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [samchon] \ No newline at end of file diff --git a/README.md b/README.md index 08aa4e1..3390296 100644 --- a/README.md +++ b/README.md @@ -16,56 +16,44 @@ TypeScript RPC (Remote Procedure Call) framework for `WebSocket` and `Worker` pr - `SharedWorker` - `NestJS` -Also, extremely easy even when composing complicated network system like grid computing. +Also, easy to develop complicated network system like grid computing. ```typescript import { Driver, WebSocketConnector } from "tgrid"; -import { ICalcConfig } from "../interfaces/ICalcConfig"; -import { ICalcEvent } from "../interfaces/ICalcEvent"; -import { ICalcEventListener } from "../interfaces/ICalcEventListener"; -import { ICompositeCalculator } from "../interfaces/ICompositeCalculator"; +import { ICalculator } from "./ICalculator"; export const webSocketClientMain = async () => { - const stack: ICalcEvent[] = []; - const listener: ICalcEventListener = { - on: (evt: ICalcEvent) => stack.push(evt), - }; - const connector: WebSocketConnector< - ICalcConfig, - ICalcEventListener, - ICompositeCalculator - > = new WebSocketConnector( - { precision: 2 }, // header - listener, // provider for remote server - ); + // CONNECT TO WEBSOCKET SERVER + const connector: WebSocketConnector = + new WebSocketConnector( + null, // header + null, // provider for remote server + ); await connector.connect("ws://127.0.0.1:37000/composite"); - const remote: Driver = connector.getDriver(); + // CALL REMOTE FUNCTIONS + const remote: Driver = connector.getDriver(); console.log( await remote.plus(10, 20), // returns 30 - await remote.multiplies(3, 4), // returns 12 - await remote.divides(5, 3), // returns 1.67 - await remote.scientific.sqrt(2), // returns 1.41 - await remote.statistics.mean(1, 3, 9), // returns 4.33 + await remote.minus(7, 3), // returns 4 + await remote.multiply(3, 4), // returns 12 + await remote.divide(5, 2), // returns 2.5 ); - await connector.close(); - console.log(stack); }; + +interface ICalculator { + plus(a: number, b: number): number + minus(a: number, b: number): number + multiply(a: number, b: number): number + divide(a: number, b: number): number +} ``` -> [!TIP] > ```bash -> $ npx ts-node examples/src/websocket +> $ npm start > 30 12 1.67 1.41 4.33 -> [ -> { type: 'plus', input: [ 10, 20 ], output: 30 }, -> { type: 'multiplies', input: [ 3, 4 ], output: 12 }, -> { type: 'divides', input: [ 5, 3 ], output: 1.67 }, -> { type: 'sqrt', input: [ 2 ], output: 1.41 }, -> { type: 'mean', input: [ 1, 3, 9 ], output: 4.33 } -> ] > ``` diff --git a/website/pages/docs/index.mdx b/website/pages/docs/index.mdx index 76e289f..bd0b5fc 100644 --- a/website/pages/docs/index.mdx +++ b/website/pages/docs/index.mdx @@ -43,53 +43,42 @@ TypeScript RPC (Remote Procedure Call) framework for `WebSocket` and `Worker` pr - `SharedWorker` - `NestJS` -Also, extremely easy even when composing complicated network system like grid computing. +Also, easy to develop complicated network system like grid computing. -```typescript filename="examples/websocket/src/client.ts" showLineNumbers +```typescript filename="examples/remote-function-call/src/client.ts" showLineNumbers import { Driver, WebSocketConnector } from "tgrid"; -import { ICalcConfig } from "../interfaces/ICalcConfig"; -import { ICalcEvent } from "../interfaces/ICalcEvent"; -import { ICalcEventListener } from "../interfaces/ICalcEventListener"; -import { ICompositeCalculator } from "../interfaces/ICompositeCalculator"; +import { ICalculator } from "./ICalculator"; export const webSocketClientMain = async () => { - const stack: ICalcEvent[] = []; - const listener: ICalcEventListener = { - on: (evt: ICalcEvent) => stack.push(evt), - }; - const connector: WebSocketConnector< - ICalcConfig, - ICalcEventListener, - ICompositeCalculator - > = new WebSocketConnector( - { precision: 2 }, // header - listener, // provider for remote server - ); + // CONNECT TO WEBSOCKET SERVER + const connector: WebSocketConnector = + new WebSocketConnector( + null, // header + null, // provider for remote server + ); await connector.connect("ws://127.0.0.1:37000/composite"); - const remote: Driver = connector.getDriver(); + // CALL REMOTE FUNCTIONS + const remote: Driver = connector.getDriver(); console.log( await remote.plus(10, 20), // returns 30 - await remote.multiplies(3, 4), // returns 12 - await remote.divides(5, 3), // returns 1.67 - await remote.scientific.sqrt(2), // returns 1.41 - await remote.statistics.mean(1, 3, 9), // returns 4.33 + await remote.minus(7, 3), // returns 4 + await remote.multiply(3, 4), // returns 12 + await remote.divide(5, 2), // returns 2.5 ); - await connector.close(); - console.log(stack); }; + +interface ICalculator { + plus(a: number, b: number): number + minus(a: number, b: number): number + multiply(a: number, b: number): number + divide(a: number, b: number): number +} ``` > ```bash filename="Terminal" > $ npm start > 30 12 1.67 1.41 4.33 -> [ -> { type: 'plus', input: [ 10, 20 ], output: 30 }, -> { type: 'multiplies', input: [ 3, 4 ], output: 12 }, -> { type: 'divides', input: [ 5, 3 ], output: 1.67 }, -> { type: 'sqrt', input: [ 2 ], output: 1.41 }, -> { type: 'mean', input: [ 1, 3, 9 ], output: 4.33 } -> ] > ```