Bläddra i källkod

删除fastest函数接受者

drake 3 år sedan
förälder
incheckning
ff0d10304d
1 ändrade filer med 6 tillägg och 8 borttagningar
  1. 6 8
      net/src/main/java/com/drake/net/utils/Fastest.kt

+ 6 - 8
net/src/main/java/com/drake/net/utils/Fastest.kt

@@ -31,12 +31,11 @@ import java.util.concurrent.CancellationException
  * @param group 指定该值将在成功返回结果后取消掉对应uid的网络请求
  * @param group 指定该值将在成功返回结果后取消掉对应uid的网络请求
  * @param listDeferred 一系列并发任务
  * @param listDeferred 一系列并发任务
  */
  */
-@OptIn(ExperimentalCoroutinesApi::class)
 @Suppress("SuspendFunctionOnCoroutineScope")
 @Suppress("SuspendFunctionOnCoroutineScope")
-suspend fun <T> CoroutineScope.fastest(
+suspend fun <T> fastest(
     listDeferred: List<Deferred<T>>,
     listDeferred: List<Deferred<T>>,
     group: Any? = null
     group: Any? = null
-): T {
+): T = coroutineScope {
     val deferred = CompletableDeferred<T>()
     val deferred = CompletableDeferred<T>()
     if (listDeferred.isNullOrEmpty()) {
     if (listDeferred.isNullOrEmpty()) {
         deferred.completeExceptionally(IllegalArgumentException("Fastest is null or empty"))
         deferred.completeExceptionally(IllegalArgumentException("Fastest is null or empty"))
@@ -61,7 +60,7 @@ suspend fun <T> CoroutineScope.fastest(
             }
             }
         }
         }
     }
     }
-    return deferred.await()
+    deferred.await()
 }
 }
 
 
 
 
@@ -75,12 +74,11 @@ suspend fun <T> CoroutineScope.fastest(
  * @param listDeferred 一系列并发任务
  * @param listDeferred 一系列并发任务
  */
  */
 @JvmName("fastestTransform")
 @JvmName("fastestTransform")
-@OptIn(ExperimentalCoroutinesApi::class)
 @Suppress("SuspendFunctionOnCoroutineScope")
 @Suppress("SuspendFunctionOnCoroutineScope")
-suspend fun <T, R> CoroutineScope.fastest(
+suspend fun <T, R> fastest(
     listDeferred: List<DeferredTransform<T, R>>?,
     listDeferred: List<DeferredTransform<T, R>>?,
     group: Any? = null
     group: Any? = null
-): R {
+): R = coroutineScope {
     val deferred = CompletableDeferred<R>()
     val deferred = CompletableDeferred<R>()
     if (listDeferred.isNullOrEmpty()) {
     if (listDeferred.isNullOrEmpty()) {
         deferred.completeExceptionally(IllegalArgumentException("Fastest is null or empty"))
         deferred.completeExceptionally(IllegalArgumentException("Fastest is null or empty"))
@@ -108,5 +106,5 @@ suspend fun <T, R> CoroutineScope.fastest(
             }
             }
         }
         }
     }
     }
-    return deferred.await()
+    deferred.await()
 }
 }