export = Service; /** * @template Options, T * * Allows you to create a handle to service that can be started or * stopped. It enables defining components that need to use service * functionality before service is started. * */ declare class Service { /** * Takes `activation` function that takes `options` and (async) returns * an implementation. * * @template {(options:any) => Await} T * * @param {Object} config * @param {T} config.start * @param {(state:State) => Await} [config.stop] * @returns {Service[0], State>} */ static create Await>({ start, stop }: { start: T_1; stop?: ((state: ReturnType extends Promise | null ? U : ReturnType) => Await) | undefined; }): import("./service")[0], ReturnType extends Promise | null ? U : ReturnType>; /** * Starts the service (by running actiavtion function). Will (async) throw * unless service is stopped. * * @template Options, T * @param {Service} service * @param {Options} options * @returns {Promise} */ static start(service: import("./service"), options: Options_2): Promise; /** * Stops the service by executing deactivation. If service is stopped * or is stopping this is noop. If service is starting up when called * it will await for start to complete and then retry stop afterwards. * This may (async) throw if `deactivate` does. * * @template T * @param {Service} service * @returns {Promise} */ static stop(service: import("./service")): Promise; /** * @template T * @param {Service} service * @returns {T|null} */ static try({ state }: import("./service")): T_4 | null; /** * Unwraps state and returns underlying value. If state is in idle state it * will throw an error. If state is pending it will wait and return the * result or throw on failure. If state is ready returns result. * * @template T * @param {Service} service * @param {AbortOptions} [options] * @returns {Promise} */ static use({ state }: import("./service"), options?: import("../utils").AbortOptions | undefined): Promise; /** * @private * @param {Service} service * @returns {never} */ private static panic; /** * Takes `activation` function that takes `options` and (async) returns * an implementation. * * @private * @param {(options:Options) => Await} activate * @param {(state:T) => Await} [deactivate] */ private constructor(); activate: (options: Options_1) => import("../interface/basic").Await; deactivate: ((state: T) => Await) | undefined; /** * A state machine for this service. * * @private * @type {ServiceState} */ private state; /** * Allows you to asynchronously obtain service implementation. If service * is starting it will await for completion. If service is stopped or stopping * this will (async) throw exception. This allows components that need to use * this service convenient API to do it. * * @param {AbortOptions} [options] - Abort options. * @returns {Promise} */ use(options?: import("../utils").AbortOptions | undefined): Promise; /** * @returns {T|null} */ try(): T | null; } declare namespace Service { export { Await, Options, State, ServiceState, AbortOptions }; } type Await = T | Promise; type State any> = ReturnType extends Promise | null ? U : ReturnType; type Options any> = Parameters[0]; /** * Represents service state which can be not started in which case * it is instanceof `Error`. Pending in which case it's promise or * ready in which case it is the value itself. */ type ServiceState = { status: 'stopped'; } | { status: 'starting'; ready: import("../interface/basic").Await; } | { status: 'started'; value: T; } | { status: 'stopping'; ready: Await; }; type AbortOptions = { /** * - A timeout in ms */ timeout?: number | undefined; /** * - Can be used to cancel any long running requests started as a result of this call */ signal?: AbortSignal | undefined; }; //# sourceMappingURL=service.d.ts.map