UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

49 lines (48 loc) 2.16 kB
import { AsyncJob, JobId } from '../../internal-common/src/public-types/job.public-types'; /** * Handles job subscriptions and notifications. * * **Important:** Each `jobId` must be globally unique and kept private. * Anyone who knows a job’s ID can query its status or result. */ export declare class JobClient { private readonly socketManager; private readonly rpcManager; private readonly clientIdService; private isListening; private readonly listeners; /** Jobs this client started and has not yet resolved; kept alive until resolved or the client shuts down. */ private readonly ownedJobs; private keepAliveHandle; /** * Starts a long-running job under a caller-generated `jobId`. The client owns the job until it * resolves it via {@link completeJob} or {@link failJob}; while owned, the job is kept alive so * core does not fail it. The `jobId` must be globally unique and kept private. */ startJob(jobId: JobId): Promise<void>; /** Resolves a job this client owns successfully with its result. */ completeJob<T = unknown>(jobId: JobId, result: T): Promise<void>; /** Resolves a job this client owns as failed with an error message. */ failJob(jobId: JobId, error: string): Promise<void>; /** * Retrieves the current status (and, if completed, the result) of a job. * * @param jobId A unique, private identifier for the job. * Do **not** reuse a `jobId` across clients—possessing the ID * allows anyone to inspect the job’s state. */ getJob<T = any>(jobId: JobId): Promise<AsyncJob<T> | undefined>; /** * Waits until the specified job finishes, then resolves with its result or * throws if the job fails. * * @param jobId A unique, private identifier for the job. * Do **not** reuse a `jobId` across clients—possessing the ID * allows anyone to inspect the job’s state. */ awaitJob<T = any>(jobId: JobId): Promise<T>; private maybeListenToJobs; private resolveJob; private ensureKeepAlive; private stopKeepAlive; }