xref: /aosp_15_r20/external/kotlinx.coroutines/kotlinx-coroutines-core/common/src/selects/WhileSelect.kt (revision 7a7160fed73afa6648ef8aa100d4a336fe921d9a)
1 package kotlinx.coroutines.selects
2 
3 import kotlinx.coroutines.*
4 
5 /**
6  * Loops while [select] expression returns `true`.
7  *
8  * The statement of the form:
9  *
10  * ```
11  * whileSelect {
12  *     /*body*/
13  * }
14  * ```
15  *
16  * is a shortcut for:
17  *
18  * ```
19  * while(select<Boolean> {
20  *    /*body*/
21  * }) {}
22  *
23  * **Note: This is an experimental api.** It may be replaced with a higher-performance DSL for selection from loops.
24  */
25 @ExperimentalCoroutinesApi
whileSelectnull26 public suspend inline fun whileSelect(crossinline builder: SelectBuilder<Boolean>.() -> Unit) {
27     while(select(builder)) { /* do nothing */ }
28 }
29