當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.interval方法代碼示例

本文整理匯總了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);
});
開發者ID:LongLiveCHIEF,項目名稱:aim,代碼行數:9,代碼來源:stock_server.ts

示例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));
開發者ID:taochunyu,項目名稱:learn,代碼行數:6,代碼來源:concat.ts

示例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));

開發者ID:taochunyu,項目名稱:learn,代碼行數:19,代碼來源:buffer.ts

示例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));
開發者ID:chun4foryou,項目名稱:develop,代碼行數:8,代碼來源:take.ts

示例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 () => {
  
};
開發者ID:taochunyu,項目名稱:learn,代碼行數:13,代碼來源:delay2.ts

示例6:

const result$ = interval$.concatMap(x => Observable.interval(1000).take(4));
開發者ID:taochunyu,項目名稱:learn,代碼行數:1,代碼來源:concatMap.ts

示例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)
})
開發者ID:taochunyu,項目名稱:learn,代碼行數:17,代碼來源:combe.ts


注:本文中的@reactivex/rxjs.Observable.interval方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。