Skip to content

Commit

Permalink
Can attempt message send without subscribers
Browse files Browse the repository at this point in the history
- Change state assert not to throw if we're in state
  where message would never get consumed. Now
  just returning false.
- Fixes #1002
  • Loading branch information
jvalkeal committed Feb 15, 2024
1 parent a13109d commit 27c2717
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,7 +45,6 @@
import org.springframework.shell.component.view.control.ViewEvent;
import org.springframework.shell.component.view.event.processor.AnimationEventLoopProcessor;
import org.springframework.shell.component.view.event.processor.TaskEventLoopProcessor;
import org.springframework.util.Assert;

/**
* Default implementation of an {@link EventLoop}.
Expand Down Expand Up @@ -202,8 +201,11 @@ public void onDestroy(Disposable disposable) {
// }

private boolean doSend(Message<?> message, long timeout) {
Assert.state(this.active && this.many.currentSubscriberCount() > 0,
() -> "The [" + this + "] doesn't have subscribers to accept messages");
if (!this.active || this.many.currentSubscriberCount() == 0) {
return false;
}
// Assert.state(this.active && this.many.currentSubscriberCount() > 0,
// () -> "The [" + this + "] doesn't have subscribers to accept messages");
long remainingTime = 0;
if (timeout > 0) {
remainingTime = timeout;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -120,6 +120,15 @@ void canDispatchMono() {
verifier1.verify(Duration.ofSeconds(1));
}


@Test
void dispatchNoSubscribersDoesNotError() {
initDefault();
Message<String> message = MessageBuilder.withPayload("TEST").build();

loop.dispatch(message);
}

@Test
void subsribtionCompletesWhenLoopDestroyed() {
initDefault();
Expand Down

0 comments on commit 27c2717

Please sign in to comment.