1
從rxjs網站油門例如,如何獲得rxjs中的限制值?
所發射的序列是0 4 2 1 3
輸出序列是0 1.(由於4,2和1滴)
var Rx = require('rxjs/Rx');
var times = [
{ value: 0, time: 100 },
{ value: 1, time: 600 },
{ value: 2, time: 400 },
{ value: 3, time: 900 },
{ value: 4, time: 200 }
];
// Delay each item by time and project value;
var source = Rx.Observable.from(times)
.flatMap(function (item) {
return Rx.Observable
.of(item.value)
.delay(item.time);
})
.throttleTime(300 /* ms */);
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function() {
console.log('Completed');
});
控制檯將輸出
Next: 0 (at 100ms) // The value 4 was dropped(at 200ms)
// The value 2 was dropped(at 400ms)
Next: 1 (at 600ms)
// The value 3 was dropped(at 900ms)
Completed
但是,是否有可能得到下降的價值流?
Next: 4 (at 200ms)
Next: 2 (at 400ms)
Next: 3 (at 900ms)
Completed
你想要什麼?爲什麼4先然後1?我在這裏沒有看到任何邏輯 – Maxime
值4將在200ms發射 值1將在600ms發射 因此,值4會先於1 –
我的不好我累了我以爲它是有序的和時間只增加... :) – Maxime