当前位置: 首页>>代码示例>>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;未经允许,请勿转载。