package com.sheep.gamegroup.model.util;

import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;
import rx.subjects.Subject;

/**
 * 广播发送
 * Created by ljy on 2018/3/23.
 */

public class RxBus {
    private static volatile RxBus rxBus;

    private final Subject<Object,Object> bus;

    public RxBus() {
        bus = new SerializedSubject<>(PublishSubject.create());
    }

    public static RxBus getDefault(){
        if (rxBus == null){
            synchronized (RxBus.class){
                if (rxBus == null){
                    rxBus = new RxBus();
                }
            }
        }
        return rxBus;
    }

    /**
     * 发送一个事件
     */
    public void post(Object o){
        bus.onNext(o);
    }
}
