``` class Test { @Volatile var ticker = 0 ...
# coroutines
d
Copy code
class Test {
    @Volatile
    var ticker = 0

    @Volatile
    var deferred: Deferred<String>
    val retryingExceptionHandler: CoroutineExceptionHandler = CoroutineExceptionHandler { _, throwable ->
        println("!!!!!!!")
        authScope.kickoffUpdateWithDelay()
        authScope.testB()
    }
    val authScope = CoroutineScope(SupervisorJob() + <http://Dispatchers.IO|Dispatchers.IO> + retryingExceptionHandler)

    init {
        deferred = authScope.async { getSome() }
        authScope.testB()
    }

    fun CoroutineScope.kickoffUpdateWithDelay() = launch {
        delay(100)
        deferred = authScope.async { getSome() }
    }

    suspend fun getSome(): String {
        if (ticker < 5) {
            delay(1)
            ticker += 1
            throw Exception()
        } else {
            delay(1)
            ticker += 1
            return "PASSSED"
        }
    }

    fun CoroutineScope.testB() = launch {
        deferred.await()
        if (ticker < 5) {
            ticker += 1
            throw Exception()
        } else {
            ticker += 1
            println("PASSSED")
        }
    }
}

fun main(args: Array<String>) = runBlocking<Unit> {

    Test()

    repeat(100) {
        delay(100)
    }
}