Skip to content

Commit 55cdbf7

Browse files
committed
Remove nested subscription from within Mono.
1 parent 96da0b8 commit 55cdbf7

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/BatchCursorPublisher.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,17 @@ public TimeoutMode getTimeoutMode() {
123123

124124
public Publisher<T> first() {
125125
return batchCursor(this::asAsyncFirstReadOperation)
126-
.flatMap(batchCursor -> Mono.create(sink -> {
126+
.flatMap(batchCursor -> {
127127
batchCursor.setBatchSize(1);
128-
Mono.from(batchCursor.next())
128+
return Mono.from(batchCursor.next())
129129
.doOnTerminate(batchCursor::close)
130-
.doOnError(sink::error)
131-
.doOnSuccess(results -> {
130+
.flatMap(results -> {
132131
if (results == null || results.isEmpty()) {
133-
sink.success();
134-
} else {
135-
sink.success(results.get(0));
132+
return Mono.empty();
136133
}
137-
})
138-
.contextWrite(sink.contextView())
139-
.subscribe();
140-
}));
134+
return Mono.fromCallable(() -> results.get(0));
135+
});
136+
});
141137
}
142138

143139
@Override

0 commit comments

Comments
 (0)