我有一个像RxJava Subject with Backpressure - only let the last value emit once downstream has finished consuming这样的问题,但我希望所有发出的项目(所有缓冲项目的列表)在下游忙于消费时
public static void main(String[] args) throws Exception {
Subject<Boolean> loadingQueue =
PublishSubject.<Boolean>create().toSerialized();
loadingQueue
.toFlowable(BackpressureStrategy.BUFFER)
.delay(0, TimeUnit.MILLISECONDS, Schedulers.single()) // <-------
.map(discarded -> {
// PRE-LOADING
System.out.println("PRE-LOADING: "
+ Thread.currentThread().getName());
return discarded;
})
.delay(0, TimeUnit.MILLISECONDS, Schedulers.computation()) // <-------
.map(b -> {
System.out.println("LOADING: "
+ Thread.currentThread().getName());
Thread.sleep(2000);
return b;
})
.delay(0, TimeUnit.MILLISECONDS, Schedulers.single()) // <-------
.rebatchRequests(1) // <----------------------------------- one-by-one
.subscribe(b -> {
System.out.println("FINISHED: "
+ Thread.currentThread().getName() + "\n\n");
});
loadingQueue.onNext(true);
loadingQueue.onNext(true);
loadingQueue.onNext(true);
Thread.sleep(10000);
}
它工作但不是一个接一个地获取项目我想一次列出所有缓冲项目而下游忙我想创建另一个列表等等
答案 0 :(得分:0)
我终于找到了一种方法来实现在某些事件发生时以列表形式发出的项目并启动另一个列表直到其他事件发生
// retrieves a non-live NodeList of all elements with any
// of the specified class-names:
var allClasses = document.querySelectorAll('ps-scrollbar-x-rail, ps-scrollbar-y-rail, ps-scrollbar-x');
// uses Array.from() to convert the Array-like NodeList
// into an Array:
Array.from( allClasses )
// upon which we can use Array.prototype.forEach():
.forEach(
// using an Arrow function to call
// Element.removeAttribute() on
// each element in turn; 'el' is
// the current element in the Array
// of elements:
el => el.removeAttribute('style')
);