Skip to content

Commit

Permalink
Add .gitattributes
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed May 17, 2024
1 parent edfef0f commit 8062019
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mdx linguist-detectable=false
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [samchon]
54 changes: 21 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<null, null, ICalculator> =
new WebSocketConnector(
null, // header
null, // provider for remote server
);
await connector.connect("ws://127.0.0.1:37000/composite");

const remote: Driver<ICompositeCalculator> = connector.getDriver();
// CALL REMOTE FUNCTIONS
const remote: Driver<ICalculator> = 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 }
> ]
> ```
Expand Down
53 changes: 21 additions & 32 deletions website/pages/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<null, null, ICalculator> =
new WebSocketConnector(
null, // header
null, // provider for remote server
);
await connector.connect("ws://127.0.0.1:37000/composite");

const remote: Driver<ICompositeCalculator> = connector.getDriver();
// CALL REMOTE FUNCTIONS
const remote: Driver<ICalculator> = 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 }
> ]
> ```

0 comments on commit 8062019

Please sign in to comment.