javascript - Why does Infinity passed to interval does not wait forever in Rx.js? -
can please explain me why following snippet outputs digits 0 6 ?
rx.observable.interval(1/0).take(6).foreach(x => console.log(x));
output: 0 1 2 3 4 5
you can see the source code of rxjs observable.interval
expects (and uses) input integer:
module rx { export interface observablestatic { /** * returns observable sequence produces value after each period. * * @example * 1 - res = rx.observable.interval(1000); * 2 - res = rx.observable.interval(1000, rx.scheduler.timeout); * * @param {number} period period producing values in resulting sequence (specified integer denoting milliseconds). * @param {scheduler} [scheduler] scheduler run timer on. if not specified, rx.scheduler.timeout used. * @returns {observable} observable sequence produces value after each period. */ interval(period: number, scheduler?: ischeduler): observable<number>; } }
and since in javascript
(1/0) === infinity
and infinity
0 when turned integer:
(infinity | 0) === 0
Comments
Post a Comment