Class: TransWorker

TransWorker()

new TransWorker()

TransWorker - Inter thread method invocation helper class for the WebWorker.

This class offers different implementations for its role on the context.

In the main thread, It creates WebWorker instance and creates wrapper functions for all the methods declared in the prototypes of the class given in the parameters.

The wrapper method sends a message to the worker with the method name and all the parameter.

When the worker side instance received the message, it invokes the method specified by the name in the message with the parameters. The return value will be notified by the message to the main thread instance from the worker.

The main thread instance that received the notification notifies the value to the callback function given at first invocation.

LICENSE

Released under the MIT license http://opensource.org/licenses/mit-license.php

Copyright (c) 2017 Koji Takami(vzg03566@gmail.com)

Source:

Classes

Options

Members

(static) SyncTypeCallback :function

A literal for the interface methods to synchronize with a callback.

Type:
  • function
Source:

(static) SyncTypePromise :function

A literal for the interface methods to synchronize with a Promise.

Type:
  • function
Source:

Methods

(static) createInterface(workerUrl, clientCtor, options) → {Transworker}

Create a worker and an interface instance for the thread.

Parameters:
Name Type Description
workerUrl string

A worker url. It must use TransWorker.

clientCtor function

client-class constructor.

options TransWorker.Options

Options to create a wrapper object for the main thread.

Source:
Returns:

The created TransWorker instance.

Type
Transworker

(static) createInvoker(workerUrl, clientCtor, thisObject, notifyHandlers) → {Transworker}

Create instance for main thread.

Parameters:
Name Type Description
workerUrl string

A worker url. It must use TransWorker.

clientCtor function

client-class constructor.

thisObject object

(Optional) A caller of callback and notification.

notifyHandlers object

A map a notification name to the handler.

Source:
Returns:

The created Transworker instance.

Type
Transworker

(static) createSharedInvoker(workerUrl, clientCtor, thisObject, notifyHandlers) → {Transworker}

Create instance for main thread.

Parameters:
Name Type Description
workerUrl string

A worker url. It must use TransWorker.

clientCtor function

client-class constructor.

thisObject object

(Optional) A caller of callback and notification.

notifyHandlers object

A map a notification name to the handler.

Source:
Returns:

The created Transworker instance.

Type
Transworker

(static) createSharedWorker(client) → {TransWorker}

Create a TransWorker having SharedWorker on the worker side.

Parameters:
Name Type Description
client object

An instance of the client class.

Source:
Returns:

an instance of TransWorker.

Type
TransWorker

(static) createWorker(client) → {TransWorker}

Create a Worker side TransWorker instance.

Parameters:
Name Type Description
client object

An instance of the client class.

Source:
Returns:

an instance of TransWorker.

Type
TransWorker

createCallbackWrapper(methodName) → {function}

Create client method wrapper

Parameters:
Name Type Description
methodName string

A method name to override.

Source:
Returns:

A wrapper function.

Type
function

createInvoker(workerUrl, clientCtor, thisObject, notifyHandlers) → {undefined}

Create instance for main thread.

Parameters:
Name Type Description
workerUrl string

A worker url. It must use TransWorker.

clientCtor function

client-class constructor.

thisObject object

(Optional) A caller of callback and notification.

notifyHandlers object

A map a notification name to the handler.

Source:
Returns:
Type
undefined

createPromiseWrapper(methodName) → {function}

Create client method wrapper that returns a promise that will be resolved by a value that remote method returns.

Parameters:
Name Type Description
methodName string

A method name to override.

Source:
Returns:

A wrapper function.

Type
function

createWorker(client) → {undefined}

Create Worker side TransWorker instance.

Parameters:
Name Type Description
client object

A instance of the client class.

Source:
Returns:
Type
undefined

postNotify(name, param) → {undefined}

Post a notify to the UI-thread TransWorker instance

Parameters:
Name Type Description
name string

A message name.

param any

A message parameters.

Source:
Returns:
Type
undefined

subscribe(name, handler) → {undefined}

Register a notification to receive a message from the worker thread.

Parameters:
Name Type Description
name string

A notification name.

handler function

A notification handler.

Source:
Returns:
Type
undefined