/** * Common communication protocol for [[WorkerService]]. */ export declare namespace WorkerServiceProtocol { /** * Service id of worker manager ([[WorkerServiceManager]]) used to create/destroy service * instances in workers. */ const WORKER_SERVICE_MANAGER_SERVICE_ID = "worker-service-manager"; /** * Define possible names of messages exchanged with services within `WebWorker`. */ enum ServiceMessageName { Initialized = "initialized", Request = "request", Response = "response" } /** * Interface for `ServiceMessage` which describes metadata for a service messages. */ interface ServiceMessage { service: string; type: ServiceMessageName; } /** * This message is sent by the worker to the main thread. No data is sent. Receiving this * message confirms that the worker has started successfully. */ interface InitializedMessage extends ServiceMessage { type: ServiceMessageName.Initialized; } /** * Type guard to check if an object is a signal message from worker. */ function isInitializedMessage(message: any): message is InitializedMessage; /** * Define possible names of requests called on services within `WebWorker`. */ enum Requests { CreateService = "create-service", DestroyService = "destroy-service" } /** * This is an internal general interface used in communication with workers. * Check [[ConcurrentWorkerSet]]'s invokeRequest function for exemplary usage. */ interface ServiceRequest { type: string; } /** * This message is sent by the main thread to [[WorkerServiceManager]] to dynamically create a * new service. * * May throw `UnknownServiceError` if service of given type is not registered in * [[WorkerServiceManager]], see [[isUnknownServiceError]]. */ interface CreateServiceRequest extends ServiceRequest { type: Requests.CreateService; /** * Type of service to be created. * * @see [[WorkerServiceManager.register]] */ targetServiceType: string; /** * The newly created service instance will be available under this id. */ targetServiceId: string; } /** * Test if `error` thrown by [[CreateServiceRequest]] was caused by unknown type of service. */ function isUnknownServiceError(error: Error): boolean; /** * This message is sent by the main thread to [[WorkerServiceManager]] to dynamically destroy a * service. */ interface DestroyServiceRequest extends ServiceRequest { type: Requests.DestroyService; /** * Id of service to be destroyed. */ targetServiceId: string; } /** * Possible service management messages (`CreateService` or `DestroyService`) sent to WebWorker. */ type WorkerServiceManagerRequest = CreateServiceRequest | DestroyServiceRequest; /** * This message is a part of the Request-Response scheme implemented to be used in communication * between workers and the decoder. */ interface RequestMessage extends ServiceMessage { type: ServiceMessageName.Request; messageId: number; request: any; } /** * Type guard to check if an object is a request message sent to a worker. */ function isRequestMessage(message: any): message is RequestMessage; /** * This message is a part of the Request-Response scheme implemented to be used in communication * between workers and the decoder. */ interface ResponseMessage extends ServiceMessage { type: ServiceMessageName.Response; messageId: number; errorMessage?: string; errorStack?: string; response?: object; } /** * Type guard to check if an object is a request message sent to a worker. */ function isResponseMessage(message: any): message is ResponseMessage; } //# sourceMappingURL=WorkerServiceProtocol.d.ts.map