Skip to content

Latest commit

 

History

History
375 lines (271 loc) · 13.3 KB

API.md

File metadata and controls

375 lines (271 loc) · 13.3 KB

Classes

ChannelEventEmitter

Channel class (queue)

ChannelQueueEventEmitter

ChannelQueue class, for managing channels

ParallelChannelChannel

ParallelChannel class (queue)

Task

Internal Task class, for handling executions

Typedefs

TaskPriority : Normal | High | Tail

Task Priority

ChannelQueue ⇐ EventEmitter

ChannelQueue class, for managing channels

Kind: global class
Extends: EventEmitter

channelQueue.channels : Object

The channels

Kind: instance property of ChannelQueue

channelQueue.createChannel(name) ⇒ Channel

Create a new channel

Kind: instance method of ChannelQueue
Returns: Channel - The new channel
Throws:

  • Error Throws if the channel already exists
Param Type Description
name String The channel name

channelQueue.createParallelChannel(name, [parallelism]) ⇒ ParallelChannel

Create a new parallel channel Creates a special channel that supports running several tasks in parallel.

Kind: instance method of ChannelQueue
Returns: ParallelChannel - The new channel
Throws:

  • Error Throws if the channel already exists
Param Type Description
name String The name of the channel
[parallelism] Number Optional number of maximum parallel tasks

channelQueue.channel(name) ⇒ Channel

Get channel by name Creates a new channel automatically if it doesn't yet exist

Kind: instance method of ChannelQueue
Returns: Channel - The channel which was requested

Param Type Description
name String The channel name

channelQueue.channelExists(name) ⇒ Boolean

Check if a channel exists

Kind: instance method of ChannelQueue
Returns: Boolean - True if it exists

Param Type Description
name String The name of the channel

ParallelChannel ⇐ Channel

ParallelChannel class (queue)

Kind: global class
Extends: Channel

parallelChannel.isEmpty : Boolean

Whether the queue is empty or not

Kind: instance property of ParallelChannel
Overrides: isEmpty
Read only: true

parallelChannel.parallelism : Number

The amount of allowed parallel executed tasks

Kind: instance property of ParallelChannel
Read only: true

parallelChannel.runningTasks : Array.<Task>

Get the currently running tasks

Kind: instance property of ParallelChannel
Read only: true

parallelChannel.autostart : Boolean

Whether the execution should start automatically or not Defaults to true

Kind: instance property of ParallelChannel
Overrides: autostart

parallelChannel.isRunning : Boolean

Whether the queue is currently running or not

Kind: instance property of ParallelChannel
Overrides: isRunning
Read only: true

parallelChannel.name : String

The name of the channel

Kind: instance property of ParallelChannel
Overrides: name
Read only: true

parallelChannel.tasks : Array.<Task>

Array of tasks (in queue)

Kind: instance property of ParallelChannel
Overrides: tasks
Read only: true

parallelChannel.tasksThrow : Boolean

Whether or not tasks throw errors

Kind: instance property of ParallelChannel
Overrides: tasksThrow

parallelChannel.clear([priorityType])

Remove all pending tasks from the channel

Kind: instance method of ParallelChannel
Overrides: clear

Param Type Description
[priorityType] String Optional priority type to clear only tasks with a certain priority value

parallelChannel.enqueue(item, [type], [stack], [timeout]) ⇒ Promise

Enqueues a function

Kind: instance method of ParallelChannel
Overrides: enqueue
Returns: Promise - A promise that eventually resolves with the result from the enqueued function or promise

Param Type Description
item function | Promise The item to place into the queue
[type] TaskPriority The task priority to use
[stack] String The stack name
[timeout] Number Optional millisecond time-limt

parallelChannel.getStackedItems(stack) ⇒ Array.<Task>

Get all task items for a stack name

Kind: instance method of ParallelChannel
Overrides: getStackedItems
Returns: Array.<Task> - An array of task instances

Param Type Description
stack String The stack name

parallelChannel.retrieveNextItem() ⇒ Task | undefined

Get the next queued Task instance This modifies the task queue by removing the task

Kind: instance method of ParallelChannel
Overrides: retrieveNextItem
Returns: Task | undefined - A task instance if there are any in queue

parallelChannel.sort()

Sort the tasks

Kind: instance method of ParallelChannel
Overrides: sort

parallelChannel.start() ⇒ Boolean

Start processing the queue Will automatically return early if queue has already started

Kind: instance method of ParallelChannel
Overrides: start
Returns: Boolean - Returns true if started, false if already started
Emits: Channel#event:started, Channel#event:stopped

parallelChannel.waitForEmpty() ⇒ Promise

Wait for the queue to become empty

Kind: instance method of ParallelChannel
Overrides: waitForEmpty

Task

Internal Task class, for handling executions

Kind: global class

new Task(item, [type], [stack])

Constructor for a Task

Param Type Description
item function | Promise The item to enqueue
[type] TaskPriority The priority to set
[stack] String The stack name

task.created : Number

Creation timestamp

Kind: instance property of Task
Read only: true

task.error : Error | null

Execution error, if one occurred

Kind: instance property of Task

task.queuedPromise : Promise

Promise which resolves when work has completed

Kind: instance property of Task

task.stack : String

The stack name

Kind: instance property of Task

task.target : function

The target function

Kind: instance property of Task

task.timeLimit : Number

Current time limit

Kind: instance property of Task

task.type : TaskPriority

The task priority type

Kind: instance property of Task

task.execute() ⇒ Promise

Execute the task

Kind: instance method of Task

TaskPriority : Normal | High | Tail

Task Priority

Kind: global typedef

TaskPriority.Normal

Normal task priority

Kind: static property of TaskPriority

TaskPriority.High

High task priority

Kind: static property of TaskPriority

TaskPriority.Tail

Task tail-priority

Kind: static property of TaskPriority