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
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
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.
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.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
Constants
A data provider key that can be used to retrieve information about unconnectedports of the original LayoutEdge.
A data provider key that can be used to retrieve information about unconnectedports of the original LayoutNode.
Static Methods
Initializes a web worker to handle layout requests sent by a LayoutExecutorAsync.
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