-
-
Notifications
You must be signed in to change notification settings - Fork 20
Home
Jeongho Nam edited this page Jan 5, 2019
·
11 revisions
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
)
- Promise Pattern (
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.
Installing TGrid in NodeJS is very easy. Just install with the npm
command.
# Install TGrid from the NPM module.
npm install --save tgrid
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();
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."
- Repositories
- Documents
- Related Projects