import type { Observable } from 'rxjs'; import type { Command, State, SubArgs } from './types'; /** * Internal class that backs the {@linkcode Pausable} public type. * * The constructor is private — use {@linkcode createPausable} to obtain an * instance. * * @template T - The value type emitted by the source observable. */ declare class Pausable { #private; constructor(source$: Observable, observer: SubArgs | undefined); /** * Starts consuming the bound source observable and forwarding its events * to the observer. * * Has no effect if the instance is not currently in the `'stopped'` state. */ start: () => void; /** * Stops the stream. Cancels any pending resume timers by flipping * `#command` to `'stop'` (which makes `#canClear` return `true`). * Has no effect if the instance is already stopped. */ stop: () => void; /** * Suspends event dispatching while continuing to buffer incoming events. * * Records the current timestamp as `#lastPaused` (only on the first pause * of the current run) so that `resume()` can compute correct replay delays. * Has no effect if the instance is already paused or stopped. */ pause: () => void; /** * Replays all buffered events and then resumes live forwarding. * * Each buffered event is scheduled via `setTimeout` using its original * timestamp relative to `#lastPaused`, preserving the source's timing. * The timers are guarded by `#canClear`: if the instance is paused or * stopped again before a timer fires, that timer is cancelled. * * Has no effect if the instance is not currently paused. */ resume: () => void; /** * Subscribes an additional observer to the internal subject. * * Unlike the observer passed to {@linkcode createPausable}, this subscriber * is registered dynamically and receives the same forwarded events subject * to the same pause/resume/stop lifecycle controls. * * @param observer - The subscriber to add. Accepts either a plain `next` * callback or a partial {@linkcode Observer}. * @returns An RxJS `Subscription` that can be used to unsubscribe. */ subscribe: (observer: SubArgs) => import("rxjs").Subscription; /** * Dispatches a no-argument lifecycle command by name. * * Equivalent to calling the corresponding method directly. Useful when * the command is determined dynamically. * * @param action - The {@linkcode Command} to execute. */ command: (action: Command) => void; /** * The current observable state of the instance, derived from `#command`. * * - `'stopped'` when `#command` is `'stop'`. * - `'running'` when `#command` is `'start'` or `'resume'`. * - `'paused'` when `#command` is `'pause'`. */ get state(): State; } export type { Pausable }; export type CreatePausable_F = (source$: Observable, observer?: SubArgs) => Pausable; /** * Creates a {@linkcode Pausable} wrapper around a source RxJS observable. * * The returned object lets you `start`, `stop`, `pause`, and `resume` * the flow of events from `source$` to `observer`. Events that * arrive while the instance is paused are timestamped and buffered; when * `resume` is called they are replayed to the observer with their original * relative timing preserved. * * @template T - The value type emitted by the source observable. * * @param source$ - The RxJS observable whose emissions should be controlled. * @param observer - Optional subscriber that receives forwarded events. * Accepts either a plain `next` callback or a partial {@linkcode Observer}. * * @returns A {@linkcode Pausable} instance exposing lifecycle controls and a * read-only `state` property. * * @example * ```ts * import { interval } from 'rxjs'; * import { createPausable } from '@bemedev/rx-pausable'; * * const pausable = createPausable(interval(1000), value => console.log(value)); * pausable.start(); * * setTimeout(() => pausable.pause(), 3500); * setTimeout(() => pausable.resume(), 6000); * setTimeout(() => pausable.stop(), 9000); * ``` */ export declare const createPausable: CreatePausable_F; export * from './types'; //# sourceMappingURL=index.d.ts.map