Skip to content

Commit

Permalink
Writing #69: features of worker protocols.
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed May 14, 2024
1 parent 71c8f37 commit eba1297
Show file tree
Hide file tree
Showing 67 changed files with 3,071 additions and 460 deletions.
56 changes: 37 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,48 @@ Also, extremely easy even when composing complicated network system like grid co
```typescript
import { Driver, WebSocketConnector } from "tgrid";

import { ICalculator } from "./interfaces/ICalculator";
import { CalcEventListener } from "./providers/CalcEventListener";

export const main = async (): Promise<void> => {
// CONNECT TO WEBSOCKET SERVER
import { ICalcConfig } from "../interfaces/ICalcConfig";
import { ICalcEvent } from "../interfaces/ICalcEvent";
import { ICalcEventListener } from "../interfaces/ICalcEventListener";
import { ICompositeCalculator } from "../interfaces/ICompositeCalculator";

export const webSocketClientMain = async () => {
const stack: ICalcEvent[] = [];
const listener: ICalcEventListener = {
on: (evt: ICalcEvent) => stack.push(evt),
};
const connector: WebSocketConnector<
null, // header
CalcEventListener, // provider for remote server
ICalculator, // provider from remote server
> = new WebSocketConnector(null, new CalcEventListener());
await connector.connect("ws://127.0.0.1:443/calculator");

// RPC (YOU CAN CALL REMOTE PROCEDURES)
const calc: Driver<ICalculator> = connector.getDriver();
console.log(
await calc.plus(2, 3),
await calc.minus(7, 1),
await calc.multiplies(3, 4),
await calc.divides(9, 3),
ICalcConfig,
ICalcEventListener,
ICompositeCalculator
> = new WebSocketConnector(
{ precision: 2 }, // header
listener, // provider for remote server
);
await connector.connect("ws://127.0.0.1:37000/composite");

const remote: Driver<ICompositeCalculator> = connector.getDriver();
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 connector.close();
console.log(...stack);
};
```

> Execution result:
>
> ```bash
> { 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 All @@ -50,7 +68,7 @@ npm install tgrid
Just install with `npm` command. That's all.
If you wanna `tgrid` in `NestJS`, read `nestia` guide documents.
If you wanna use `tgrid` in `NestJS`, read `nestia` guide documents.
- [Nestia > Guide Documents > Setup](https://nestia.io/docs/setup/)
- [Nestia > Guide Documents > WebSocketRoute](https://nestia.io/docs/core/WebSocketRoute/)
Expand Down
1 change: 1 addition & 0 deletions examples/docs/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
92 changes: 92 additions & 0 deletions examples/docs/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
:root {
--light-hl-0: #AF00DB;
--dark-hl-0: #C586C0;
--light-hl-1: #000000;
--dark-hl-1: #D4D4D4;
--light-hl-2: #001080;
--dark-hl-2: #9CDCFE;
--light-hl-3: #A31515;
--dark-hl-3: #CE9178;
--light-hl-4: #0000FF;
--dark-hl-4: #569CD6;
--light-hl-5: #795E26;
--dark-hl-5: #DCDCAA;
--light-hl-6: #0070C1;
--dark-hl-6: #4FC1FF;
--light-hl-7: #267F99;
--dark-hl-7: #4EC9B0;
--light-hl-8: #098658;
--dark-hl-8: #B5CEA8;
--light-hl-9: #008000;
--dark-hl-9: #6A9955;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}

@media (prefers-color-scheme: light) { :root {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--code-background: var(--light-code-background);
} }

@media (prefers-color-scheme: dark) { :root {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--code-background: var(--dark-code-background);
} }

:root[data-theme='light'] {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--code-background: var(--light-code-background);
}

:root[data-theme='dark'] {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--code-background: var(--dark-code-background);
}

.hl-0 { color: var(--hl-0); }
.hl-1 { color: var(--hl-1); }
.hl-2 { color: var(--hl-2); }
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
.hl-7 { color: var(--hl-7); }
.hl-8 { color: var(--hl-8); }
.hl-9 { color: var(--hl-9); }
pre, code { background: var(--code-background); }
Loading

0 comments on commit eba1297

Please sign in to comment.