C

LayoutExecutorAsyncWorker

Executes an algorithm or ILayoutAlgorithm on a graph in a separate execution context.
Inheritance Hierarchy

Remarks

This class implements the "worker" part for the LayoutExecutorAsync. It will serve requests started by the layout executor in the main thread, perform the actual calculations and send back the results. This allows the main thread to continue and the UI to stay responsive when longer layout calculations need to be performed, or multiple layout calculations should be carried out in parallel.

Instances of this class will deserialize all the information received from the LayoutExecutorAsync, let the callback passed to the constructor perform the actual calculations, and send back the results. Instances of this class often execute in a Web Worker, but it could also be running on a different machine or a server, separate from the browser.

The actual transmission of the serialized data from and to the other context is not part of this implementation. Rather the reception of the data needs to be implemented by users of this class. The data will then be passed to the process method, for deserialization.

See Also

The ability to execute layouts asynchronously via web workers is presented in detail in the section Asynchronous Layout Calculation.

Developer's Guide

API

LayoutExecutorAsync, LayoutExecutor

Members

Show:

Constructors

Creates a new instance of a layout service worker.

The actual work will be performed by the handler function. Upon each call to process, this instance will deserialize the data, construct the graph, attach the data to the graph elements and pass the graph and LayoutDescriptor to the callback function. The function will perform the work on the graph and may optionally use the descriptor to create and configure the corresponding algorithms. Once the function returns or resolves the Promise in case of asynchronous execution, the data will again be serialized and returned to the caller of process, who is responsible for sending back the opaque serialized blob back to the main context. The contents of the data blob are considered an implementation detail and may change at any time between releases.

When no additional data has to be passed between the threads, the convenience method initializeWebWorker can be used instead of creating a new instance of this class manually.

Parameters

handler: function(LayoutGraph, object): Promise<object>
The handler that will perform the actual calculations

Methods

Factory method that creates the graph that will be passed to the worker handler
The default implementation simply returns a new LayoutGraph
protected

Return Value

LayoutGraph
The layout graph to use for the ongoing service request
Called by client code for each data blob received from the main thread's layout request.
Since this class does not know how to receive the data from the main thread, your code will need to call this method for every request it receives in the worker thread. Once the returned Promise resolves, the value needs to be send back to the calling thread for further processing by the worker message handler that sent the request.
final

Parameters

data: object
The data that was given to the worker message handler. The contents of the data are considered an implementation detail and may change at any time between releases.

Return Value

Promise<object>
The Promise that will resolve to the data that needs to be sent back to the calling worker message handler.

See Also

API
initializeWebWorker

Constants

A data provider key that can be used to retrieve information about unconnectedports of the original LayoutEdge.
You can use this data provider to look up additional location information about these ports, e.g. to create additional LayoutPortCandidates or just reserve space for them. The absolute location is provided.
static
A data provider key that can be used to retrieve information about unconnectedports of the original LayoutNode.
You can access information about connected ports through the sourcePortLocation and targetPortLocation properties of the LayoutGraph edge elements. However, the LayoutGraph does not provide information about unconnected ports in the original graph. You can use this data provider to look up additional location information about these ports, e.g. to create additional LayoutPortCandidates or just reserve space for them. The location is relative to the center of that node to match the values provided by the port information in the LayoutEdge.
static

Static Methods

Initializes a web worker to handle layout requests sent by a LayoutExecutorAsync.
This function registers a message event listener that handles requests sent by a LayoutExecutorAsync, processes them using a LayoutExecutorAsyncWorker, and sends back the results. Messages that are not sent by a LayoutExecutorAsync are ignored.
static

Parameters

handler: function(LayoutGraph, object): Promise<object>
The handler that will perform the actual calculations

Throws

Exception ({ name: 'Error' })
Throws if called outside a web worker context.

See Also

Developer's Guide
API
createWebWorkerMessageHandler