observableTimer.ts 847 Bytes
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Deshui Yu's avatar
Deshui Yu committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

'use strict';

import * as rx from 'rx';
import * as component from '../common/component';

@component.Singleton
class ObservableTimer {
    private observableSource: rx.Observable<number>;
    constructor() {
        // TODO: move 100 and 1000 into constants class
        this.observableSource = rx.Observable.timer(100, 1000).takeWhile(() => true);
    }

    public subscribe(onNext?: (value: any) => void, onError?: (exception: any) => void, onCompleted?: () => void): Rx.IDisposable {
        return this.observableSource.subscribe(onNext, onError, onCompleted);
    }

chicm-ms's avatar
chicm-ms committed
21
    public unsubscribe( subscription: Rx.IDisposable): void {
22
        if(typeof subscription !== 'undefined') {
Deshui Yu's avatar
Deshui Yu committed
23
24
25
26
27
28
            subscription.dispose();
        }
    }
}

export { ObservableTimer };