@@ -10,85 +10,89 @@ import org.reactivestreams.Subscriber
10
10
import org.reactivestreams.Subscription
11
11
import java.lang.IllegalStateException
12
12
import java.util.*
13
+ import kotlin.NoSuchElementException
13
14
import kotlin.coroutines.*
14
15
15
16
/* *
16
- * Awaits for the first value from the given publisher without blocking a thread and
17
- * returns the resulting value or throws the corresponding exception if this publisher had produced error .
17
+ * Awaits the first value from the given publisher without blocking the thread and returns the resulting value, or, if
18
+ * the publisher has produced an error, throws the corresponding exception.
18
19
*
19
20
* This suspending function is cancellable.
20
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
21
- * immediately resumes with [CancellationException].
21
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
22
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
22
23
*
23
- * @throws NoSuchElementException if publisher does not emit any value
24
+ * @throws NoSuchElementException if the publisher does not emit any value
24
25
*/
25
26
public suspend fun <T > Publisher<T>.awaitFirst (): T = awaitOne(Mode .FIRST )
26
27
27
28
/* *
28
- * Awaits for the first value from the given observable or the [default] value if none is emitted without blocking a
29
- * thread and returns the resulting value or throws the corresponding exception if this observable had produced error.
29
+ * Awaits the first value from the given observable, or returns the [default] value if none is emitted, without blocking
30
+ * the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding
31
+ * exception.
30
32
*
31
33
* This suspending function is cancellable.
32
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
33
- * immediately resumes with [CancellationException].
34
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
35
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
34
36
*/
35
37
public suspend fun <T > Publisher<T>.awaitFirstOrDefault (default : T ): T = awaitOne(Mode .FIRST_OR_DEFAULT , default)
36
38
37
39
/* *
38
- * Awaits for the first value from the given observable or `null` value if none is emitted without blocking a
39
- * thread and returns the resulting value or throws the corresponding exception if this observable had produced error.
40
+ * Awaits the first value from the given observable, or returns `null` if none is emitted, without blocking the thread,
41
+ * and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception .
40
42
*
41
43
* This suspending function is cancellable.
42
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
43
- * immediately resumes with [CancellationException].
44
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
45
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
44
46
*/
45
47
public suspend fun <T > Publisher<T>.awaitFirstOrNull (): T ? = awaitOne(Mode .FIRST_OR_DEFAULT )
46
48
47
49
/* *
48
- * Awaits for the first value from the given observable or call [defaultValue] to get a value if none is emitted without blocking a
49
- * thread and returns the resulting value or throws the corresponding exception if this observable had produced error.
50
+ * Awaits the first value from the given observable, or calls [defaultValue] to get a value if none is emitted, without
51
+ * blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the
52
+ * corresponding exception.
50
53
*
51
54
* This suspending function is cancellable.
52
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
53
- * immediately resumes with [CancellationException].
55
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
56
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
54
57
*/
55
58
public suspend fun <T > Publisher<T>.awaitFirstOrElse (defaultValue : () -> T ): T = awaitOne(Mode .FIRST_OR_DEFAULT ) ? : defaultValue()
56
59
57
60
/* *
58
- * Awaits for the last value from the given publisher without blocking a thread and
59
- * returns the resulting value or throws the corresponding exception if this publisher had produced error.
61
+ * Awaits the last value from the given publisher without blocking the thread and
62
+ * returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception .
60
63
*
61
64
* This suspending function is cancellable.
62
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
63
- * immediately resumes with [CancellationException].
65
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
66
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
64
67
*
65
- * @throws NoSuchElementException if publisher does not emit any value
68
+ * @throws NoSuchElementException if the publisher does not emit any value
66
69
*/
67
70
public suspend fun <T > Publisher<T>.awaitLast (): T = awaitOne(Mode .LAST )
68
71
69
72
/* *
70
- * Awaits for the single value from the given publisher without blocking a thread and
71
- * returns the resulting value or throws the corresponding exception if this publisher had produced error .
73
+ * Awaits the single value from the given publisher without blocking the thread and returns the resulting value, or,
74
+ * if this publisher has produced an error, throws the corresponding exception.
72
75
*
73
76
* This suspending function is cancellable.
74
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
75
- * immediately resumes with [CancellationException].
77
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
78
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
76
79
*
77
- * @throws NoSuchElementException if publisher does not emit any value
78
- * @throws IllegalArgumentException if publisher emits more than one value
80
+ * @throws NoSuchElementException if the publisher does not emit any value
81
+ * @throws IllegalArgumentException if the publisher emits more than one value
79
82
*/
80
83
public suspend fun <T > Publisher<T>.awaitSingle (): T = awaitOne(Mode .SINGLE )
81
84
82
85
/* *
83
- * Awaits for the single value from the given publisher or the [default] value if none is emitted without blocking a thread and
84
- * returns the resulting value or throws the corresponding exception if this publisher had produced error.
86
+ * Awaits the single value from the given observable, or returns the [default] value if none is emitted, without
87
+ * blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the
88
+ * corresponding exception.
85
89
*
86
90
* This suspending function is cancellable.
87
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
88
- * immediately resumes with [CancellationException].
91
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
92
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
89
93
*
90
- * @throws NoSuchElementException if publisher does not emit any value
91
- * @throws IllegalArgumentException if publisher emits more than one value
94
+ * @throws NoSuchElementException if the publisher does not emit any value
95
+ * @throws IllegalArgumentException if the publisher emits more than one value
92
96
*/
93
97
public suspend fun <T > Publisher<T>.awaitSingleOrDefault (default : T ): T = awaitOne(Mode .SINGLE_OR_DEFAULT , default)
94
98
@@ -108,17 +112,18 @@ public suspend fun <T> Publisher<T>.awaitSingleOrNull(): T? = try {
108
112
}
109
113
110
114
/* *
111
- * Awaits for the single value from the given publisher or call [defaultValue] to get a value if none is emitted without blocking a thread and
112
- * returns the resulting value or throws the corresponding exception if this publisher had produced error.
115
+ * Awaits the single value from the given observable, or calls [defaultValue] to get a value if none is emitted, without
116
+ * blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the
117
+ * corresponding exception.
113
118
*
114
119
* This suspending function is cancellable.
115
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
116
- * immediately resumes with [CancellationException].
120
+ * If the [Job] of the current coroutine is cancelled or completed while the suspending function is waiting, this
121
+ * function immediately cancels its [Subscription] and resumes with [CancellationException].
117
122
*
118
- * @throws NoSuchElementException if publisher does not emit any value
119
- * @throws IllegalArgumentException if publisher emits more than one value
123
+ * @throws IllegalArgumentException if the publisher emits more than one value
120
124
*/
121
- public suspend fun <T > Publisher<T>.awaitSingleOrElse (defaultValue : () -> T ): T = awaitOne(Mode .SINGLE_OR_DEFAULT ) ? : defaultValue()
125
+ public suspend fun <T > Publisher<T>.awaitSingleOrElse (defaultValue : () -> T ): T =
126
+ awaitOne(Mode .SINGLE_OR_DEFAULT ) ? : defaultValue()
122
127
123
128
// ------------------------ private ------------------------
124
129
0 commit comments