Skip to content

Commit 0197afb

Browse files
authored
Replace delay(Long) with corresponding delay(Duration) (#3030)
1 parent 7e7e8c3 commit 0197afb

18 files changed

Lines changed: 69 additions & 53 deletions

File tree

compose/desktop/desktop/samples/src/jvmMain/kotlin/androidx/compose/desktop/examples/layout/Main.jvm.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.compose.ui.unit.dp
2727
import androidx.compose.ui.window.DialogWindow
2828
import androidx.compose.ui.window.application
2929
import androidx.compose.ui.window.rememberDialogState
30+
import kotlin.time.Duration.Companion.milliseconds
3031
import kotlinx.coroutines.delay
3132

3233
fun main() = application {
@@ -65,7 +66,7 @@ fun IterateViews(periodMs: Long, vararg views: @Composable () -> Unit) {
6566
if (currentIndex < views.size) {
6667
views[currentIndex]()
6768
LaunchedEffect(currentIndex) {
68-
delay(periodMs)
69+
delay(periodMs.milliseconds)
6970
currentIndex++
7071
}
7172
} else {

compose/desktop/desktop/samples/src/jvmMain/kotlin/androidx/compose/desktop/examples/windowapi/Examples.jvm.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import java.awt.Frame
6767
import java.awt.event.WindowAdapter
6868
import java.awt.event.WindowEvent
6969
import javax.imageio.ImageIO
70+
import kotlin.time.Duration.Companion.seconds
7071
import kotlinx.coroutines.DelicateCoroutinesApi
7172
import kotlinx.coroutines.Dispatchers
7273
import kotlinx.coroutines.GlobalScope
@@ -100,9 +101,9 @@ fun suspendBackgroundApplication() = GlobalScope.launch {
100101
awaitApplication {
101102
LaunchedEffect(Unit) {
102103
println("1")
103-
delay(1000)
104+
delay(1.seconds)
104105
println("2")
105-
delay(1000)
106+
delay(1.seconds)
106107
println("3")
107108
}
108109
}
@@ -115,7 +116,7 @@ fun splashScreen() = GlobalScope.launchApplication {
115116
var isLoading by remember { mutableStateOf(true) }
116117

117118
LaunchedEffect(Unit) {
118-
delay(2000)
119+
delay(2.seconds)
119120
isLoading = false
120121
}
121122

@@ -135,7 +136,7 @@ fun autoClose() = GlobalScope.launchApplication {
135136
var isOpen by remember { mutableStateOf(true) }
136137

137138
LaunchedEffect(Unit) {
138-
delay(2000)
139+
delay(2.seconds)
139140
isOpen = false
140141
}
141142

@@ -178,7 +179,7 @@ fun closeToTray() = GlobalScope.launchApplication {
178179
LaunchedEffect(Unit) {
179180
while (true) {
180181
counter++
181-
delay(1000)
182+
delay(1.seconds)
182183
}
183184
}
184185
Text(counter.toString())
@@ -227,7 +228,7 @@ fun customWindow() = GlobalScope.launchApplication {
227228
LaunchedEffect(Unit) {
228229
while (true) {
229230
titleNum++
230-
delay(1000)
231+
delay(1.seconds)
231232
}
232233
}
233234

@@ -288,7 +289,7 @@ fun hideDialog() = GlobalScope.launchApplication {
288289
LaunchedEffect(Unit) {
289290
while (true) {
290291
counter++
291-
delay(1000)
292+
delay(1.seconds)
292293
}
293294
}
294295
Text(counter.toString())
@@ -331,11 +332,11 @@ fun setIcon() = GlobalScope.launchApplication {
331332
var icon: Painter? by remember { mutableStateOf(null) }
332333

333334
LaunchedEffect(Unit) {
334-
delay(1000)
335+
delay(1.seconds)
335336
icon = loadIcon()
336-
delay(1000)
337+
delay(1.seconds)
337338
icon = null
338-
delay(1000)
339+
delay(1.seconds)
339340
icon = loadIcon()
340341
}
341342

compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/TooltipArea.desktop.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import androidx.compose.ui.window.Popup
4545
import androidx.compose.ui.window.PopupPositionProvider
4646
import androidx.compose.ui.window.rememberPopupPositionProviderAtPosition
4747
import androidx.compose.ui.window.rememberComponentRectPositionProvider
48+
import kotlin.time.Duration.Companion.milliseconds
4849
import kotlinx.coroutines.delay
4950
import kotlinx.coroutines.Job
5051
import kotlinx.coroutines.flow.collectLatest
@@ -115,7 +116,7 @@ fun TooltipArea(
115116
return
116117
}
117118
showTooltipJob = scope.launch {
118-
delay(delayMillis.toLong())
119+
delay(delayMillis.milliseconds)
119120
isVisible = true
120121
}
121122
}

compose/mpp/demo/src/desktopMain/kotlin/androidx/compose/mpp/demo/components/DragAndDropExample.desktop.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import androidx.compose.ui.text.rememberTextMeasurer
5252
import androidx.compose.ui.unit.dp
5353
import java.awt.datatransfer.DataFlavor
5454
import java.awt.datatransfer.StringSelection
55+
import kotlin.time.Duration.Companion.seconds
5556
import kotlinx.coroutines.delay
5657
import kotlinx.coroutines.launch
5758

@@ -141,7 +142,7 @@ actual fun DragAndDropExample() {
141142
it.transferDataFlavors.first().humanPresentableName
142143
}
143144
coroutineScope.launch {
144-
delay(2000)
145+
delay(2.seconds)
145146
targetText = "Drop Here"
146147
}
147148
return result

compose/ui/ui-test-junit4/src/desktopTest/kotlin/androidx/compose/ui/test/ComposeUiTestTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import com.google.common.truth.Truth.assertThat
2828
import kotlin.coroutines.CoroutineContext
2929
import kotlin.test.assertEquals
3030
import kotlin.test.assertFailsWith
31-
import kotlin.test.assertTrue
3231
import kotlin.test.fail
3332
import kotlin.time.Duration.Companion.milliseconds
33+
import kotlin.time.Duration.Companion.seconds
3434
import kotlinx.coroutines.CoroutineScope
3535
import kotlinx.coroutines.Dispatchers
3636
import kotlinx.coroutines.delay
@@ -172,7 +172,7 @@ class ComposeUiTestTest {
172172
val error = assertFailsWith<AssertionError> {
173173
runComposeUiTest(testTimeout = timeout) {
174174
// switch a dispatcher to not skip the delay
175-
withContext(Dispatchers.Default) { delay(1000) }
175+
withContext(Dispatchers.Default) { delay(1.seconds) }
176176
}
177177
}
178178
// Here our assert relies on the implementation details of kotlinx.coroutines.test library,

compose/ui/ui-test/src/desktopTest/kotlin/androidx/compose/ui/test/DesktopTestsTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import java.nio.file.Files
3434
import kotlin.io.path.readBytes
3535
import kotlin.io.path.writeBytes
3636
import kotlin.test.Test
37+
import kotlin.time.Duration.Companion.seconds
3738
import kotlinx.coroutines.CoroutineScope
3839
import kotlinx.coroutines.Dispatchers
3940
import kotlinx.coroutines.delay
@@ -150,7 +151,7 @@ class DesktopTestsTest {
150151
text = "first"
151152
isIdle = false
152153
val job = CoroutineScope(Dispatchers.Default).launch {
153-
delay(1000)
154+
delay(1.seconds)
154155
text = "second"
155156
isIdle = true
156157
}

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/a11y/Accessibility.desktop.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.jetbrains.skiko.OS
1212
import org.jetbrains.skiko.hostOs
1313
import org.jetbrains.skiko.initializeCAccessible
1414
import androidx.compose.ui.scene.skia.SkiaLayerComponent
15+
import kotlin.time.Duration.Companion.milliseconds
1516

1617
/**
1718
* A helper class for requesting accessibility focus on a given accessible.
@@ -85,7 +86,7 @@ internal class AccessibleFocusHelper(
8586
}
8687

8788
companion object {
88-
const val RESET_FOCUS_ACCESSIBLE_DELAY = 100L
89+
val RESET_FOCUS_ACCESSIBLE_DELAY = 100.milliseconds
8990
}
9091
}
9192

compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/ComposeSceneTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import kotlin.test.assertEquals
9595
import kotlin.test.assertNull
9696
import kotlin.test.assertTrue
9797
import kotlin.test.fail
98+
import kotlin.time.Duration.Companion.milliseconds
9899
import kotlinx.coroutines.CompletableDeferred
99100
import kotlinx.coroutines.Dispatchers
100101
import kotlinx.coroutines.asCoroutineDispatcher
@@ -679,7 +680,7 @@ class ComposeSceneTest {
679680
for (i in 1..50) {
680681
value = i
681682
Snapshot.sendApplyNotifications()
682-
delay(1)
683+
delay(1.milliseconds)
683684
}
684685
} catch (e: Throwable) {
685686
exceptionThrown = e
@@ -749,14 +750,14 @@ class ComposeSceneTest {
749750

750751
// Try to cause changes while sendApplyNotifications is being called, to get
751752
// SnapshotStateObserver.sendNotifications to call drainChanges.
752-
for (i in 1..500) {
753+
repeat(500) {
753754
repeat(100) {
754755
value++
755756
if (timedOut.get()) {
756757
fail("Reached timeout; was probably stuck in a deadlock")
757758
}
758759
}
759-
delay(1)
760+
delay(1.milliseconds)
760761
}
761762
}
762763

compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComplexApplicationTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ import androidx.compose.ui.window.runApplicationTest
126126
import com.google.common.truth.Truth
127127
import kotlin.random.Random
128128
import kotlin.test.Ignore
129+
import kotlin.time.Duration.Companion.milliseconds
129130
import kotlin.time.Duration.Companion.minutes
130131
import kotlin.time.Duration.Companion.seconds
131132
import kotlinx.coroutines.DelicateCoroutinesApi
@@ -648,9 +649,9 @@ fun AppWindow() {
648649
private suspend fun performGC() {
649650
repeat(10) {
650651
System.gc()
651-
delay(100)
652+
delay(100.milliseconds)
652653
}
653-
delay(5000)
654+
delay(5.seconds)
654655
}
655656

656657
private val availableMemory get() = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()
@@ -664,7 +665,7 @@ class ComplexApplicationTest {
664665
awaitApplication {
665666
AppWindow()
666667
LaunchedEffect(Unit) {
667-
delay(1000)
668+
delay(1.seconds)
668669
exitApplication()
669670
}
670671
}
@@ -677,7 +678,7 @@ class ComplexApplicationTest {
677678
awaitApplication {
678679
AppWindow()
679680
LaunchedEffect(Unit) {
680-
delay(1000)
681+
delay(1.seconds)
681682
exitApplication()
682683
}
683684
}

compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposePanelTest.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import junit.framework.TestCase.assertTrue
8484
import kotlin.test.assertEquals
8585
import kotlin.test.assertFalse
8686
import kotlin.test.assertNotNull
87+
import kotlin.time.Duration.Companion.seconds
8788
import kotlinx.coroutines.delay
8889
import kotlinx.coroutines.runBlocking
8990
import org.jetbrains.skiko.ExperimentalSkikoApi
@@ -263,15 +264,15 @@ class ComposePanelTest {
263264
frame.pack()
264265

265266
frame.isVisible = true
266-
delay(1000)
267+
delay(1.seconds)
267268
assertEquals(1, initialStateCounter)
268269

269270
frame.contentPane.remove(composePanel)
270-
delay(1000)
271+
delay(1.seconds)
271272
assertEquals(1, initialStateCounter)
272273

273274
frame.contentPane.add(composePanel)
274-
delay(1000)
275+
delay(1.seconds)
275276
assertEquals(1, initialStateCounter)
276277
} finally {
277278
frame.dispose()
@@ -306,15 +307,15 @@ class ComposePanelTest {
306307
frame.pack()
307308

308309
frame.isVisible = true
309-
delay(1000)
310+
delay(1.seconds)
310311
assertEquals(1, initialStateCounter)
311312

312313
frame.contentPane.remove(composePanel)
313-
delay(1000)
314+
delay(1.seconds)
314315
assertEquals(1, initialStateCounter)
315316

316317
frame.contentPane.add(composePanel)
317-
delay(1000)
318+
delay(1.seconds)
318319
assertEquals(2, initialStateCounter)
319320
} finally {
320321
frame.dispose()
@@ -343,19 +344,19 @@ class ComposePanelTest {
343344
val density = frame.contentPane.density.density
344345
frame.contentPane.add(composePanel)
345346
frame.isVisible = true
346-
delay(1000)
347+
delay(1.seconds)
347348
assertEquals(Size(100f * density, 100f * density), size)
348349

349350
frame.contentPane.remove(composePanel)
350-
delay(1000)
351+
delay(1.seconds)
351352
assertEquals(Size(100f * density, 100f * density), size)
352353

353354
frame.contentPane.add(composePanel)
354-
delay(1000)
355+
delay(1.seconds)
355356
assertEquals(Size(100f * density, 100f * density), size)
356357

357358
frame.size = Dimension(200, 100)
358-
delay(1000)
359+
delay(1.seconds)
359360
assertEquals(Size(200f * density, 100f * density), size)
360361
} finally {
361362
frame.dispose()
@@ -382,7 +383,7 @@ class ComposePanelTest {
382383
frame.pack()
383384

384385
frame.isVisible = true
385-
delay(1000)
386+
delay(1.seconds)
386387
assertTrue(content.size.height > 2)
387388
assertTrue(content.size.width > 2)
388389
} finally {
@@ -416,7 +417,7 @@ class ComposePanelTest {
416417
frame.pack()
417418

418419
frame.isVisible = true
419-
delay(1000)
420+
delay(1.seconds)
420421
assertTrue(content.size.width > 2)
421422
assertEquals(500, content.size.height)
422423
} finally {
@@ -451,7 +452,7 @@ class ComposePanelTest {
451452
frame.pack()
452453

453454
frame.isVisible = true
454-
delay(1000)
455+
delay(1.seconds)
455456
assertEquals(200, content.size.width)
456457
assertEquals(300, content.size.height)
457458
} finally {

0 commit comments

Comments
 (0)