2016-12-07 74 views

回答

3

不是直接的,你需要捕獲用戶和消除:

PublishProcessor<?> pp = ... 

AtomicInteger counter = new AtomicInteger(); 

Action onFirst = ... 

Action onLast = ... 

Flowable<?> f = pp.doOnSubscribe(s -> { 
    if (counter.getAndIncrement() == 0) { 
     onFirst.run(); 
    } 
}) 
.doFinally(() -> { 
    if (counter.decrementAndGet() == 0) { 
     onLast.run(); 
    } 
}) 

// use f for subscribe() instead of pp