为什么在Rx.js中传递给interval的Infinity不会永远等待?
Why does Infinity passed to interval does not wait forever in Rx.js?
谁能解释一下为什么下面的代码段立即输出数字0到6 ?
Rx.Observable.interval(1/0).take(6).forEach(x => console.log(x));
输出:0 1 2 3 4 5
您可以从RxJS的源代码中看到,Observable.interval
期望(并使用)其输入为整数:
module Rx {
export interface ObservableStatic {
/**
* Returns an observable sequence that produces a value after each period.
*
* @example
* 1 - res = Rx.Observable.interval(1000);
* 2 - res = Rx.Observable.interval(1000, Rx.Scheduler.timeout);
*
* @param {Number} period Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds).
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, Rx.Scheduler.timeout is used.
* @returns {Observable} An observable sequence that produces a value after each period.
*/
interval(period: number, scheduler?: IScheduler): Observable<number>;
}
}
和Javascript中的
(1/0) === Infinity
和Infinity
转换为整数时为零:
(Infinity | 0) === 0
相关文章:
- 单击按钮以等待单击按钮
- React组件等待所需道具进行渲染
- 正在等待呈现图表,直到加载数据为止
- 在等待ajax请求时显示微调器并禁用页面
- Javascript在for循环中等待处理请求
- JavaScript循环并等待函数
- 在等待异步任务时永久循环
- 在通过child.print()打印之前,我如何等待图像加载到我的新窗口中
- 成功回调永远不会被JSONP请求调用
- 失败:等待Protractor与页面同步时出错:“”;在窗口上找不到角度”;
- 等待300毫秒,然后使用jQuery向下滑动菜单
- 等待循环调用的所有承诺完成
- 等待回调函数执行
- RxJS等待承诺解决
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- 永远不要停止gif预加载程序
- Casperjs等待资源
- draggableCursor没有't更改为等待光标
- 如何使请求等待上一个请求完成
- 为什么在Rx.js中传递给interval的Infinity不会永远等待?