admin管理员组文章数量:1328037
In short, trying to chunk a really large array into chunks of 10 and wait 5 seconds before emitting the next 10.
Here is what I currently have
Rx.Observable
.from(hugeArray)
.bufferCount(10)
.delay(5000) //want to wait 5 secs
.flatMap(e => e) // this needs to go after to flatten the array, buffer spits out arrays of entries
.flatMap( (data, index) => Rx.Observable.create(observer => {
// going to render stuff here
observer.onNext(data)
observer.onCompleted();
}))
.subscribe(val => console.log('Buffered Values:', val));
Just trying to do 10 chunks ever 5 seconds, only been able to do an initial delay and then it emitted the rest.
In short, trying to chunk a really large array into chunks of 10 and wait 5 seconds before emitting the next 10.
Here is what I currently have
Rx.Observable
.from(hugeArray)
.bufferCount(10)
.delay(5000) //want to wait 5 secs
.flatMap(e => e) // this needs to go after to flatten the array, buffer spits out arrays of entries
.flatMap( (data, index) => Rx.Observable.create(observer => {
// going to render stuff here
observer.onNext(data)
observer.onCompleted();
}))
.subscribe(val => console.log('Buffered Values:', val));
Just trying to do 10 chunks ever 5 seconds, only been able to do an initial delay and then it emitted the rest.
Share Improve this question asked Dec 30, 2016 at 22:31 user240993user2409931 Answer
Reset to default 8Your chain just emitted everything at once and then scheduled each chunk to wait 5s starting at the same time so the delay elapsed for all chunks at the exact same moment.
Solution could be to use concatMap()
that subscribes to each Observable one by one.
Rx.Observable
.from(hugeArray)
.bufferCount(10)
.concatMap(data => Rx.Observable.of(data).delay(5000))
.flatMap(e => e) // or mergeAll() or concatAll()
.flatMap( (data, index) => Rx.Observable.create(observer => {
// going to render stuff here
observer.onNext(data);
observer.onCompleted();
}))
.subscribe(val => console.log('Buffered Values:', val));
本文标签: javascriptRxjs Chunk and delay streamStack Overflow
版权声明:本文标题:javascript - Rxjs: Chunk and delay stream? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742242503a2438920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论