1 | import { Database } from "./database.js";
|
2 | import { ArangojsResponse } from "./lib/request.js";
|
3 | /**
|
4 | * Represents an async job in a {@link database.Database}.
|
5 | */
|
6 | export declare class Job<T = any> {
|
7 | protected _id: string;
|
8 | protected _db: Database;
|
9 | protected _transformResponse?: (res: ArangojsResponse) => Promise<T>;
|
10 | protected _transformError?: (error: any) => Promise<T>;
|
11 | protected _loaded: boolean;
|
12 | protected _result: T | undefined;
|
13 | /**
|
14 | * @internal
|
15 | */
|
16 | constructor(db: Database, id: string, transformResponse?: (res: ArangojsResponse) => Promise<T>, transformError?: (error: any) => Promise<T>);
|
17 | /**
|
18 | * The job's ID.
|
19 | */
|
20 | get id(): string;
|
21 | /**
|
22 | * Whether the job's results have been loaded. If set to `true`, the job's
|
23 | * result can be accessed from { Job.result}.
|
24 | */
|
25 | get isLoaded(): boolean;
|
26 | /**
|
27 | * The job's result if it has been loaded or `undefined` otherwise.
|
28 | */
|
29 | get result(): T | undefined;
|
30 | /**
|
31 | * Loads the job's result from the database if it is not already loaded.
|
32 | *
|
33 | * @example
|
34 | * ```js
|
35 | * // poll for the job to complete
|
36 | * while (!job.isLoaded) {
|
37 | * await timeout(1000);
|
38 | * const result = await job.load();
|
39 | * console.log(result);
|
40 | * }
|
41 | * // job result is now loaded and can also be accessed from job.result
|
42 | * console.log(job.result);
|
43 | * ```
|
44 | */
|
45 | load(): Promise<T | undefined>;
|
46 | /**
|
47 | * Cancels the job if it is still running. Note that it may take some time to
|
48 | * actually cancel the job.
|
49 | */
|
50 | cancel(): Promise<void>;
|
51 | /**
|
52 | * Deletes the result if it has not already been retrieved or deleted.
|
53 | */
|
54 | deleteResult(): Promise<void>;
|
55 | /**
|
56 | * Fetches the job's completion state.
|
57 | *
|
58 | * Returns `true` if the job has completed, `false` otherwise.
|
59 | *
|
60 | * @example
|
61 | * ```js
|
62 | * // poll for the job to complete
|
63 | * while (!(await job.getCompleted())) {
|
64 | * await timeout(1000);
|
65 | * }
|
66 | * // job result is now available and can be loaded
|
67 | * await job.load();
|
68 | * console.log(job.result);
|
69 | * ```
|
70 | */
|
71 | getCompleted(): Promise<boolean>;
|
72 | }
|
73 | //# sourceMappingURL=job.d.ts.map |
\ | No newline at end of file |