///
import Deferred from '../Deferred';
import Buffer from '../Buffer';
import { PushAdapter } from '../common';
/**
* Async iterable iterator with a non-optional return method.
*/
export interface WrappedBalancer extends AsyncIterableIterator {
return(value?: A): Promise>;
throw?: undefined;
}
export interface Unpushed {
result: IteratorResult;
defer: Deferred>;
}
/**
* Balances a push queue with a pull queue, also known as a
* dropping-buffer channel, since the queues are FIFO and
* can be set to be bounded, i.e., to drop the oldest enqueued
* values if the limit is exceeded. The channel is unbounded
* by default.
*/
export default class Channel implements PushAdapter {
/** Pushed results waiting for pulls to resolve */
readonly pushBuffer: Buffer>;
/** Unresolved pulls waiting for results to be pushed */
readonly pullBuffer: Buffer>>;
/** Determines whether new values can be pushed or pulled */
private closed;
static fromDom: (type: keyof GlobalEventHandlersEventMap, target: import("../fromDom").Target, boolean | AddEventListenerOptions>, options?: boolean | AddEventListenerOptions | undefined) => AsyncIterableIterator | SecurityPolicyViolationEvent | SubmitEvent | TouchEvent | TransitionEvent | WheelEvent>;
static fromEmitter: (type: string | symbol, emitter: NodeJS.EventEmitter) => AsyncIterableIterator;
constructor(
/** Limit (bounds) after which the oldest buffered value is dropped. */
limit?: number);
/**
* Pull a promise of the next result.
*/
next(): Promise>;
/**
* Push the next result value.
*
* @param value - Result
* @param done - If true, closes the balancer when this result is resolved
* @throws Throws if the balancer is already closed
*/
push(value: A, done?: boolean): Promise>;
/**
* Returns itself, since {@link Channel} already implements the iterator protocol.
*/
[Symbol.asyncIterator](): this;
/**
* Closes the balancer; clears the queues and makes {@link Channel#next} only
* return `doneResult`.
*
* @param value - The result value to be returned
*/
return(value?: A): Promise>;
close(): void;
/**
* Convert {@link Channel} to a generic async iterable iterator to hide implementation details.
*
* @param onReturn - Optional callback for when the iterator is closed with {@link Channel#return}
* @throws Throws if called when closed
*/
wrap(onReturn?: () => void): WrappedBalancer;
}