本文整理匯總了TypeScript中@reactivex/rxjs.Observable.interval方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.interval方法的具體用法?TypeScript Observable.interval怎麽用?TypeScript Observable.interval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@reactivex/rxjs.Observable
的用法示例。
在下文中一共展示了Observable.interval方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
subs.subscribe(({connection, message:{symbol}}:any) => {
const source = Observable.interval(500).map(() => ({
symbol,
price: Math.random() * 100,
timestamp: Date.now()
}));
connection.streams = connection.streams || {};
connection.streams[symbol] = source.subscribe(connection);
});
示例2:
import { Observable } from '@reactivex/rxjs';
var timer = Observable.interval(1000).take(4);
var sequence = Observable.range(1, 10).publish();
var result = timer.concat(sequence);
result.subscribe(x => console.log(x));
示例3: Promise
import { Observable } from '@reactivex/rxjs';
/*
var clicks = Observable.interval(1000);
var interval = Observable.interval(200);
var buffered = interval.buffer(clicks);
buffered.subscribe(x => console.log(x));
*/
/*
var clicks = Observable.interval(200);
var buffered = clicks.bufferWhen(() =>
Observable.interval(1000)
);
buffered.subscribe(x => console.log(x));
*/
let update$ = Observable.interval(200);
let init$ = Observable.fromPromise(new Promise((resolve, reject) => resolve('hi')));
update$.bufferWhen(() => init$)
.subscribe(x => console.log(x));
示例4:
/**
* @author happygrammer
*/
import * as Rx from "@reactivex/rxjs";
const interval = Rx.Observable.interval(100);
const take$ = interval.take(3);
take$.subscribe(val => console.log(val));
示例5: Subject
import { Observable, Subject } from '@reactivex/rxjs';
const reducer = (state, payload) => state + payload;
const action$ = Observable.interval(1000);
action$.scan(reducer).startWith('');
const start$ = new Subject();
const start = async () => {
};
示例6:
const result$ = interval$.concatMap(x => Observable.interval(1000).take(4));
示例7:
import { Observable } from '@reactivex/rxjs'
/*
A ------> |
B ------> | -> E
C -> D -> |
*/
const A$ = Observable.interval(1000)
const B$ = Observable.of(3)
const C$ = Observable.from([5, 6, 7])
const D$ = C$.toArray().map(arr => arr.reduce((acc, val) => acc + val, 0))
const E$ = Observable.combineLatest(A$, B$, D$).map(arr => arr.reduce((acc, val) => acc + val, 0))
E$.subscribe(observer => {
console.log(observer)
})