UNPKG

1.95 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17export declare type NextFn<T> = (value: T) => void;
18export declare type ErrorFn = (error: Error) => void;
19export declare type CompleteFn = () => void;
20export interface Observer<T> {
21 next: NextFn<T>;
22 error: ErrorFn;
23 complete: CompleteFn;
24}
25export declare type PartialObserver<T> = Partial<Observer<T>>;
26export declare type Unsubscribe = () => void;
27/**
28 * The Subscribe interface has two forms - passing the inline function
29 * callbacks, or a object interface with callback properties.
30 */
31export interface Subscribe<T> {
32 (next?: NextFn<T>, error?: ErrorFn, complete?: CompleteFn): Unsubscribe;
33 (observer: PartialObserver<T>): Unsubscribe;
34}
35export interface Observable<T> {
36 subscribe: Subscribe<T>;
37}
38export declare type Executor<T> = (observer: Observer<T>) => void;
39/**
40 * Helper to make a Subscribe function (just like Promise helps make a
41 * Thenable).
42 *
43 * @param executor Function which can make calls to a single Observer
44 * as a proxy.
45 * @param onNoObservers Callback when count of Observers goes to zero.
46 */
47export declare function createSubscribe<T>(executor: Executor<T>, onNoObservers?: Executor<T>): Subscribe<T>;
48/** Turn synchronous function into one called asynchronously. */
49export declare function async(fn: Function, onError?: ErrorFn): Function;