Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including tgrid with all npm packages installed. Try it out:

var tgrid = require("tgrid")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

tgrid v0.3.0

Grid Computing Framework for TypeScript

TGrid

Introduction

Flag

GitHub license npm version Downloads Build Status FOSSA Status Chat on Gitter

Full name of TGrid is TypeScript Grid Computing Framework.

As its name suggests, TGrid is a useful framework for implementating Grid Computing in the TypeScript. With TGrid and its core concept Remote Funtion Call, you can make many computers to be a virtual computer.

To know more, refer below links. If you are the first comer to the TGrid, I strongly recommend you to read the Guide Documents. In article level, I Basic Concepts and Learn from Examples sections would be good choices.

1.2. Grid Computing

Grid Computing

Computers be a (virtual) computer

As its name suggests, TGrid is a useful framework for Grid Computing. However, perpective of Grid Computing in TGrid is something different. It doesn't mean just combining multiple computers uinsg network communication. TGrid insists the real Grid Computing must be possible to turning multiple computers into a virtual computer.

Therefore, within framework of the TGrid, it must be possible to develop Grid Computing System as if there has been only a computer from the beginning. A program running on a computer and a Distributed Processing System with millions, both of them must have similar program code. It's the real Grid Computing.

Do you agree with me?

1.3. Remote Function Call

TGrid realizes the Grid Computing through Remote Function Call. It literally calling remote system's functions are possible. With the Remote Function Call, you can access to objects of remote system as if they have been in my memory from the beginning.

With TGrid and Remote Function Call, it's possible to handle remote system's objects and functions as if they're mine from the beginning. Do you think what that sentence means? Right, being able to call objects and functions of the remote system, it means that current and remote system are integrated into a single virtual computer.

However, whatever Grid Computing and Remote Function Call are, you've only heard theoretical stories. Now, it's time to see the real program code. Let's see the demonstration code and feel the Remote Function Call. If you want to know more about the below demonstration code, read a section Learn from Examples wrote into the Guide Documents.

composite-calculator/server.ts

import { WebServer, WebAcceptor } from "tgrid/protocols/web";
import { CompositeCalculator } from "../../providers/Calculator";

async function main(): Promise<void>
{
    let server: WebServer = new WebServer();
    await server.open(10102, async (acceptor: WebAcceptor) =>
    {
        await acceptor.accept(new CompositeCalculator());
    });
}
main();

composite-calculator/client.ts

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

import { ICalculator } from "../../controllers/ICalculator";

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

    //----
    // CALL REMOTE FUNCTIONS
    //----
    // GET DRIVER
    let calc: Driver<ICalculator> = connector.getDriver<ICalculator>();

    // FUNCTIONS IN THE ROOT SCOPE
    console.log("1 + 6 =", await calc.plus(1, 6));
    console.log("7 * 2 =", await calc.multiplies(7, 2));

    // FUNCTIONS IN AN OBJECT (SCIENTIFIC)
    console.log("3 ^ 4 =", await calc.scientific.pow(3, 4));
    console.log("log (2, 32) =", await calc.scientific.log(2, 32));

    try
    {
        // TO CATCH EXCEPTION IS STILL POSSIBLE
        await calc.scientific.sqrt(-4);
    }
    catch (err)
    {
        console.log("SQRT (-4) -> Error:", err.message);
    }

    // FUNCTIONS IN AN OBJECT (STATISTICS)
    console.log("Mean (1, 2, 3, 4) =", await calc.statistics.mean(1, 2, 3, 4));
    console.log("Stdev. (1, 2, 3, 4) =", await calc.statistics.stdev(1, 2, 3, 4));

    //----
    // TERMINATE
    //----
    await connector.close();
}
main();
1 + 6 = 7
7 * 2 = 14
3 ^ 4 = 81
log (2, 32) = 5
SQRT (-4) -> Error: Negative value on sqaure.
Mean (1, 2, 3, 4) = 2.5
Stdev. (1, 2, 3, 4) = 1.118033988749895
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free