Skip to content

Commit df68c22

Browse files
committed
Clarify the docs
1 parent 797c2d5 commit df68c22

File tree

1 file changed

+65
-20
lines changed
  • reactive/kotlinx-coroutines-reactor/src

1 file changed

+65
-20
lines changed

reactive/kotlinx-coroutines-reactor/src/Mono.kt

+65-20
Original file line numberDiff line numberDiff line change
@@ -136,66 +136,111 @@ public fun <T> CoroutineScope.mono(
136136
): Mono<T> = monoInternal(this, context, block)
137137

138138
/**
139-
* This function is deprecated in favor of [Mono.awaitSingle].
140-
* Both functions await the first value, or throw [NoSuchElementException] if there is none, but the name
141-
* [Mono.awaitSingle] better reflects the semantics of [Mono].
139+
* This is a lint function that was added already deprecated in order to guard against confusing usages on [Mono].
140+
* On [Publisher] instances other than [Mono], this function is not deprecated.
141+
*
142+
* Both [awaitFirst] and [awaitSingle] await the first value, or throw [NoSuchElementException] if there is none, but
143+
* the name [Mono.awaitSingle] better reflects the semantics of [Mono].
144+
*
145+
* For example, consider this code:
146+
* ```
147+
* myDbClient.findById(uniqueId).awaitFirst() // findById returns a `Mono`
148+
* ```
149+
* It looks like more than one value could be returned from `findById` and [awaitFirst] discards the extra elements,
150+
* when in fact, at most a single value can be present.
142151
*/
143152
@Deprecated(
144153
message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
145154
"Please use awaitSingle() instead.",
146155
level = DeprecationLevel.WARNING,
147156
replaceWith = ReplaceWith("this.awaitSingle()")
148-
) // Warning since 1.5, error in 1.6, hidden in 1.7
157+
) // Warning since 1.5, error in 1.6
149158
public suspend fun <T> Mono<T>.awaitFirst(): T = awaitSingle()
150159

151160
/**
152-
* This function is deprecated in favor of [Mono.awaitSingleOrNull].
153-
* Both functions await the first value or return some special value if there is none, but the name
154-
* [Mono.awaitSingleOrNull] better reflects the semantics of [Mono] than an operation with a "first" in its name.
161+
* This is a lint function that was added already deprecated in order to guard against confusing usages on [Mono].
162+
* On [Publisher] instances other than [Mono], this function is not deprecated.
163+
*
164+
* Both [awaitFirstOrDefault] and [awaitSingleOrNull] await the first value, or return some special value if there
165+
* is none, but the name [Mono.awaitSingleOrNull] better reflects the semantics of [Mono].
166+
*
167+
* For example, consider this code:
168+
* ```
169+
* myDbClient.findById(uniqueId).awaitFirstOrDefault(default) // findById returns a `Mono`
170+
* ```
171+
* It looks like more than one value could be returned from `findById` and [awaitFirstOrDefault] discards the extra
172+
* elements, when in fact, at most a single value can be present.
155173
*/
156174
@Deprecated(
157175
message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
158176
"Please use awaitSingleOrNull() instead.",
159177
level = DeprecationLevel.WARNING,
160178
replaceWith = ReplaceWith("this.awaitSingleOrNull() ?: default")
161-
) // Warning since 1.5, error in 1.6, hidden in 1.7
179+
) // Warning since 1.5, error in 1.6
162180
public suspend fun <T> Mono<T>.awaitFirstOrDefault(default: T): T = awaitSingleOrNull() ?: default
163181

