tgrid
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

TGrid

TGrid logo

GitHub license npm version Downloads Build Status Guide Documents

TypeScript Grid Computing Framework.

TypeScript RPC (Remote Procedure Call) framework for WebSocket and Worker protocols.

  • WebSocket
  • Worker
  • SharedWorker
  • NestJS

Also, extremely easy even when composing complicated network system like grid computing.

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";

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
  );
  await connector.connect("ws://127.0.0.1:37000/composite");

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

[!TIP]

$ npx ts-node examples/src/websocket
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 }
]

Setup

npm install tgrid

Just install with npm command. That's all.

If you wanna use TGrid in NestJS, read Nestia guide documents, too.

Guide Documents

Check out the document in the website:

🏠 Home

📖 Tutorial

🔗 Appendix

Package Sidebar

Install

npm i tgrid

Homepage

tgrid.com

Weekly Downloads

1,020

Version

1.0.0

License

MIT

Unpacked Size

509 kB

Total Files

193

Last publish

Collaborators

  • samchon