From f98b1f97302c44bf844c4cf6e58dbe5a9faebbbb Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Mon, 15 Jul 2019 17:26:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/coroutine/Coroutine.kt | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index 76e4a8439..8dd2cf9dc 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -17,9 +17,18 @@ class Coroutine() { } } - private var coroutine: Coroutine? = null + private var interceptor: Coroutine? = null private var job: Job? = null + private var start: (() -> Unit)? = null + private var success: ((T?) -> Unit)? = null + private var error: ((Throwable) -> Unit)? = null + private var finally: (() -> Unit)? = null + + private var timeMillis: Long? = null + + private var errorReturn: Result? = null + private constructor( scope: CoroutineScope? = null, block: (suspend CoroutineScope.() -> T)? = null @@ -30,23 +39,13 @@ class Coroutine() { } private constructor(coroutine: Coroutine) : this() { - this.coroutine = coroutine + this.interceptor = coroutine this.job = coroutine.job } - private var start: (() -> Unit)? = null - private var success: ((T?) -> Unit)? = null - private var error: ((Throwable) -> Unit)? = null - private var finally: (() -> Unit)? = null - - private var timeMillis: Long? = null - - private var errorReturn: Result? = null - - fun timeout(timeMillis: () -> Long): Coroutine { - if (this.coroutine != null) { - this.coroutine!!.timeMillis = timeMillis() + if (this.interceptor != null) { + this.interceptor!!.timeMillis = timeMillis() } else { this.timeMillis = timeMillis() } @@ -54,8 +53,8 @@ class Coroutine() { } fun onErrorReturn(value: () -> T?): Coroutine { - if (this.coroutine != null) { - this.coroutine!!.errorReturn = Result(value()) + if (this.interceptor != null) { + this.interceptor!!.errorReturn = Result(value()) } else { errorReturn = Result(value()) } @@ -63,8 +62,8 @@ class Coroutine() { } fun onStart(start: (() -> Unit)): Coroutine { - if (this.coroutine != null) { - this.coroutine!!.start = start + if (this.interceptor != null) { + this.interceptor!!.start = start } else { this.start = start } @@ -72,8 +71,8 @@ class Coroutine() { } fun onSuccess(success: (T?) -> Unit): Coroutine { - if (this.coroutine != null) { - this.coroutine!!.success = success + if (this.interceptor != null) { + this.interceptor!!.success = success } else { this.success = success } @@ -81,8 +80,8 @@ class Coroutine() { } fun onError(error: (Throwable) -> Unit): Coroutine { - if (this.coroutine != null) { - this.coroutine!!.error = error + if (this.interceptor != null) { + this.interceptor!!.error = error } else { this.error = error } @@ -90,8 +89,8 @@ class Coroutine() { } fun onFinally(finally: () -> Unit): Coroutine { - if (this.coroutine != null) { - this.coroutine!!.finally = finally + if (this.interceptor != null) { + this.interceptor!!.finally = finally } else { this.finally = finally }