#723·EventBus

eventQueue in PostingThreadState is necessary?

Author: CliffLeopardCreated Jan 6, 2024Updated Jan 6, 2024
    public void post(Object event) {
        PostingThreadState postingState = currentPostingThreadState.get();
        List<Object> eventQueue = postingState.eventQueue;
        eventQueue.add(event);

        if (!postingState.isPosting) {
            postingState.isMainThread = isMainThread();
            postingState.isPosting = true;
            if (postingState.canceled) {
                throw new EventBusException("Internal error. Abort state was not reset");
            }
            try {
                while (!eventQueue.isEmpty()) {
                    postSingleEvent(eventQueue.remove(0), postingState);
                }
            } finally {
                postingState.isPosting = false;
                postingState.isMainThread = false;
            }
        }
    }
  • When one thread run post method , postingState while always be false, Is there any example can show the case that postState be false? eventQueue size while never more than one, so Why eventQueue is necessary?