import { BehaviorSubject, Observable, Subject } from 'rxjs';
type FunctionPatch<T> = (currentValue: T) => T;
type AsyncFunctionPatch<T> = (currentValue: T) => Promise<T>;
/**
 * A value or a function which takes the current value and returns a new value.
 */
export type Patch<T> = T | FunctionPatch<T>;
/**
 * Gets the current value of an observable, or undefined if the observable has
 * not emitted a value yet.
 *
 * @param observable$ the observable to get the value from.
 */
export declare const getCurrentValue: <T>(observable$: Observable<T>) => T;
/**
 * Updates the value of the provided Subject.
 * An `update` can either be a new value or a function which takes
 * the current value and returns a new value.
 *
 * @param subject the subject to update.
 * @param update the update to apply to the subject.
 * @return the updated value.
 */
export declare const setCurrentValue: <T>(subject: Subject<T>, update: Patch<T>) => T;
/**
 * Updates the value of the provided Subject asynchronously.
 * Locks the subject to prevent concurrent updates.
 *
 * @param subject the subject to update.
 * @param update the update to apply to the subject.
 */
export declare const setCurrentValueAsync: <T>(subject: Subject<T>, update: AsyncFunctionPatch<T>) => Promise<T>;
/**
 * Updates the value of the provided Subject and returns the previous value
 * and a function to roll back the update.
 * This is useful when you want to optimistically update a value
 * and roll back the update if an error occurs.
 *
 * @param subject the subject to update.
 * @param update the update to apply to the subject.
 */
export declare const updateValue: <T>(subject: BehaviorSubject<T>, update: Patch<T>) => {
    lastValue: T;
    value: T;
    rollback: () => T;
};
/**
 * Creates a subscription and returns a function to unsubscribe.
 *
 * @param observable the observable to subscribe to.
 * @param handler the handler to call when the observable emits a value.
 * @param onError an optional error handler.
 */
export declare const createSubscription: <T>(observable: Observable<T>, handler: (value: T) => void, onError?: (error: any) => void) => () => void;
/**
 * Creates a subscription and returns a function to unsubscribe. Makes sure that
 * only one async handler runs at the same time. If updates come in quicker than
 * it takes for the current handler to finish, other handlers will wait.
 *
 * @param observable the observable to subscribe to.
 * @param handler the async handler to call when the observable emits a value.
 */
export declare const createSafeAsyncSubscription: <T>(observable: Observable<T>, handler: (value: T) => Promise<void>) => () => void;
export {};
