arangojs
Version:
The official ArangoDB JavaScript driver.
88 lines • 2.66 kB
TypeScript
/**
* ```ts
* import type { Job } from "arangojs/jobs";
* ```
*
* The "jobs" module provides job-related types for TypeScript.
*
* @packageDocumentation
*/
import * as connection from "./connection.js";
import * as databases from "./databases.js";
/**
* Represents an async job in a {@link databases.Database}.
*
* @param ResultType - The type of the job's result.
*/
export declare class Job<ResultType = any> {
protected _id: string;
protected _db: databases.Database;
protected _transformResponse?: (res: connection.ProcessedResponse) => Promise<ResultType>;
protected _transformError?: (error: any) => Promise<ResultType>;
protected _loaded: boolean;
protected _result: ResultType | undefined;
/**
* @internal
*/
constructor(db: databases.Database, id: string, transformResponse?: (res: connection.ProcessedResponse) => Promise<ResultType>, transformError?: (error: any) => Promise<ResultType>);
/**
* Database this job belongs to.
*/
get database(): databases.Database;
/**
* The job's ID.
*/
get id(): string;
/**
* Whether the job's results have been loaded. If set to `true`, the job's
* result can be accessed from {@link Job.result}.
*/
get isLoaded(): boolean;
/**
* The job's result if it has been loaded or `undefined` otherwise.
*/
get result(): ResultType | undefined;
/**
* Loads the job's result from the database if it is not already loaded.
*
* @example
* ```js
* // 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);
* ```
*/
load(): Promise<ResultType | undefined>;
/**
* Cancels the job if it is still running. Note that it may take some time to
* actually cancel the job.
*/
cancel(): Promise<void>;
/**
* Deletes the result if it has not already been retrieved or deleted.
*/
deleteResult(): Promise<void>;
/**
* Fetches the job's completion state.
*
* Returns `true` if the job has completed, `false` otherwise.
*
* @example
* ```js
* // 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);
* ```
*/
getCompleted(): Promise<boolean>;
}
//# sourceMappingURL=jobs.d.ts.map