UNPKG

tgrid

Version:

Grid Computing Framework for TypeScript

108 lines (107 loc) 3.63 kB
import { Communicator } from "../../components/Communicator"; import { Invoke } from "../../components/Invoke"; import { IServer } from "../internal/IServer"; import { IWorkerSystem } from "./internal/IWorkerSystem"; /** * Worker Server. * * The `WorkerServer` is a class representing a `Worker` server which communicate * with client ({@link WorkerConnector}), through the RPC (Remote Procedure Call). * * Unlike other servers, `WorkerServer` can accept only one client * ({@link WorkerConnector}), because the `Worker` is dependent on its parent instance * (web page, node or parent worker). Thus, `WorkerServer` does not have any acceptor * and communicates with client (its parent) directly. * * To start communication with the client, call the {@link open} method * with `Provider` instance. After your business, don't forget {@link close closing} * this `Worker` instance. If the termination is performed by the * {@link WorkerConnector}, you can wait the closing signal through the * {@link join} method. * * Also, when declaring this `WorkerServer` type, you've to define three * generic arguments; `Header`, `Provider` and `Remote`. Those generic arguments must * be same with the ones defined in the target {@link WorkerConnector} class * (`Provider` and `Remote` must be reversed). * * For reference, the first `Header` type represents an initial data from the * client after the connection. I recommend utilize it as an activation tool * for security enhancement. The second generic argument `Provider` represents a * provider from server to client, and the other `Remote` means a provider from the * client to server. * * @template Header Type of the header containing initial data. * @template Provider Type of features provided for the client. * @template Remote Type of features supported by client. * @author Jeongho Nam - https://github.com/samchon */ export declare class WorkerServer<Header, Provider extends object | null, Remote extends object | null> extends Communicator<Provider | undefined, Remote> implements IWorkerSystem, IServer<WorkerServer.State> { /** * @hidden */ private channel_; /** * @hidden */ private state_; /** * @hidden */ private header_; /** * Default Constructor. * * @param type You can specify the worker mode when NodeJS. Default is "thread". */ constructor(); /** * Open server with `Provider`. * * Open worker server and start communication with the client * ({@link WorkerConnector}). * * Note that, after your business, you should terminate this worker to prevent * waste of memory leak. Close this worker by yourself ({@link close}) or let * client to close this worker ({@link WorkerConnector.close}). * * @param provider An object providing features for the client. */ open(provider: Provider): Promise<void>; /** * @inheritDoc */ close(): Promise<void>; /** * @inheritDoc */ get state(): WorkerServer.State; /** * Get header containing initialization data like activation. */ getHeader(): Promise<Header>; /** * @hidden */ private _Handshake; /** * @hidden */ protected sendData(invoke: Invoke): Promise<void>; /** * @hidden */ protected inspectReady(): Error | null; /** * @hidden */ private _Handle_message; } /** * */ export declare namespace WorkerServer { /** * Current state of the {@link WorkerServer}. */ export import State = IServer.State; }