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