import { destructor } from '../destructor'; /** Handler is called when the value of an Observable changes. */ export type Handler = (value: T) => void; export type AsyncHandler = (value: T) => Promise; /** A generic interface for an entity whose value can be observed when it changes. */ export interface Observable { /** * Binds the given handler to the Observable, and starts calling it whenever the * value of the Observable changes. * @param handler The handler to bind to the Observable. * @returns A function that can be called to unbind the handler from the Observable. */ onChange: (handler: Handler) => destructor.Destructor; } /** An Observable that can be closed using an async function. */ export interface ObservableAsyncCloseable extends Observable { /** Closes the Observable. */ close: () => Promise; } /** A function that transforms a value of type I into a value of type O. * @param value The value to transform. * @returns A tuple containing the transformed value and a boolean indicating whether * the value has changed (i.e. whether the observable should notify its handlers). */ export type Transform = (value: I) => [O, true] | [O | null, false]; /** * An implementation fo the Observable interface that can be manually notified of changes. */ export declare class Observer implements ObservableAsyncCloseable { private readonly handlers; private readonly transform?; private closer?; constructor(transform?: Transform, handlers?: Map, null>); /** Implements the observable interface. */ onChange(handler: Handler): destructor.Destructor; /** Notifies all handlers that the value of the observable has changed. */ notify(value: I): void; setCloser(closer: () => Promise): void; close(): Promise; } export declare class BaseObserver implements Observable { private readonly handlers; constructor(handlers?: Map, null>); onChange(handler: Handler): destructor.Destructor; notify(value: V): void; } //# sourceMappingURL=observe.d.ts.map