JS API Reference

Class: Job<Output>

job/job.Job

This API is experimental and subject to change. Use at your own risk.

The Job class represents a single self-contained unit of work that can be run on the Golem Network. It is responsible for managing the lifecycle of the work and providing information about its state. It also provides an event emitter that can be used to listen for state changes.

Type parameters

NameType
Outputunknown

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Job<Output>(id, yagnaApi, defaultOptions?): Job<Output>

Create a new Job instance. It is recommended to use GolemNetwork to create jobs instead of using this constructor directly.

Type parameters

NameType
Outputunknown

Parameters

NameType
idstring
yagnaApiYagnaApi
defaultOptionsPartial<RunJobOptions>

Returns

Job<Output>

Defined in

src/job/job.ts:76

Properties

events

Readonly events: EventEmitter<JobEventsDict, any>

Defined in

src/job/job.ts:62


results

results: undefined | Output

Defined in

src/job/job.ts:65


error

error: undefined | Error

Defined in

src/job/job.ts:66


state

state: TaskState = JobState.New

Defined in

src/job/job.ts:67


id

Readonly id: string

Defined in

src/job/job.ts:77

Methods

isRunning

isRunning(): boolean

Returns

boolean

Defined in

src/job/job.ts:82


startWork

startWork(workOnGolem, options?): void

Run your worker function on the Golem Network. This method will synchronously initialize all internal services and validate the job options. The work itself will be run asynchronously in the background. You can use the Job.events event emitter to listen for state changes. You can also use Job.waitForResult to wait for the job to finish and get the results. If you want to cancel the job, use Job.cancel. If you want to run multiple jobs in parallel, you can use GolemNetwork.createJob to create multiple jobs and run them in parallel.

Parameters

NameTypeDescription
workOnGolemWorker<Output>Your worker function that will be run on the Golem Network.
optionsRunJobOptionsConfiguration options for the job. These options will be merged with the options passed to the constructor.

Returns

void

Defined in

src/job/job.ts:98


cancel

cancel(): Promise<void>

Cancel the job. This method will stop the activity and wait for it to finish. Throws an error if the job is not running.

Returns

Promise<void>

Defined in

src/job/job.ts:235


waitForResult

waitForResult(): Promise<unknown>

Wait for the job to finish and return the results. Throws an error if the job was not started.

Returns

Promise<unknown>

Defined in

src/job/job.ts:249

Was this helpful?