Home Manual Reference Source
import Scheduler from '@pageproof/sdk/src/util/Scheduler.js'
public class | source

Scheduler

Constructor Summary

Public Constructor
public

constructor(options: object)

Member Summary

Public Members
public

options: *

public

The list of pending QueueItem.

public

workers: Map<Worker, boolean>

The registry of Workers.

Method Summary

Public Methods
public

handle(item: QueueItem, worker: Worker)

Actually sends a QueueItem message to a worker.

public

prime()

Primes the Scheduler to have the same number of Workers as the specified limit.

public

send(message: *): Promise<*>

Sends a message to a worker.

Public Constructors

public constructor(options: object) source

Params:

NameTypeAttributeDescription
options object
options.limit number

The maximum number of Workers which can be created

options.create function

The function which handles creating new Workers

Public Members

public options: * source

public queue: Array<QueueItem> source

The list of pending QueueItem.

public workers: Map<Worker, boolean> source

The registry of Workers. The key being the Worker, and the value being whether the Worker is idle.

Public Methods

public handle(item: QueueItem, worker: Worker) source

Actually sends a QueueItem message to a worker.

This method is in charge of calling Worker.postMessage with the QueueItem.message. It's also in charge of setting the Worker's idle state. The idle state is what prevents multiple messages from being sent to the same worker.

Params:

NameTypeAttributeDescription
item QueueItem

The queue item

worker Worker

The worker

public prime() source

Primes the Scheduler to have the same number of Workers as the specified limit.

See:

  • Scheduler.createWorker

public send(message: *): Promise<*> source

Sends a message to a worker.

Params:

NameTypeAttributeDescription
message *

A message to post to the worker

Return:

Promise<*>