Anders Sveen
11/17/2022, 6:43 AM@Test
fun shouldExecuteOnDifferentThreads() {
runBlocking {
// Some blocking DB operation
val firstThread = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
Thread.currentThread()
}
// Another blocking DB operation
val secondThread = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
Thread.currentThread()
}
assertThat(firstThread).isNotSameAs(secondThread)
}
}
bezrukov
11/17/2022, 6:56 AMAnders Sveen
11/17/2022, 8:24 AMAnders Sveen
11/17/2022, 8:29 AMasync { Thread.sleep(1000) }
Anders Sveen
11/17/2022, 8:42 AMJoffrey
11/17/2022, 3:50 PM@OptIn(DelicateCoroutinesApi::class)
@Test
fun shouldExecuteOnDifferentThreads() = runBlocking {
val thread1 = newSingleThreadContext("thread-1")
val thread2 = newSingleThreadContext("thread-2")
// Some blocking DB operation
val firstThread = withContext(thread1) {
Thread.currentThread()
}
// Another blocking DB operation
val secondThread = withContext(thread2) {
Thread.currentThread()
}
assertThat(firstThread).isNotSameAs(secondThread)
}
Srikanth Raju
07/14/2023, 3:48 AMAnders Sveen
10/19/2023, 11:06 AMSrikanth Raju
10/19/2023, 5:32 PMAnders Sveen
10/19/2023, 5:35 PMSrikanth Raju
10/19/2023, 5:38 PMAnders Sveen
10/19/2023, 5:40 PM