Skip to content
Jeongho Nam edited this page Jan 16, 2019 · 11 revisions

TypeScript Grid Computing Framework

Build Status npm version Downloads DeepScan grade Chat on Gitter

TGrid is a tiny framework for Grid Computing in TypeScript, using such concepts.

  • RFC: Remote Function Call
  • ROC: Remote Object Call
  • OON: Object Oriented Network
    • Promise Pattern (async & await)

Following paradigm of the TGrid, you can compose real-time network communication systems very easily. Consider that system nodes are correspondent with objects. All you have to do is just calling functions in those objects with a special symbol await.

I repeat, whether how network systems are enormous and feature are complicated, they're just objects. Just call functions, with the keyword await. It sound difficult, then look at the below Usage - Example Code, then you may understand. If you want to know more, Guide Documents are prepared for you.

Installation

NPM Module

Installing TGrid in NodeJS is very easy. Just install with the npm command.

# Install TGrid from the NPM module.
npm install --save tgrid

Usage - Example Code

vector/server.ts

import { WebServer } from "tgrid/protocols/web";
import { Vector } from "tstl/container";

async function main(): Promise<void>
{
    let server = new WebServer();
    await server.open(10101, async acceptor =>
    {
        // accept connection & provide Vector
        await acceptor.accept(new Vector<number>());
    });
}
main();

vector/client.ts

import { WebConnector } from "tgrid/protocols/web";

interface IVector<T>
{
    size(): number;
    at(index: number): T;
    push_back(val: T): void;
}

async function main(): Promise<void>
{
    // do connect
    let connector = new WebConnector();
    await connector.connect("ws://127.0.0.1:10101");

    //----
    // CALL FUNCTIONS IN THE REMOTE SYSTEM
    //----
    // get Driver<Controller>
    let v = connector.getDriver<IVector<number>>();

    // insert elements
    for (let i: number = 0; i < 5; ++i)
        await v.push_back(i);

    // access elements
    console.log("size:", await v.size());
    for (let i: number = 0; i < await v.size(); ++i)
        console.log("  element:", await v.at(i));

    // catching exception is also possible
    try 
    {
        await v.at(9999);
    } 
    catch (exp) 
    {
        console.log(`${exp.name}: "${exp.message}"`);
    }

    // close the connection
    await connector.close();
}
main();
size: 5
  element: 0
  element: 1
  element: 2
  element: 3
  element: 4
out_of_range: "Target index is greater than Vector's size."

References

Clone this wiki locally