EventBus 黏性事件的postSticky

EventBus 黏性事件的postSticky

    /**
     * Posts the given event to the event bus and holds on to the event (because it is sticky). The most recent sticky
     * event of an event's type is kept in memory for future access by subscribers using {@link Subscribe#sticky()}.
     */
    public void postSticky(Object event) {
        synchronized (stickyEvents) {
            stickyEvents.put(event.getClass(), event);
        }
        // Should be posted after it is putted, in case the subscriber wants to remove immediately
        post(event);
    }

将事件类型添加到stickyEvents中,是一个Map,Key是事件类型,Value是事件对象;

然后调用post方法;对已经注册过得方法发送订阅事件;

这里我有一点疑惑,就是这个注释:

// Should be posted after it is putted, in case the subscriber wants to remove immediately

翻译过来就是:在put到stickyEvents之后应该立即post出去,防止订阅者想要立刻移除事件;

没明白是什么意思…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值