-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test:
delaySafe
as a safe replacement for delay
when used inside …
…a `runTest` or `TestScope`. Details: https://github.com/Kotlin/kotlinx.coroutines/blob/81e17dd/kotlinx-coroutines-test/README.md#delay-skipping Kotlin/kotlinx.coroutines#3588 Signed-off-by: Artyom Shendrik <[email protected]>
- Loading branch information
Showing
10 changed files
with
53 additions
and
33 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
fluxo-core/src/commonTest/kotlin/kt/fluxo/test/DelaySafe.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package kt.fluxo.test | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.test.TestScope | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.coroutines.withContext | ||
|
||
/** | ||
* Use as a safe replacement for [delay] when used inside a [runTest]/[TestScope]. | ||
* | ||
* Delays coroutine for a given time without blocking a thread and resumes it after a specified time. | ||
* | ||
* [Documentation on delay-skipping in tests](https://github.com/Kotlin/kotlinx.coroutines/blob/81e17dd/kotlinx-coroutines-test/README.md#delay-skipping) | ||
* | ||
* @param timeMillis timeout time in milliseconds. | ||
* | ||
* @see delay | ||
* @see withTimeoutSafe | ||
*/ | ||
@Suppress("MaxLineLength") | ||
suspend fun delaySafe(timeMillis: Long) { | ||
withContext(Dispatchers.Default) { | ||
delay(timeMillis) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters