/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Diagnostic } from "../log/Diagnostic.js";
import { Observable } from "../util/Observable.js";
import type { Environment } from "./Environment.js";
import { Environmental } from "./Environmental.js";
import type { Worker } from "./Worker.js";
/**
 * Handles lifecycle management of other components.
 */
export declare class RuntimeService {
    #private;
    [Diagnostic.value]: unknown[];
    constructor(environment: Environment);
    /**
     * Add a {@link Worker}, either directly or by invoking an {@link Initiator}.
     *
     * The runtime considers itself "active" if there are one or more workers installed.
     *
     * A worker must either be {@link PromiseLike} or {@link Constructable} for the runtime to detect completion. On
     * completion the worker is removed and destroyed if the worker is {@link Destructable}.
     *
     * Once added, the {@link worker} is owned by the RuntimeService until closed, resolved or removed via
     * {@link delete}.
     */
    add(worker: RuntimeService.NewWorker): void;
    /**
     * Remove a worker.
     */
    delete(worker: Worker): void;
    /**
     * Emits when a worker is added when previously there were none.
     */
    get started(): Observable<[], void>;
    /**
     * Emits when the last worker departs.
     */
    get stopped(): Observable<[], void>;
    /**
     * Emits when a worker experiences an unhandled error.
     */
    get crashed(): Observable<[cause: any], void>;
    static [Environmental.create](environment: Environment): RuntimeService;
    /**
     * Cancel execution.
     *
     * On cancel the runtime destroys all workers.
     */
    cancel(): void;
    /**
     * Interrupt handler.  Triggered by e.g. SIGINT on unixish systems.
     *
     * The default implementation cancels the runtime.
     */
    interrupt(): void;
    /**
     * Resolves when no workers are active.
     */
    get inactive(): Promise<void>;
    close(): Promise<void>;
    [Symbol.asyncDispose](): Promise<void>;
}
export declare namespace RuntimeService {
    /**
     * A function that initiates work.
     */
    interface Initiator {
        (env: Environment): NewWorker;
    }
    type NewWorker = Worker | Initiator | void;
}
//# sourceMappingURL=RuntimeService.d.ts.map