Class Job<T>

Represents an async job in a database.Database.

Type Parameters

  • T = any

Accessors

  • get id(): string
  • The job's ID.

    Returns string

  • get isLoaded(): boolean
  • Whether the job's results have been loaded. If set to true, the job's result can be accessed from Job.result.

    Returns boolean

  • get result(): undefined | T
  • The job's result if it has been loaded or undefined otherwise.

    Returns undefined | T

Methods

  • Cancels the job if it is still running. Note that it may take some time to actually cancel the job.

    Returns Promise<void>

  • Deletes the result if it has not already been retrieved or deleted.

    Returns Promise<void>

  • Fetches the job's completion state.

    Returns true if the job has completed, false otherwise.

    Returns Promise<boolean>

    Example

    // poll for the job to complete
    while (!(await job.getCompleted())) {
    await timeout(1000);
    }
    // job result is now available and can be loaded
    await job.load();
    console.log(job.result);
  • Loads the job's result from the database if it is not already loaded.

    Returns Promise<undefined | T>

    Example

    // poll for the job to complete
    while (!job.isLoaded) {
    await timeout(1000);
    const result = await job.load();
    console.log(result);
    }
    // job result is now loaded and can also be accessed from job.result
    console.log(job.result);