Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WorkerConnector<Provider>

Worker Connector.

The WorkerConnector is a communicator class, who can create an Worker instance and communicate with it using RFC (Remote Function Call), considering the Worker as a remote system (WorkerServer).

You can create an Worker instance with compile() or connect() method. Anyway, after creation of the Worker instance, the Worker program must open a server using the WorkerServer.open() method.

Note that, after your business, don't forget terminating the worker using close() or WorkerServer.close(). If you don't terminate it, then vulnerable memory and communication channel would not be destroyed and it may cause the memory leak.

author

Jeongho Nam http://samchon.org

Type parameters

  • Provider: object

    Type of features provided for remote system.

Hierarchy

Implements

Index

Constructors

constructor

Accessors

state

  • get state(): WorkerConnector.State

Methods

close

  • close(): Promise<void>
  • Close connection.

    Close connection between the remote worker system.

    It destroies all RFCs (remote function calls) between this and the remote system (through Driver<Controller>) that are not returned (completed) yet. The destruction causes all incompleted RFCs to throw exceptions.

    Returns Promise<void>

compile

  • compile(content: string, ...args: string[]): Promise<void>
  • Compile server and connect to there.

    The compile method tries compile JS source code, creates Worker instance with that code connects to the Worker. To complete the compilation and connection, the Worker program must open that server using the WorkerServer.open() method.

    Note that, after your business has been completed, you've to close the Worker using close() or WorkerServer.close(). If you don't close that, vulnerable memory usage and communication channel would not be destroyed and it may cause the memory leak.

    Parameters

    • content: string

      JS Source code to compile.

    • Rest ...args: string[]

      Arguments to deliver.

    Returns Promise<void>

connect

  • connect(jsFile: string, ...args: string[]): Promise<void>
  • Connect to server.

    The connect() method tries to create an Worker instance and connect to the Worker. To complete the connection, the Worker program must open that server using the WorkerServer.open() method.

    Note that, after your business has been completed, you've to close the Worker using close() or WorkerServer.close(). If you don't close that, vulnerable memory usage and communication channel would not be destroyed and it may cause the memory leak.

    Parameters

    • jsFile: string

      JS File to be WorkerServer.

    • Rest ...args: string[]

      Arguments to deliver.

    Returns Promise<void>

Protected destructor

  • destructor(error?: Error): Promise<void>
  • Destory the communicator.

    A destory function must be called when the network communication has been closed. It would destroy all function calls in the remote system (by Driver<Controller>), which are not returned yet.

    The error instance would be thrown to those function calls. If the disconnection is abnormal, then write the detailed reason why into the error instance.

    Parameters

    • Optional error: Error

      An error instance to be thrown to the unreturned functions.

    Returns Promise<void>

getDriver

  • getDriver<Controller, UseParametric>(): Driver<Controller, UseParametric>
  • Get Driver for RFC (Remote Function Call).

    The Controller is an interface who defines provided functions from the remote system. The Driver is an object who makes to call remote functions, defined in the Controller and provided by Provider in the remote system, possible.

    In other words, calling a functions in the Driver<Controller>, it means to call a matched function in the remote system's Provider object.

    • Controller: Definition only
    • Driver: Remote Function Call

    Type parameters

    • Controller: object

      An interface for provided features (functions & objects) from the remote system (Provider).

    • UseParametric: boolean

      Whether to convert type of function parameters to be compatible with their pritimive.

    Returns Driver<Controller, UseParametric>

    A Driver for the RFC.

getProvider

  • getProvider(): Provider | null
  • Get current Provider.

    Get an object providing features (functions & objects) for remote system. The remote system would call the features (Provider) by using its Driver<Controller>.

    Returns Provider | null

    Current Provider object

join

  • join(): Promise<void>
  • join(ms: number): Promise<boolean>
  • join(at: Date): Promise<boolean>

Protected replyData

  • replyData(invoke: Invoke): void
  • Data Reply Function.

    A function should be called when data has come from the remote system.

    When you receive a message from the remote system, then parse the message with your special protocol and covert it to be an Invoke object. After the conversion, call this method.

    Parameters

    • invoke: Invoke

      Structured data converted by your special protocol.

    Returns void

setProvider

  • setProvider(obj: Provider | null): void

Generated using TypeDoc