Skip to content

Commit d330a32

Browse files
authored
improves BaseDuplexConnection and fixes PingClient impl (#1062)
1 parent 1fe2d64 commit d330a32

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

rsocket-core/src/main/java/io/rsocket/internal/BaseDuplexConnection.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
import reactor.core.publisher.Sinks;
2323

2424
public abstract class BaseDuplexConnection implements DuplexConnection {
25-
protected Sinks.Empty<Void> onClose = Sinks.empty();
25+
protected final Sinks.Empty<Void> onClose = Sinks.empty();
26+
protected final UnboundedProcessor sender = new UnboundedProcessor(onClose::tryEmitEmpty);
2627

27-
protected UnboundedProcessor sender = new UnboundedProcessor();
28-
29-
public BaseDuplexConnection() {
30-
onClose().doFinally(s -> doOnClose()).subscribe();
31-
}
28+
public BaseDuplexConnection() {}
3229

3330
@Override
3431
public void sendFrame(int streamId, ByteBuf frame) {
@@ -48,7 +45,7 @@ public final Mono<Void> onClose() {
4845

4946
@Override
5047
public final void dispose() {
51-
onClose.tryEmitEmpty();
48+
doOnClose();
5249
}
5350

5451
@Override

rsocket-test/src/main/java/io/rsocket/test/PingClient.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ Flux<Payload> pingPong(
6363
BiFunction<RSocket, ? super Payload, ? extends Publisher<Payload>> interaction,
6464
int count,
6565
final Recorder histogram) {
66-
return client
67-
.flatMapMany(
66+
return Flux.usingWhen(
67+
client,
6868
rsocket ->
6969
Flux.range(1, count)
7070
.flatMap(
@@ -78,7 +78,11 @@ Flux<Payload> pingPong(
7878
histogram.recordValue(diff);
7979
});
8080
},
81-
64))
81+
64),
82+
rsocket -> {
83+
rsocket.dispose();
84+
return rsocket.onClose();
85+
})
8286
.doOnError(Throwable::printStackTrace);
8387
}
8488
}

0 commit comments

Comments
 (0)