Class: Job

Job(promiseProducer, nameopt)

The events emitted are (using the declared/exported symbols and the class JobEvent): - 'run' (immediately triggered before the job is run) - 'done' (if successfully ran to completion, includes the result) - 'failed' (if failed with an error, includes the error)

Constructor

new Job(promiseProducer, nameopt)

Parameters:
Name Type Attributes Description
promiseProducer producerHandler.<Promise.<T>> A function returning a Promise or an async function (essentially the same). If you want to use a sync function, call Job::fromSyncFunction(fn) instead.
name String <optional>
Optional. Defaults to undefined. Give an optional name to this job.
Author:
Source:
See:
  • {fromSyncFunction()}

Extends

  • EventEmitter

Members

cost :void

Type:
  • void
Source:

cost :Number|undefined

Type:
  • Number | undefined
Source:

createTime :Date

Returns the timestamp of when this Job was created.
Type:
  • Date
Source:

donePromise :Promise.<T>

A promise that can be used to await this Job's final state. If resolved, will resolve with this Job's result. The promise returned by run() should only be used by the queue.
Type:
  • Promise.<T>
Source:

hasCost :Boolean

Returns whether this Job has an associated cost.
Type:
  • Boolean
Source:

hasFailed :Boolean

Type:
  • Boolean
Source:

isDone :Boolean

Type:
  • Boolean
Source:

isRunning :Boolean

Type:
  • Boolean
Source:

isStopped :Boolean

Returns true, iff this Job was previously started and is now either done or has failed.
Type:
  • Boolean
Source:

name :undefined|String

Returns the name of this Job.
Type:
  • undefined | String
Source:

name :void

Sets the name of this Job.
Type:
  • void
Source:

observableDone :Observable.<JobEvent>

Type:
Source:

observableFailed :Observable.<JobEvent>

Type:
Source:

observableRun :Observable.<JobEvent>

Type:
Source:

progress :void

Use this setter to give this Job an instance of Progress that may be used by the scheduler for this Job. This Job itself does not observe the instance or subscribe to its observables.
Type:
  • void
Source:

progress :Progress.<TProgress>

Returns the Progress-instance of type TProgress.
Type:
Source:

properties :DictionaryMapBased.<any, any>

Returns a map with arbitrary properties or date associated with this Job.
Type:
Source:

result :T

Type:
  • T
Source:

runDurationMs :Number

Returns the amount of milliseconds between start- and stop-time of this Job. If the Job was not yet started, returns 0. If it is still running, returns the time between start and now, otherwise between start and stop.
Type:
  • Number
Source:

startTime :Date

Returns the timestamp of when this Job was started.
Type:
  • Date
Source:

stopTime :Date

Returns the timestamp of when this Job was stopped (when it finished with success or failed).
Type:
  • Date
Source:

supportsProgress :Boolean

Returns whether or not this Job is/was equipped with an instance of Progress.
Type:
  • Boolean
Source:

wasStarted :Boolean

Returns true, iff this Job was started. This is also true for done or failed Jobs or those that are currently running.
Type:
  • Boolean
Source:

Methods

(static) fromProcess(processWrapper) → {Job}

Convenience function to create a Job from a ProcessWrapper. Once run, the Job will run the ProcessWrapper as Observable. All observed output is then reported as Progress, as the Job will be decorated with a Progress-instance of type ProcessOutput.
Parameters:
Name Type Description
processWrapper ProcessWrapper
Source:
Returns:
Type
Job

(static) fromSyncFunction(func) → {Job}

Creates a job from a synchronous function by wrapping it into an async function.
Parameters:
Name Type Description
func function A function that does synchronous work and returns a value (i.e. its result is not awaited).
Source:
Returns:
Type
Job

(async) run() → {Promise.<T>}

Source:
Returns:
the Promise that will resolve with the job's result.
Type
Promise.<T>