@@ -34,6 +34,7 @@ import kotlinx.coroutines.flow.asFlow
3434import kotlinx.coroutines.flow.onEach
3535import kotlinx.coroutines.launch
3636import kotlinx.coroutines.runBlocking
37+ import java.util.UUID
3738
3839
3940/* *
@@ -92,18 +93,13 @@ internal object FatalIssueGenerator {
9293 }
9394
9495 fun forceCoroutinesAnr () {
95- CoroutineScope (Dispatchers .Main ).launch {
96- (1 .. Int .MAX_VALUE ).asFlow()
97- .onEach {
98- Thread .sleep(1 )
99- }
100- .collect {
101- Log .i(TAG_NAME , " Item received: $it " )
102- }
96+ callOnMainThread {
97+ Log .i(TAG_NAME , " forceCoroutinesAnr. Getting device" )
98+ val deviceId = DeviceFetcher .getDeviceId()
99+ Log .d(TAG_NAME , " forceCoroutinesAnr. Device ID: $deviceId " )
103100 }
104101 }
105102
106-
107103 fun forceCoroutinesCrash (){
108104 CoroutineScope (Dispatchers .IO ).launch {
109105 throw RuntimeException (" Coroutine background thread crash" )
@@ -195,4 +191,22 @@ internal object FatalIssueGenerator {
195191 return " Task ID [$id ] completed with a $duration of milliseconds"
196192 }
197193 }
194+
195+ object DeviceFetcher {
196+
197+ private suspend fun fetchDeviceId (): String {
198+ delay(20000 )
199+ return " Device ID: ${UUID .randomUUID()} "
200+ }
201+
202+ /* *
203+ * This call will block caller thread until fetchDeviceId completes
204+ */
205+ fun getDeviceId (): String {
206+ return runBlocking {
207+ Log .i(" DeviceScopeRegistry" , " getDevice" )
208+ fetchDeviceId()
209+ }
210+ }
211+ }
198212}
0 commit comments