本文整理汇总了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)
})