# API `@deepkit/core-rxjs`

```shell
npm install @deepkit/core-rxjs
```

## API reference of @deepkit/core-rxjs

### watchClosed (function)

```typescript
(observer: Observer<any>): { closed: boolean; }
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L31

### isSubject (function)

```typescript
(v: any): v is Subject<any>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L47

### isBehaviorSubject (function)

```typescript
(v: any): v is BehaviorSubject<any>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L51

### subscriptionToPromise (function)

```typescript
<T>(subscription: Subscription): Promise<void>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L97

### nextValue (function)

```typescript
<T>(o: Observable<T>): Promise<T>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L105

### observableToPromise (function)

```typescript
<T>(o: Observable<T>, next?: (data: T) => void): Promise<T>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L113

### promiseToObservable (function)

```typescript
<T>(o: () => Promise<T>): Observable<T>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L131

### tearDown (function)

```typescript
(teardown: TeardownLogic): Promise<void>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L148

### throttleMessages (function)

Handles incoming messages in batches. The handler is called when the observable completes or when a certain time passed since the last message.

This makes sure the handler is awaited before the next batch is processed.

`maxWait` in milliseconds, this makes sure every `maxWait` ms the handler is called with the current messages if there are any.
`batchSize` this is the maximum amount of messages that are passed to the handler.

```typescript
<T, R>(observable: Observable<T>, handler: (messages: T[]) => Promise<R>, options?: Partial<{ maxWait: number; batchSize: number; }>): Promise<R[]>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L164

### decoupleSubject (function)

Clone a given subject (BehaviourSubject or ProgressTracker or Subject) and decouple it from the source,
so that when the new object is completed or errored, the source is not affected.

This is handy if you want to hand out a subject to a consumer, but you don't want the consumer to be
able to complete or error the subject, which is usually requires for RPC controllers.

```typescript
<T extends Observable<any> | undefined>(observable: T): T
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L225

### AsyncSubscription (class)

```typescript
export class AsyncSubscription {
    constructor(private cb: () => Promise<void>);
    async unsubscribe(): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L16

### Subscriptions (class)

RXJS subscription collection, to easily collect multiple subscriptions and unsubscribe all at once.
Added subscriptions are automatically removed when they get unsubscribed.

```typescript
export class Subscriptions {
    readonly list: Subscription[];
    constructor(protected teardown?: () => void | Promise<void>);
    unsubscribe();
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/utils.ts#L69

### ObserverTimer (class)

Allows to create Timer which is deactivated automatically
when the observer is stopped.

```typescript
export class ObserverTimer extends Timer {
    constructor(protected observer: Observer<any>);
    setTimeout(cb: () => void, timeout: number): any;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/timer.ts#L19

### watchProgressTracker (function)

Turns a ProgressTracker into a BehaviorSubject<ProgressTracker> aka ProgressTrackerWatcher.

```typescript
<T extends ProgressTracker>(tracker: T): ProgressTrackerWatcher<T>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/progress.ts#L241

### ProgressTrackerState (type)

```typescript
interface ProgressTrackerState {
    total: number;
    done: number;
    message: string;
    speed: number;
    stopped: boolean;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/progress.ts#L4

### ProgressTrackerGroup (class)

```typescript
export class ProgressTrackerGroup {
    stopCallbacks: (() => void)[];
    constructor(public state: ProgressTrackerState);
    changed();
    /**
     * Registers a callback that is called when the progress is stopped.
     */
    onStop(callback: () => void);
    stop();
    /**
     * Number between 0 and 1.
     */
    get progress(): number;
    /**
     * Total number of items to process.
     */
    get total(): number;
    /**
     * True if the progress is finished (done === total).
     * Same as progress === 1.
     */
    get finished();
    /**
     * True if the progress is running (finished === false && stopped === false).
     */
    get running();
    /**
     * True if the progress is ended (finished === true || stopped === true).
     */
    get ended();
    /**
     * True if the progress is stopped (stopped === true), but might not be finished.
     */
    get stopped();
    get message(): string;
    get done(): number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/progress.ts#L12

### ProgressTracker (class)

This class allows to track multiple progress states.

Natively supported as return type in

```typescript
export class ProgressTracker extends BehaviorSubject<ProgressTrackerState[]> {
    groups: ProgressTrackerGroup[];
    changed;
    constructor(states: ProgressTrackerState[] = []);
    next(states: ProgressTrackerState[]);
    stop();
    track(message: string = , total: number, current: number = ): ProgressTrackerGroup;
    get progress(): number;
    /**
     * True if the progress is finished (done === total).
     * Same as progress === 1.
     */
    get finished(): boolean;
    /**
     * True if the progress is running (finished === false && stopped === false).
     */
    get running(): boolean;
    /**
     * True if the progress is ended (finished === true || stopped === true).
     */
    get ended(): boolean;
    /**
     * True if the progress is stopped (stopped === true), but might not be finished.
     */
    get stopped();
    get done(): number;
    get total(): number;
    get current(): ProgressTrackerGroup | undefined;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/progress.ts#L132

### ProgressTrackerWatcher (class)

```typescript
export class ProgressTrackerWatcher<T extends ProgressTracker = ProgressTracker> extends BehaviorSubject<T> {
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/core-rxjs/src/progress.ts#L235
