Home Reference Source Repository
import Thread from 'wyst/es6/Queue/Thread.js'
public class | source

Thread

exposes a useful API for managing the state of processes created from cluster.fork()

Static Member Summary

Static Public Members
public static get

the key definition that stores the business of a <Process>

Static Method Summary

Static Public Methods
public static

Generates a new Thread instance

public static

free(thread: Process): Process

sets the BUSY_SWITCH to false for a given <Process>

public static

isAvailable(thread: Process): boolean

Determine if a Thread is available.

public static

kill(process: Process): *

Used by the Main process to kill a Thread

public static

reserve(thread: Process): Process

sets the BUSY_SWITCH to true for a given <Process>

public static

spin(fabric: *): Promise

forks a new Thread for the cluster.Master <Process:Main> to use

Constructor Summary

Public Constructor
public

generates a new Thread instance when cluster.isWorker is true

Member Summary

Public Members
public

debug: *

Method Summary

Public Methods
public

done(id: <type>, result: <type>)

Convience wrapper for emitting successful <Job> completion

public

emit(namespace: String, data: Object): Thread

Emits a namespaced <Event> back to <Process:Main>

public

error(id: String, err: Error): Thread

Convenience wrapper for Thread.prototype.emit(Thread.Event.Error, <Error>)

public

invalidate(script: String)

invalidates the local require cache for a particular script

public

run(job: Object): Thread

The runtime wrapper for a <Job>

public

verify(data: Object, keys: Array): boolean

Checks the integrity of a <Job> before a <Thread> attempts to process it

Static Public Members

public static get BUSY_SWITCH: String: string source

the key definition that stores the business of a <Process>

Return:

String

Static Public Methods

public static create(): Thread source

Generates a new Thread instance

Return:

Thread

public static free(thread: Process): Process source

sets the BUSY_SWITCH to false for a given <Process>

Params:

NameTypeAttributeDescription
thread Process

The thread to free

Return:

Process

public static isAvailable(thread: Process): boolean source

Determine if a Thread is available.

Params:

NameTypeAttributeDescription
thread Process

The thread

Return:

boolean

True if available, False otherwise.

public static kill(process: Process): * source

Used by the Main process to kill a Thread

Params:

NameTypeAttributeDescription
process Process

The process to kill

Return:

*

public static reserve(thread: Process): Process source

sets the BUSY_SWITCH to true for a given <Process>

Params:

NameTypeAttributeDescription
thread Process

The thread to reserve

Return:

Process

public static spin(fabric: *): Promise source

forks a new Thread for the cluster.Master <Process:Main> to use

Params:

NameTypeAttributeDescription
fabric *

Return:

Promise

Public Constructors

public constructor: Thread source

generates a new Thread instance when cluster.isWorker is true

Return:

Thread

Public Members

public debug: * source

Public Methods

public done(id: <type>, result: <type>) source

Convience wrapper for emitting successful <Job> completion

Params:

NameTypeAttributeDescription
id <type>

the <Job:id> that should be associated with the <Result>

result <type>

The result of <Job>

public emit(namespace: String, data: Object): Thread source

Emits a namespaced <Event> back to <Process:Main>

Params:

NameTypeAttributeDescription
namespace String

The namespace

data Object

The data

Return:

Thread

public error(id: String, err: Error): Thread source

Convenience wrapper for Thread.prototype.emit(Thread.Event.Error, <Error>)

Params:

NameTypeAttributeDescription
id String

the <Job:id> that should be associated with the <Error>

err Error

The <Error> that occured

Return:

Thread

public invalidate(script: String) source

invalidates the local require cache for a particular script

Params:

NameTypeAttributeDescription
script String

The absolute path of the script

public run(job: Object): Thread source

The runtime wrapper for a <Job>

Params:

NameTypeAttributeDescription
job Object

The <Job> to run

Return:

Thread

public verify(data: Object, keys: Array): boolean source

Checks the integrity of a <Job> before a <Thread> attempts to process it

Params:

NameTypeAttributeDescription
data Object

The data to verify

keys Array

The keys to verify exist for <data>

Return:

boolean

Where <data> is valid or not