Rx.Observable.generateWithAbsoluteTime(initialState, condition, iterate, resultSelector, timeSelector, [scheduler])
生成一个带绝对时间控制的Observable,通过迭代一个初始值,直到判定条件返回false.
参数
initialState
(Any
): 初始值.condition
(Function
): 生成判定条件的函数(返回false时终止循环)iterate
(Function
): 迭代函数resultSelector
(Function
): 处理迭代函数的值,返回最终结果timeSelector
(Function
): 间隔时间函数,控制每次迭代产生的值的速度,返回一个未来的时间戳(绝对时间值)。[scheduler=Rx.Scheduler.timeout]
(Scheduler
): generator循环的调度器,如果没有提供,默认为Scheduler.timeout
.
返回值
(Observable
): Observable.
例
// Generate a value with an absolute time with an offset of 100ms multipled by value
var source = Rx.Observable.generateWithAbsoluteTime(
1,
function (x) { return x < 4; },
function (x) { return x + 1; },
function (x) { return x; },
function (x) { return Date.now() + (100 * x); }
).timeInterval();
var subscription = source.subscribe(
function (x) {
console.log('Next: ', x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: {value: 1, interval: 100}
// => Next: {value: 2, interval: 200}
// => Next: {value: 3, interval: 300}
// => Completed