| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -3,7 +3,7 @@ package io.legado.app.help.coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlinx.coroutines.* | 
					 | 
					 | 
					 | 
					import kotlinx.coroutines.* | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					class Coroutine<T>() { | 
					 | 
					 | 
					 | 
					class Coroutine<T>(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    companion object { | 
					 | 
					 | 
					 | 
					    companion object { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -13,13 +13,9 @@ class Coroutine<T>() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            return Coroutine(scope, block) | 
					 | 
					 | 
					 | 
					            return Coroutine(scope, block) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        fun <T> plus(coroutine: Coroutine<T>): Coroutine<T> { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            return Coroutine(coroutine) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private var interceptor: Coroutine<T>? = null | 
					 | 
					 | 
					 | 
					    private val job: Job | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private lateinit var job: Job | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private var start: (suspend CoroutineScope.() -> Unit)? = null | 
					 | 
					 | 
					 | 
					    private var start: (suspend CoroutineScope.() -> Unit)? = null | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private var execute: (suspend CoroutineScope.(T?) -> Unit)? = null | 
					 | 
					 | 
					 | 
					    private var execute: (suspend CoroutineScope.(T?) -> Unit)? = null | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -40,80 +36,54 @@ class Coroutine<T>() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    val isCompleted: Boolean | 
					 | 
					 | 
					 | 
					    val isCompleted: Boolean | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        get() = job.isCompleted | 
					 | 
					 | 
					 | 
					        get() = job.isCompleted | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private constructor( | 
					 | 
					 | 
					 | 
					    init { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        scope: CoroutineScope, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        block: suspend CoroutineScope.() -> T | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    ) : this() { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        this.job = scope.plus(Dispatchers.Main).launch { | 
					 | 
					 | 
					 | 
					        this.job = scope.plus(Dispatchers.Main).launch { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            executeInternal(this@launch, block) | 
					 | 
					 | 
					 | 
					            executeInternal(this@launch, block) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private constructor(coroutine: Coroutine<T>) : this() { | 
					 | 
					 | 
					 | 
					    fun timeout(timeMillis: () -> Long): Coroutine<T> { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        this.interceptor = coroutine | 
					 | 
					 | 
					 | 
					        this.timeMillis = timeMillis() | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        this.job = coroutine.job | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun timeout(timeMillis: () -> Long): Coroutine<T> { | 
					 | 
					 | 
					 | 
					    fun timeout(timeMillis: Long): Coroutine<T> { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (this.interceptor != null) { | 
					 | 
					 | 
					 | 
					        this.timeMillis = timeMillis | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.interceptor!!.timeMillis = timeMillis() | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.timeMillis = timeMillis() | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return this@Coroutine | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun onErrorReturn(value: () -> T?): Coroutine<T> { | 
					 | 
					 | 
					 | 
					    fun onErrorReturn(value: () -> T?): Coroutine<T> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (this.interceptor != null) { | 
					 | 
					 | 
					 | 
					        this.errorReturn = Result(value()) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.interceptor!!.errorReturn = Result(value()) | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            errorReturn = Result(value()) | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					    fun onErrorReturn(value: T?): Coroutine<T> { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        this.errorReturn = Result(value) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return this@Coroutine | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun onStart(start: (suspend CoroutineScope.() -> Unit)): Coroutine<T> { | 
					 | 
					 | 
					 | 
					    fun onStart(start: (suspend CoroutineScope.() -> Unit)): Coroutine<T> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (this.interceptor != null) { | 
					 | 
					 | 
					 | 
					        this.start = start | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.interceptor!!.start = start | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.start = start | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return this@Coroutine | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun onExecute(execute: suspend CoroutineScope.(T?) -> Unit): Coroutine<T> { | 
					 | 
					 | 
					 | 
					    fun onExecute(execute: suspend CoroutineScope.(T?) -> Unit): Coroutine<T> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (this.interceptor != null) { | 
					 | 
					 | 
					 | 
					        this.execute = execute | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.interceptor!!.execute = execute | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.execute = execute | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return this@Coroutine | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun onSuccess(success: suspend CoroutineScope.(T?) -> Unit): Coroutine<T> { | 
					 | 
					 | 
					 | 
					    fun onSuccess(success: suspend CoroutineScope.(T?) -> Unit): Coroutine<T> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (this.interceptor != null) { | 
					 | 
					 | 
					 | 
					        this.success = success | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.interceptor!!.success = success | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.success = success | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return this@Coroutine | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun onError(error: suspend CoroutineScope.(Throwable) -> Unit): Coroutine<T> { | 
					 | 
					 | 
					 | 
					    fun onError(error: suspend CoroutineScope.(Throwable) -> Unit): Coroutine<T> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (this.interceptor != null) { | 
					 | 
					 | 
					 | 
					        this.error = error | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.interceptor!!.error = error | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.error = error | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return this@Coroutine | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun onFinally(finally: suspend CoroutineScope.() -> Unit): Coroutine<T> { | 
					 | 
					 | 
					 | 
					    fun onFinally(finally: suspend CoroutineScope.() -> Unit): Coroutine<T> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (this.interceptor != null) { | 
					 | 
					 | 
					 | 
					        this.finally = finally | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.interceptor!!.finally = finally | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } else { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            this.finally = finally | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return this@Coroutine | 
					 | 
					 | 
					 | 
					        return this@Coroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -122,7 +92,7 @@ class Coroutine<T>() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        job.cancel(cause) | 
					 | 
					 | 
					 | 
					        job.cancel(cause) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle{ | 
					 | 
					 | 
					 | 
					    fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return job.invokeOnCompletion(handler) | 
					 | 
					 | 
					 | 
					        return job.invokeOnCompletion(handler) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |