admin
2024-07-03 a40e0e51331e5e6f69e8bed5940512b29150c7a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.taoke.autopay.android;
 
import com.jakewharton.rxrelay3.PublishRelay;
import com.jakewharton.rxrelay3.Relay;
 
import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
 
/**
 * courtesy: <a href="https://gist.github.com/benjchristensen/04eef9ca0851f3a5d7bf">...</a>
 */
public class RxBus {
 
    private final Relay<Object> _bus = PublishRelay.create().toSerialized();
 
    private static final class Holder {
        static final RxBus INSTANCE = new RxBus();
    }
 
    public static RxBus getInstance() {
        return Holder.INSTANCE;
    }
 
    public void send(Object o) {
        _bus.accept(o);
    }
 
    public Flowable<Object> asFlowable() {
        return _bus.toFlowable(BackpressureStrategy.LATEST);
    }
 
    public boolean hasObservers() {
        return _bus.hasObservers();
    }
}