Class RinzlerEngine

Welcome to Rinzler's full documentation.

If you're just getting started, check out the Quick Start guide.

This page describes the interface of an instanted RinzlerEngine class, which you can access like so:

import RinzlerEngine from 'rinzler-engine'

const engine = new RinzlerEngine()

Hierarchy

  • RinzlerEngine

Constructors

Methods - Lifecycle

Methods - Optimization

Methods - Other

Methods - ⚠️ Dangerous

Constructors

Lifecycle Methods

  • Start the engine.

    Internally, configures the job processing functions, starts the load balancer and launches a first Web Worker.

    Returns

    A Promise for the current engine instance. Can be used for chaining multiple instance method calls.

    Parameters

    • workFunction: WorkerFunction<unknown>

      The function which will process all jobs sent to this engine instance.

    • Optional initFunction: WorkerInitFunction<unknown>

      A function for setting up a Web Worker environment before it starts processing jobs. May be sync or async.

    • Optional initArgs: WorkerFunctionTransferArgs

      Dynamic data to send to the initFunction to set up the environment of new Web Worker instances.

    Returns Promise<RinzlerEngine>

  • Schedule, execute and get the results of a job.

    Returns

    A Promise that will be fulfilled with T or an empty resolve when the job has been processed.

    If the job threw an error when processing, the Promise will reject with an [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Instance_properties) object containing the job's error message.
    

    Type Parameters

    • T = void

      The return type of a successful job - meaning what the WorkerFunction will return, with Transferable objects inlined.

    Parameters

    Returns Promise<T>

  • Stop the engine.

    Wait for any remaining tasks to complete, shuts down all WebWorkers and sets the engine instance back to a blank state.

    Returns Promise<void>

Optimization Methods

  • Start as much WebWorkers as currently recommended by the browser, or allowed by afterburner.

    You should use this only if you know you will have to process many jobs and want to ensure that the engine is fully revved up. In most cases the automatic "temperature" adjustement will provide a good balance between performance and memory footprint.

    You should immediatly follow this call with your actual runJob calls, otherwise the engine might start to cool itself down automatically.

    Returns

    A Promise for the current engine instance. Can be used for chaining multiple instance method calls.

    Returns Promise<RinzlerEngine>

Other Methods

  • Returns Record<string, unknown>

⚠️ Dangerous Methods

  • WARNING: Possibly unstable.

    Overrides the maximum number of WebWorkers Rinzler will attempt to spawn.

    Normally this is retrieved from navigator.hardwareConcurrency, which is a browser-provided indicator of how many Workers a browsing context should use, with respect to the browser's own limitations and the number of available CPU cores on the host hardware.

    By going beyond that number you may crash the browser tab, get unexpected errors, or a considerable boost in parallelized performance. Aim for the moon, right?

    Returns

    A Promise for the current engine instance. Can be used for chaining multiple instance method calls.

    Parameters

    • max: number

      The new maximum number of WebWorkers this instance will manage. If set to lower than the current max, extra Workers will be gracefully shut down to respect the new limit.

    Returns Promise<RinzlerEngine>

Generated using TypeDoc