Merge pull request #1959 from 1552980358/master

Coroutine.kt: Replace .plus with '+'
pull/1966/head
kunfei 2 years ago committed by GitHub
commit 6c6e240b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt

@ -121,7 +121,7 @@ class Coroutine<T>(
if (null == it.context) { if (null == it.context) {
it.block.invoke(scope) it.block.invoke(scope)
} else { } else {
withContext(scope.coroutineContext.plus(it.context)) { withContext(scope.coroutineContext + it.context) {
it.block.invoke(this) it.block.invoke(this)
} }
} }
@ -137,7 +137,7 @@ class Coroutine<T>(
context: CoroutineContext, context: CoroutineContext,
block: suspend CoroutineScope.() -> T block: suspend CoroutineScope.() -> T
): Job { ): Job {
return scope.plus(Dispatchers.Main).launch { return (scope + Dispatchers.Main).launch {
try { try {
start?.let { dispatchVoidCallback(this, it) } start?.let { dispatchVoidCallback(this, it) }
ensureActive() ensureActive()
@ -166,7 +166,7 @@ class Coroutine<T>(
if (null == callback.context) { if (null == callback.context) {
callback.block.invoke(scope) callback.block.invoke(scope)
} else { } else {
withContext(scope.coroutineContext.plus(callback.context)) { withContext(scope.coroutineContext + callback.context) {
callback.block.invoke(this) callback.block.invoke(this)
} }
} }
@ -181,7 +181,7 @@ class Coroutine<T>(
if (null == callback.context) { if (null == callback.context) {
callback.block.invoke(scope, value) callback.block.invoke(scope, value)
} else { } else {
withContext(scope.coroutineContext.plus(callback.context)) { withContext(scope.coroutineContext + callback.context) {
callback.block.invoke(this, value) callback.block.invoke(this, value)
} }
} }
@ -193,7 +193,7 @@ class Coroutine<T>(
timeMillis: Long, timeMillis: Long,
noinline block: suspend CoroutineScope.() -> T noinline block: suspend CoroutineScope.() -> T
): T { ): T {
return withContext(scope.coroutineContext.plus(context)) { return withContext(scope.coroutineContext + context) {
if (timeMillis > 0L) withTimeout(timeMillis) { if (timeMillis > 0L) withTimeout(timeMillis) {
block() block()
} else { } else {

Loading…
Cancel
Save