@@ -53,8 +53,7 @@ public suspend fun <T> Mono<T>.awaitSingleOrNull(): T? = suspendCancellableCorou
53
53
}
54
54
55
55
override fun onComplete () {
56
- if (! seenValue)
57
- cont.resume(null )
56
+ if (! seenValue) cont.resume(null )
58
57
}
59
58
60
59
override fun onNext (t : T ) {
@@ -136,87 +135,66 @@ public fun <T> CoroutineScope.mono(
136
135
): Mono <T > = monoInternal(this , context, block)
137
136
138
137
/* *
139
- * Awaits the first value from the given publisher without blocking the thread and returns the resulting value, or, if
140
- * the publisher has produced an error, throws the corresponding exception.
141
- *
142
- * This suspending function is cancellable.
143
- * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
144
- * function immediately cancels its [Subscription] and resumes with [CancellationException].
145
- *
146
- * @throws NoSuchElementException if the publisher does not emit any value
138
+ * This function is deprecated in favor of [Mono.awaitSingle].
139
+ * Both functions await the first value, or throw [NoSuchElementException] if there is none, but the name
140
+ * [Mono.awaitSingle] better reflects the semantics of [Mono].
147
141
*/
148
142
@Deprecated(
149
143
message = " Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
150
144
" Please use awaitSingle() instead." ,
151
145
level = DeprecationLevel .WARNING ,
152
146
replaceWith = ReplaceWith (" this.awaitSingle()" )
153
- )
147
+ ) // Warning since 1.5, error in 1.6, hidden in 1.7
154
148
public suspend fun <T > Mono<T>.awaitFirst (): T = awaitSingle()
155
149
156
150
/* *
157
- * Awaits the first value from the given publisher, or returns the [default] value if none is emitted, without blocking
158
- * the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding
159
- * exception.
160
- *
161
- * This suspending function is cancellable.
162
- * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
163
- * function immediately cancels its [Subscription] and resumes with [CancellationException].
151
+ * This function is deprecated in favor of [Mono.awaitSingleOrNull].
152
+ * Both functions await the first value or return some special value if there is none, but the name
153
+ * [Mono.awaitSingleOrNull] better reflects the semantics of [Mono] than an operation with a "first" in its name.
164
154
*/
165
155
@Deprecated(
166
156
message = " Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
167
157
" Please use awaitSingleOrNull() instead." ,
168
158
level = DeprecationLevel .WARNING ,
169
159
replaceWith = ReplaceWith (" this.awaitSingleOrNull() ?: default" )
170
- )
160
+ ) // Warning since 1.5, error in 1.6, hidden in 1.7
171
161
public suspend fun <T > Mono<T>.awaitFirstOrDefault (default : T ): T = awaitSingleOrNull() ? : default
172
162
173
163
/* *
174
- * Awaits the first value from the given publisher, or returns `null` if none is emitted, without blocking the thread,
175
- * and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.
176
- *
177
- * This suspending function is cancellable.
178
- * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
179
- * function immediately cancels its [Subscription] and resumes with [CancellationException].
164
+ * This function is deprecated in favor of [Mono.awaitSingleOrNull].
165
+ * Both functions await the first value or return some special value if there is none, but the name
166
+ * [Mono.awaitSingleOrNull] better reflects the semantics of [Mono].
180
167
*/
181
168
@Deprecated(
182
169
message = " Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
183
170
" Please use awaitSingleOrNull() instead." ,
184
171
level = DeprecationLevel .WARNING ,
185
172
replaceWith = ReplaceWith (" this.awaitSingleOrNull()" )
186
- )
173
+ ) // Warning since 1.5, error in 1.6, hidden in 1.7
187
174
public suspend fun <T > Mono<T>.awaitFirstOrNull (): T ? = awaitSingleOrNull()
188
175
189
176
/* *
190
- * Awaits the first value from the given publisher, or calls [defaultValue] to get a value if none is emitted, without
191
- * blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the
192
- * corresponding exception.
193
- *
194
- * This suspending function is cancellable.
195
- * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
196
- * function immediately cancels its [Subscription] and resumes with [CancellationException].
177
+ * This function is deprecated in favor of [Mono.awaitSingleOrNull].
178
+ * Both functions await the first value or return some special value if there is none, but the name
179
+ * [Mono.awaitSingleOrNull] better reflects the semantics of [Mono] than an operation with a "first" in its name.
197
180
*/
198
181
@Deprecated(
199
182
message = " Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
200
183
" Please use awaitSingleOrNull() instead." ,
201
184
level = DeprecationLevel .WARNING ,
202
185
replaceWith = ReplaceWith (" this.awaitSingleOrNull() ?: defaultValue()" )
203
- )
186
+ ) // Warning since 1.5, error in 1.6, hidden in 1.7
204
187
public suspend fun <T > Mono<T>.awaitFirstOrElse (defaultValue : () -> T ): T = awaitSingleOrNull() ? : defaultValue()
205
188
206
189
/* *
207
- * Awaits the last value from the given publisher without blocking the thread and
208
- * returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.
209
- *
210
- * This suspending function is cancellable.
211
- * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
212
- * function immediately cancels its [Subscription] and resumes with [CancellationException].
213
- *
214
- * @throws NoSuchElementException if the publisher does not emit any value
190
+ * This function is deprecated in favor of [Mono.awaitSingle].
191
+ * Both functions await the only value or return some special value if there is none, but the name
192
+ * "awaitLast" strongly suggests that there is more than one value, which is not the case.
215
193
*/
216
194
@Deprecated(
217
195
message = " Mono produces at most one value, so the last element is the same as the first. " +
218
196
" Please use awaitSingle() instead." ,
219
197
level = DeprecationLevel .WARNING ,
220
198
replaceWith = ReplaceWith (" this.awaitSingle()" )
221
- )
199
+ ) // Warning since 1.5, error in 1.6, hidden in 1.7
222
200
public suspend fun <T > Mono<T>.awaitLast (): T = awaitSingle()
0 commit comments