|
|
@ -108,14 +108,7 @@ class Coroutine<T>() { |
|
|
|
{ |
|
|
|
{ |
|
|
|
start?.let { it() } |
|
|
|
start?.let { it() } |
|
|
|
|
|
|
|
|
|
|
|
val time = timeMillis |
|
|
|
val result = executeBlock(block, timeMillis ?: 0L) |
|
|
|
val result = if (time != null && time > 0) { |
|
|
|
|
|
|
|
withTimeout(time) { |
|
|
|
|
|
|
|
executeBlock(block) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
executeBlock(block) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
success?.let { it(result) } |
|
|
|
success?.let { it(result) } |
|
|
|
}, |
|
|
|
}, |
|
|
@ -134,10 +127,11 @@ class Coroutine<T>() { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private suspend fun executeBlock(block: suspend CoroutineScope.() -> T): T? { |
|
|
|
private suspend fun executeBlock(block: suspend CoroutineScope.() -> T, timeMillis: Long): T? { |
|
|
|
return withContext(Dispatchers.IO) { |
|
|
|
val asyncBlock = withContext(Dispatchers.IO) { |
|
|
|
block() |
|
|
|
block() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return if (timeMillis > 0L) withTimeout(timeMillis) { asyncBlock } else asyncBlock |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private suspend fun tryCatch( |
|
|
|
private suspend fun tryCatch( |
|
|
|