interface IDisposable { dispose(): void; } declare function isDisposable(thing: E): thing is E & IDisposable; declare function dispose(disposable: T): T; declare function dispose(disposable: T | undefined): T | undefined; declare function dispose(disposables: Array): Array; declare function dispose(disposables: ReadonlyArray): ReadonlyArray; declare function combinedDisposable(...disposables: IDisposable[]): IDisposable; declare function toDisposable(fn: () => void): IDisposable; declare class DisposableStore implements IDisposable { static DISABLE_DISPOSED_WARNING: boolean; private _toDispose; private _isDisposed; /** * Dispose of all registered disposables and mark this object as disposed. * * Any future disposables added to this object will be disposed of on `add`. */ dispose(): void; /** * Dispose of all registered disposables but do not mark this object as disposed. */ clear(): void; add(t: T): T; } declare abstract class Disposable implements IDisposable { static readonly None: Readonly; private readonly _store; constructor(); dispose(): void; protected _register(t: T): T; } /** * Manages the lifecycle of a disposable value that may be changed. * * This ensures that when the disposable value is changed, the previously held disposable is disposed of. You can * also register a `MutableDisposable` on a `Disposable` to ensure it is automatically cleaned up. */ /** * Manages the lifecycle of a disposable value that may be changed. * * This ensures that when the disposable value is changed, the previously held disposable is disposed of. You can * also register a `MutableDisposable` on a `Disposable` to ensure it is automatically cleaned up. */ declare class MutableDisposable implements IDisposable { private _value?; private _isDisposed; constructor(); get value(): T | undefined; set value(value: T | undefined); clear(): void; dispose(): void; } interface IReference extends IDisposable { readonly object: T; } declare abstract class ReferenceCollection { private readonly references; acquire(key: string): IReference; protected abstract createReferencedObject(key: string): T; protected abstract destroyReferencedObject(key: string, object: T): void; } declare class ImmortalReference implements IReference { object: T; constructor(object: T); dispose(): void; } declare namespace CancellationToken$0 { function isCancellationToken(thing: any): thing is CancellationToken$0; const None: CancellationToken$0; const Cancelled: CancellationToken$0; } declare class CancellationTokenSource { private _token?; private _parentListener?; constructor(parent?: CancellationToken$0); get token(): CancellationToken$0; cancel(): void; dispose(cancel?: boolean): void; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ interface IteratorDefinedResult { readonly done: false; readonly value: T; } interface IteratorUndefinedResult { readonly done: true; readonly value: undefined; } type IteratorResult = IteratorDefinedResult | IteratorUndefinedResult; interface NativeIteratorYieldResult { done?: false; value: TYield; } interface NativeIteratorReturnResult { done: true; value: TReturn; } type NativeIteratorResult = NativeIteratorYieldResult | NativeIteratorReturnResult; interface NativeIterator { next(): NativeIteratorResult; } declare module Iterator$0 { function empty(): Iterator$0; function single(value: T): Iterator$0; function fromArray(array: ReadonlyArray, index?: number, length?: number): Iterator$0; function fromNativeIterator(it: NativeIterator): Iterator$0; function from(elements: Iterator$0 | T[] | undefined): Iterator$0; function map(iterator: Iterator$0, fn: (t: T) => R): Iterator$0; function filter(iterator: Iterator$0, fn: (t: T) => boolean): Iterator$0; function forEach(iterator: Iterator$0, fn: (t: T) => void): void; function collect(iterator: Iterator$0, atMost?: number): T[]; function concat(...iterators: Iterator$0[]): Iterator$0; function chain(iterator: Iterator$0): ChainableIterator; } declare class ChainableIterator implements Iterator$0 { private it; constructor(it: Iterator$0); next(): IteratorResult; map(fn: (t: T) => R): ChainableIterator; filter(fn: (t: T) => boolean): ChainableIterator; } declare class LinkedList { private _first; private _last; private _size; get size(): number; isEmpty(): boolean; clear(): void; unshift(element: E): () => void; push(element: E): () => void; private _insert; shift(): E | undefined; pop(): E | undefined; private _remove; iterator(): Iterator$0; toArray(): E[]; } declare namespace Event$0 { const None: Event$0; /** * Given an event, returns another event which only fires once. */ function once(event: Event$0): Event$0; /** * Given an event and a `map` function, returns another event which maps each element * through the mapping function. */ /** * Given an event and a `map` function, returns another event which maps each element * through the mapping function. */ function map(event: Event$0, map: (i: I) => O): Event$0; /** * Given an event and an `each` function, returns another identical event and calls * the `each` function per each element. */ /** * Given an event and an `each` function, returns another identical event and calls * the `each` function per each element. */ function forEach(event: Event$0, each: (i: I) => void): Event$0; /** * Given an event and a `filter` function, returns another event which emits those * elements for which the `filter` function returns `true`. */ /** * Given an event and a `filter` function, returns another event which emits those * elements for which the `filter` function returns `true`. */ function filter(event: Event$0, filter: (e: T) => boolean): Event$0; function filter(event: Event$0, filter: (e: T | R) => e is R): Event$0; /** * Given an event, returns the same event but typed as `Event`. */ function signal(event: Event$0): Event$0; /** * Given a collection of events, returns a single event which emits * whenever any of the provided events emit. */ /** * Given a collection of events, returns a single event which emits * whenever any of the provided events emit. */ function any(...events: Event$0[]): Event$0; function any(...events: Event$0[]): Event$0; /** * Given an event and a `merge` function, returns another event which maps each element * and the cumulative result through the `merge` function. Similar to `map`, but with memory. */ function reduce(event: Event$0, merge: (last: O | undefined, event: I) => O, initial?: O): Event$0; /** * Given a chain of event processing functions (filter, map, etc), each * function will be invoked per event & per listener. Snapshotting an event * chain allows each function to be invoked just once per event. */ /** * Given a chain of event processing functions (filter, map, etc), each * function will be invoked per event & per listener. Snapshotting an event * chain allows each function to be invoked just once per event. */ function snapshot(event: Event$0): Event$0; /** * Debounces the provided event, given a `merge` function. * * @param event The input event. * @param merge The reducing function. * @param delay The debouncing delay in millis. * @param leading Whether the event should fire in the leading phase of the timeout. * @param leakWarningThreshold The leak warning threshold override. */ /** * Debounces the provided event, given a `merge` function. * * @param event The input event. * @param merge The reducing function. * @param delay The debouncing delay in millis. * @param leading Whether the event should fire in the leading phase of the timeout. * @param leakWarningThreshold The leak warning threshold override. */ function debounce(event: Event$0, merge: (last: T | undefined, event: T) => T, delay?: number, leading?: boolean, leakWarningThreshold?: number): Event$0; function debounce(event: Event$0, merge: (last: O | undefined, event: I) => O, delay?: number, leading?: boolean, leakWarningThreshold?: number): Event$0; /** * Given an event, it returns another event which fires only once and as soon as * the input event emits. The event data is the number of millis it took for the * event to fire. */ function stopwatch(event: Event$0): Event$0; /** * Given an event, it returns another event which fires only when the event * element changes. */ /** * Given an event, it returns another event which fires only when the event * element changes. */ function latch(event: Event$0): Event$0; /** * Buffers the provided event until a first listener comes * along, at which point fire all the events at once and * pipe the event from then on. * * ```typescript * const emitter = new Emitter(); * const event = emitter.event; * const bufferedEvent = buffer(event); * * emitter.fire(1); * emitter.fire(2); * emitter.fire(3); * // nothing... * * const listener = bufferedEvent(num => console.log(num)); * // 1, 2, 3 * * emitter.fire(4); * // 4 * ``` */ /** * Buffers the provided event until a first listener comes * along, at which point fire all the events at once and * pipe the event from then on. * * ```typescript * const emitter = new Emitter(); * const event = emitter.event; * const bufferedEvent = buffer(event); * * emitter.fire(1); * emitter.fire(2); * emitter.fire(3); * // nothing... * * const listener = bufferedEvent(num => console.log(num)); * // 1, 2, 3 * * emitter.fire(4); * // 4 * ``` */ function buffer(event: Event$0, nextTick?: boolean, _buffer?: T[]): Event$0; interface IChainableEvent { event: Event$0; map(fn: (i: T) => O): IChainableEvent; forEach(fn: (i: T) => void): IChainableEvent; filter(fn: (e: T) => boolean): IChainableEvent; filter(fn: (e: T | R) => e is R): IChainableEvent; reduce(merge: (last: R | undefined, event: T) => R, initial?: R): IChainableEvent; latch(): IChainableEvent; debounce(merge: (last: T | undefined, event: T) => T, delay?: number, leading?: boolean, leakWarningThreshold?: number): IChainableEvent; debounce(merge: (last: R | undefined, event: T) => R, delay?: number, leading?: boolean, leakWarningThreshold?: number): IChainableEvent; on(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[] | DisposableStore): IDisposable; once(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[]): IDisposable; } function chain(event: Event$0): IChainableEvent; interface NodeEventEmitter { on(event: string | symbol, listener: Function): this; removeListener(event: string | symbol, listener: Function): this; } function fromNodeEventEmitter(emitter: NodeEventEmitter, eventName: string, map?: (...args: any[]) => T): Event$0; interface DOMEventEmitter { addEventListener(event: string | symbol, listener: Function): void; removeEventListener(event: string | symbol, listener: Function): void; } function fromDOMEventEmitter(emitter: DOMEventEmitter, eventName: string, map?: (...args: any[]) => T): Event$0; function fromPromise(promise: Promise): Event$0; function toPromise(event: Event$0): Promise; } type Listener = [(e: T) => void, any] | ((e: T) => void); interface EmitterOptions { onFirstListenerAdd?: Function; onFirstListenerDidAdd?: Function; onListenerDidAdd?: Function; onLastListenerRemove?: Function; leakWarningThreshold?: number; } declare function setGlobalLeakWarningThreshold(n: number): IDisposable; /** * The Emitter can be used to expose an Event to the public * to fire it from the insides. * Sample: class Document { private readonly _onDidChange = new Emitter<(value:string)=>any>(); public onDidChange = this._onDidChange.event; // getter-style // get onDidChange(): Event<(value:string)=>any> { // return this._onDidChange.event; // } private _doIt() { //... this._onDidChange.fire(value); } } */ declare class Emitter { private static readonly _noop; private readonly _options?; private readonly _leakageMon?; private _disposed; private _event?; private _deliveryQueue?; protected _listeners?: LinkedList>; constructor(options?: EmitterOptions); /** * For the public to allow to subscribe * to events from this Emitter */ get event(): Event$0; /** * To be kept private to fire an event to * subscribers */ /** * To be kept private to fire an event to * subscribers */ fire(event: T): void; dispose(): void; } declare class PauseableEmitter extends Emitter { private _isPaused; private _eventQueue; private _mergeFn?; constructor(options?: EmitterOptions & { merge?: (input: T[]) => T; }); pause(): void; resume(): void; fire(event: T): void; } interface IWaitUntil { waitUntil(thenable: Promise): void; } declare class AsyncEmitter extends Emitter { private _asyncDeliveryQueue?; fireAsync(data: Omit, token: CancellationToken$0, promiseJoin?: (p: Promise, listener: Function) => Promise): Promise; } declare class EventMultiplexer implements IDisposable { private readonly emitter; private hasListeners; private events; constructor(); get event(): Event$0; add(event: Event$0): IDisposable; private onFirstListenerAdd; private onLastListenerRemove; private hook; private unhook; dispose(): void; } /** * The EventBufferer is useful in situations in which you want * to delay firing your events during some code. * You can wrap that code and be sure that the event will not * be fired during that wrap. * * ``` * const emitter: Emitter; * const delayer = new EventDelayer(); * const delayedEvent = delayer.wrapEvent(emitter.event); * * delayedEvent(console.log); * * delayer.bufferEvents(() => { * emitter.fire(); // event will not be fired yet * }); * * // event will only be fired at this point * ``` */ /** * The EventBufferer is useful in situations in which you want * to delay firing your events during some code. * You can wrap that code and be sure that the event will not * be fired during that wrap. * * ``` * const emitter: Emitter; * const delayer = new EventDelayer(); * const delayedEvent = delayer.wrapEvent(emitter.event); * * delayedEvent(console.log); * * delayer.bufferEvents(() => { * emitter.fire(); // event will not be fired yet * }); * * // event will only be fired at this point * ``` */ /** * The EventBufferer is useful in situations in which you want * to delay firing your events during some code. * You can wrap that code and be sure that the event will not * be fired during that wrap. * * ``` * const emitter: Emitter; * const delayer = new EventDelayer(); * const delayedEvent = delayer.wrapEvent(emitter.event); * * delayedEvent(console.log); * * delayer.bufferEvents(() => { * emitter.fire(); // event will not be fired yet * }); * * // event will only be fired at this point * ``` */ declare class EventBufferer { private buffers; wrapEvent(event: Event$0): Event$0; bufferEvents(fn: () => R): R; } /** * A Relay is an event forwarder which functions as a replugabble event pipe. * Once created, you can connect an input event to it and it will simply forward * events from that input event through its own `event` property. The `input` * can be changed at any point in time. */ /** * A Relay is an event forwarder which functions as a replugabble event pipe. * Once created, you can connect an input event to it and it will simply forward * events from that input event through its own `event` property. The `input` * can be changed at any point in time. */ /** * A Relay is an event forwarder which functions as a replugabble event pipe. * Once created, you can connect an input event to it and it will simply forward * events from that input event through its own `event` property. The `input` * can be changed at any point in time. */ declare class Relay implements IDisposable { private listening; private inputEvent; private inputEventListener; private readonly emitter; readonly event: Event$0; set input(event: Event$0); dispose(): void; } declare function isThenable(obj: any): obj is Promise; interface CancelablePromise extends Promise { cancel(): void; } declare function createCancelablePromise(callback: (token: CancellationToken$0) => Promise): CancelablePromise; declare function raceCancellation(promise: Promise, token: CancellationToken$0): Promise; declare function raceCancellation(promise: Promise, token: CancellationToken$0, defaultValue: T): Promise; declare function asPromise(callback: () => T | Thenable): Promise; interface ITask { (): T; } /** * A helper to prevent accumulation of sequential async tasks. * * Imagine a mail man with the sole task of delivering letters. As soon as * a letter submitted for delivery, he drives to the destination, delivers it * and returns to his base. Imagine that during the trip, N more letters were submitted. * When the mail man returns, he picks those N letters and delivers them all in a * single trip. Even though N+1 submissions occurred, only 2 deliveries were made. * * The throttler implements this via the queue() method, by providing it a task * factory. Following the example: * * const throttler = new Throttler(); * const letters = []; * * function deliver() { * const lettersToDeliver = letters; * letters = []; * return makeTheTrip(lettersToDeliver); * } * * function onLetterReceived(l) { * letters.push(l); * throttler.queue(deliver); * } */ /** * A helper to prevent accumulation of sequential async tasks. * * Imagine a mail man with the sole task of delivering letters. As soon as * a letter submitted for delivery, he drives to the destination, delivers it * and returns to his base. Imagine that during the trip, N more letters were submitted. * When the mail man returns, he picks those N letters and delivers them all in a * single trip. Even though N+1 submissions occurred, only 2 deliveries were made. * * The throttler implements this via the queue() method, by providing it a task * factory. Following the example: * * const throttler = new Throttler(); * const letters = []; * * function deliver() { * const lettersToDeliver = letters; * letters = []; * return makeTheTrip(lettersToDeliver); * } * * function onLetterReceived(l) { * letters.push(l); * throttler.queue(deliver); * } */ declare class Throttler { private activePromise; private queuedPromise; private queuedPromiseFactory; constructor(); queue(promiseFactory: ITask>): Promise; } declare class Sequencer { private current; queue(promiseTask: ITask>): Promise; } /** * A helper to delay execution of a task that is being requested often. * * Following the throttler, now imagine the mail man wants to optimize the number of * trips proactively. The trip itself can be long, so he decides not to make the trip * as soon as a letter is submitted. Instead he waits a while, in case more * letters are submitted. After said waiting period, if no letters were submitted, he * decides to make the trip. Imagine that N more letters were submitted after the first * one, all within a short period of time between each other. Even though N+1 * submissions occurred, only 1 delivery was made. * * The delayer offers this behavior via the trigger() method, into which both the task * to be executed and the waiting period (delay) must be passed in as arguments. Following * the example: * * const delayer = new Delayer(WAITING_PERIOD); * const letters = []; * * function letterReceived(l) { * letters.push(l); * delayer.trigger(() => { return makeTheTrip(); }); * } */ /** * A helper to delay execution of a task that is being requested often. * * Following the throttler, now imagine the mail man wants to optimize the number of * trips proactively. The trip itself can be long, so he decides not to make the trip * as soon as a letter is submitted. Instead he waits a while, in case more * letters are submitted. After said waiting period, if no letters were submitted, he * decides to make the trip. Imagine that N more letters were submitted after the first * one, all within a short period of time between each other. Even though N+1 * submissions occurred, only 1 delivery was made. * * The delayer offers this behavior via the trigger() method, into which both the task * to be executed and the waiting period (delay) must be passed in as arguments. Following * the example: * * const delayer = new Delayer(WAITING_PERIOD); * const letters = []; * * function letterReceived(l) { * letters.push(l); * delayer.trigger(() => { return makeTheTrip(); }); * } */ declare class Delayer implements IDisposable { defaultDelay: number; private timeout; private completionPromise; private doResolve; private doReject; private task; constructor(defaultDelay: number); trigger(task: ITask>, delay?: number): Promise; isTriggered(): boolean; cancel(): void; private cancelTimeout; dispose(): void; } /** * A helper to delay execution of a task that is being requested often, while * preventing accumulation of consecutive executions, while the task runs. * * The mail man is clever and waits for a certain amount of time, before going * out to deliver letters. While the mail man is going out, more letters arrive * and can only be delivered once he is back. Once he is back the mail man will * do one more trip to deliver the letters that have accumulated while he was out. */ /** * A helper to delay execution of a task that is being requested often, while * preventing accumulation of consecutive executions, while the task runs. * * The mail man is clever and waits for a certain amount of time, before going * out to deliver letters. While the mail man is going out, more letters arrive * and can only be delivered once he is back. Once he is back the mail man will * do one more trip to deliver the letters that have accumulated while he was out. */ declare class ThrottledDelayer { private delayer; private throttler; constructor(defaultDelay: number); trigger(promiseFactory: ITask>, delay?: number): Promise; isTriggered(): boolean; cancel(): void; dispose(): void; } /** * A barrier that is initially closed and then becomes opened permanently. */ /** * A barrier that is initially closed and then becomes opened permanently. */ declare class Barrier { private _isOpen; private _promise; private _completePromise; constructor(); isOpen(): boolean; open(): void; wait(): Promise; } declare function timeout(millis: number): CancelablePromise; declare function timeout(millis: number, token: CancellationToken$0): Promise; declare function disposableTimeout(handler: () => void, timeout?: number): IDisposable; declare function ignoreErrors(promise: Promise): Promise; /** * Runs the provided list of promise factories in sequential order. The returned * promise will complete to an array of results from each promise. */ /** * Runs the provided list of promise factories in sequential order. The returned * promise will complete to an array of results from each promise. */ declare function sequence(promiseFactories: ITask>[]): Promise; declare function first(promiseFactories: ITask>[], shouldStop?: (t: T) => boolean, defaultValue?: T | null): Promise; /** * A helper to queue N promises and run them all with a max degree of parallelism. The helper * ensures that at any time no more than M promises are running at the same time. */ declare class Limiter { private _size; private runningPromises; private maxDegreeOfParalellism; private outstandingPromises; private readonly _onFinished; constructor(maxDegreeOfParalellism: number); get onFinished(): Event$0; get size(): number; queue(factory: ITask>): Promise; private consume; private consumed; dispose(): void; } /** * A queue is handles one promise at a time and guarantees that at any time only one promise is executing. */ /** * A queue is handles one promise at a time and guarantees that at any time only one promise is executing. */ declare class Queue extends Limiter { constructor(); } /** * A helper to organize queues per resource. The ResourceQueue makes sure to manage queues per resource * by disposing them once the queue is empty. */ /** * A helper to organize queues per resource. The ResourceQueue makes sure to manage queues per resource * by disposing them once the queue is empty. */ /** * A helper to organize queues per resource. The ResourceQueue makes sure to manage queues per resource * by disposing them once the queue is empty. */ declare function retry(task: ITask>, delay: number, retries: number): Promise; //#region Task Sequentializer //#region Task Sequentializer //#region Task Sequentializer //#region Task Sequentializer export { isThenable, CancelablePromise, createCancelablePromise, raceCancellation, asPromise, Throttler, Sequencer, Delayer, ThrottledDelayer, Barrier, timeout, disposableTimeout, ignoreErrors, sequence, first, Limiter, Queue, retry, CancellationToken$0 as CancellationToken, CancellationTokenSource, Event$0 as Event, EmitterOptions, setGlobalLeakWarningThreshold, Emitter, PauseableEmitter, IWaitUntil, AsyncEmitter, EventMultiplexer, EventBufferer, Relay, IDisposable, isDisposable, dispose, combinedDisposable, toDisposable, DisposableStore, Disposable, MutableDisposable, IReference, ReferenceCollection, ImmortalReference };