@Test public void shouldForwardMessagesToConsumer() throws Exception { new MessageDispatcher<String>(WorkRunners.immediate(), messages::add).accept("hey hello"); assertThat(messages).containsExactly("hey hello"); }
@Override public void accept(final M message) { if (disposed) { return; } runner.post( () -> { try { consumer.accept(message); } catch (Throwable throwable) { MobiusHooks.handleError( new RuntimeException( "Consumer threw an exception when accepting message: " + message, throwable)); } }); }
MessageDispatcher implements Consumer<M>, Disposable { @Override public void accept(final M message) { if (disposed) { return; } runner.post( () -> { try { consumer.accept(message); } catch (Throwable throwable) { MobiusHooks.handleError( new RuntimeException( "Consumer threw an exception when accepting message: " + message, throwable)); } }); } }
MessageDispatcher implements Consumer<M>, Disposable { @Override public void accept(final M message) { if (disposed) { return; } runner.post( () -> { try { consumer.accept(message); } catch (Throwable throwable) { MobiusHooks.handleError( new RuntimeException( "Consumer threw an exception when accepting message: " + message, throwable)); } }); } MessageDispatcher(WorkRunner runner, Consumer<M> consumer); }
MessageDispatcher implements Consumer<M>, Disposable { @Override public void accept(final M message) { if (disposed) { return; } runner.post( () -> { try { consumer.accept(message); } catch (Throwable throwable) { MobiusHooks.handleError( new RuntimeException( "Consumer threw an exception when accepting message: " + message, throwable)); } }); } MessageDispatcher(WorkRunner runner, Consumer<M> consumer); @Override void accept(final M message); @Override void dispose(); }
MessageDispatcher implements Consumer<M>, Disposable { @Override public void accept(final M message) { if (disposed) { return; } runner.post( () -> { try { consumer.accept(message); } catch (Throwable throwable) { MobiusHooks.handleError( new RuntimeException( "Consumer threw an exception when accepting message: " + message, throwable)); } }); } MessageDispatcher(WorkRunner runner, Consumer<M> consumer); @Override void accept(final M message); @Override void dispose();  }