review changes
This commit is contained in:
@@ -4,7 +4,6 @@ import kotlinx.coroutines.CoroutineDispatcher
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
fun <T> dispatch(
|
fun <T> dispatch(
|
||||||
dispatcher: CoroutineDispatcher = Dispatchers.IO,
|
dispatcher: CoroutineDispatcher = Dispatchers.IO,
|
||||||
@@ -12,9 +11,6 @@ fun <T> dispatch(
|
|||||||
block: () -> T
|
block: () -> T
|
||||||
) {
|
) {
|
||||||
CoroutineScope(dispatcher).launch {
|
CoroutineScope(dispatcher).launch {
|
||||||
val result = runCatching { block() }
|
callback(runCatching { block() })
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
callback(result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ func dispatch<T>(
|
|||||||
block: @escaping () throws -> T
|
block: @escaping () throws -> T
|
||||||
) {
|
) {
|
||||||
DispatchQueue.global(qos: qos).async {
|
DispatchQueue.global(qos: qos).async {
|
||||||
let result = Result { try block() }
|
completion(Result { try block() })
|
||||||
DispatchQueue.main.async {
|
|
||||||
completion(result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user