Skip to content

Probably dispatch method should be reused inside emit #6086

@doxlik

Description

@doxlik

Describe the feature

Currently emit method looks like

  @Override
  public final <T> void emit(T argument, Handler<T> task) {
    if (executor().inThread()) {
      ContextInternal prev = beginDispatch();
      try {
        task.handle(argument);
      } catch (Throwable t) {
        reportException(t);
      } finally {
        endDispatch(prev);
      }
    } else {
      executor().execute(() -> emit(argument, task));
    }
  }

while dispatch is

  default <E> void dispatch(E event, Handler<E> handler) {
    ContextInternal prev = beginDispatch();
    try {
      handler.handle(event);
    } catch (Throwable t) {
      reportException(t);
    } finally {
      endDispatch(prev);
    }
  }

so it is effective duplicate logic of dispatch in the "if (executor().inThread())" branch.

Contribution

here is PR #6085

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions