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