runBlocking<Unit> {
                  
                  
                          val scope = CoroutineScope(Dispatchers.Default + Job(coroutineContext[Job]))
                  
                  
                          val value = suspendCoroutine<Boolean> { continuation ->
                  
                  
                              scope.launch {
                  
                  
                                  continuation.resume(true)
                  
                  
                                  println("suspendCoroutine resumed")
                  
                  
                                  delay(1000)
                  
                  
                                  println("suspendCoroutineStillActive ${continuation.context.isActive}")
                  
                  
                                  scope.cancel()
                  
                  
                              }
                  
                  
                          }
                  
                  
                          println("suspendCoroutineValue $value")
                  
                  
                      }
                  
                  
                  Выводит
                  
                  
                  suspendCoroutine resumed
                  
                  
                  suspendCoroutineValue true
                  
                  
                  suspendCoroutineStillActive true
                  
                  
                  ЧЯДНТ?
                  
                  
                
Ну пожалуй стоит начать с того что так suspendCoroutine не стоит использовать, он для других целей. Или это чисто для демонстрации код?
Обсуждают сегодня