Skip to content

Commit 015a32a

Browse files
committed
Clarify the docs
1 parent a4ddb16 commit 015a32a

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
@@ -133,66 +133,111 @@ public fun <T> CoroutineScope.mono(
133133
): Mono<T> = monoInternal(this, context, block)
134134

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

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

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

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

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

0 commit comments

Comments
 (0)