164182
/**
165-
* This function is deprecated in favor of [Mono.awaitSingleOrNull].
166-
* Both functions await the first value or return some special value if there is none, but the name
167-
* [Mono.awaitSingleOrNull] better reflects the semantics of [Mono].
183+
* This is a lint function that was added already deprecated in order to guard against confusing usages on [Mono].
184+
* On [Publisher] instances other than [Mono], this function is not deprecated.
185+
*
186+
* Both [awaitFirstOrNull] and [awaitSingleOrNull] await the first value, or return some special value if there
187+
* is none, but the name [Mono.awaitSingleOrNull] better reflects the semantics of [Mono].
188+
*
189+
* For example, consider this code:
190+
* ```
191+
* myDbClient.findById(uniqueId).awaitFirstOrNull() // findById returns a `Mono`
192+
* ```
193+
* It looks like more than one value could be returned from `findById` and [awaitFirstOrNull] discards the extra
194+
* elements, when in fact, at most a single value can be present.
168195
*/
169196
@Deprecated(
170197
message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
171198
"Please use awaitSingleOrNull() instead.",
172199
level = DeprecationLevel.WARNING,
173200
replaceWith = ReplaceWith("this.awaitSingleOrNull()")
174-
) // Warning since 1.5, error in 1.6, hidden in 1.7
201+
) // Warning since 1.5, error in 1.6
175202
public suspend fun <T> Mono<T>.awaitFirstOrNull(): T? = awaitSingleOrNull()
176203

177204
/**
178-
* This function is deprecated in favor of [Mono.awaitSingleOrNull].
179-
* Both functions await the first value or return some special value if there is none, but the name
180-
* [Mono.awaitSingleOrNull] better reflects the semantics of [Mono] than an operation with a "first" in its name.
205+
* This is a lint function that was added already deprecated in order to guard against confusing usages on [Mono].
206+
* On [Publisher] instances other than [Mono], this function is not deprecated.
207+
*
208+
* Both [awaitFirstOrElse] and [awaitSingleOrNull] await the first value, or return some special value if there
209+
* is none, but the name [Mono.awaitSingleOrNull] better reflects the semantics of [Mono].
210+
*
211+
* For example, consider this code:
212+
* ```
213+
* myDbClient.findById(uniqueId).awaitFirstOrElse(defaultValue) // findById returns a `Mono`
214+
* ```
215+
* It looks like more than one value could be returned from `findById` and [awaitFirstOrElse] discards the extra
216+
* elements, when in fact, at most a single value can be present.
181217
*/
182218
@Deprecated(
183219
message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " +
184220
"Please use awaitSingleOrNull() instead.",
185221
level = DeprecationLevel.WARNING,
186222
replaceWith = ReplaceWith("this.awaitSingleOrNull() ?: defaultValue()")
187-
) // Warning since 1.5, error in 1.6, hidden in 1.7
223+
) // Warning since 1.5, error in 1.6
188224
public suspend fun <T> Mono<T>.awaitFirstOrElse(defaultValue: () -> T): T = awaitSingleOrNull() ?: defaultValue()
189225

190226
/**
191-
* This function is deprecated in favor of [Mono.awaitSingle].
192-
* Both functions await the only value or return some special value if there is none, but the name
193-
* "awaitLast" strongly suggests that there is more than one value, which is not the case.
227+
* This is a lint function that was added already deprecated in order to guard against confusing usages on [Mono].
228+
* On [Publisher] instances other than [Mono], this function is not deprecated.
229+
*
230+
* Both [awaitLast] and [awaitSingle] await the single value, or throw [NoSuchElementException] if there is none, but
231+
* the name [Mono.awaitSingle] better reflects the semantics of [Mono].
232+
*
233+
* For example, consider this code:
234+
* ```
235+
* myDbClient.findById(uniqueId).awaitLast() // findById returns a `Mono`
236+
* ```
237+
* It looks like more than one value could be returned from `findById` and [awaitLast] discards the initial elements,
238+
* when in fact, at most a single value can be present.
194239
*/
195240
@Deprecated(
196241
message = "Mono produces at most one value, so the last element is the same as the first. " +
197242
"Please use awaitSingle() instead.",
198243
level = DeprecationLevel.WARNING,
199244
replaceWith = ReplaceWith("this.awaitSingle()")
200-
) // Warning since 1.5, error in 1.6, hidden in 1.7
245+
) // Warning since 1.5, error in 1.6
201246
public suspend fun <T> Mono<T>.awaitLast(): T = awaitSingle()

0 commit comments

Comments
 (0)