private var job = Job() private val scope = CoroutineScope(dispatcherProvider.io + job) private fun coroutineMethod() { scope.launch(exceptionHandler) { while(job.isActive) { dosomething() delay(4000) } } } private val exceptionHandler = CoroutineExceptionHandler { _, exception -> if (exception.isSomeException()) { job.cancel() //Or scope.cancel doSomethingMore() coroutineMethod() //restart coroutine } else { Logger.e(TAG, "Failed in fetching connector status", exception) } }