Fix "redundant async" for coroutines 1.*, forbid explicit scopes case
Related to KT-28504 #KT-28445 Fixed
This commit is contained in:
+15
-15
@@ -6,7 +6,9 @@ interface Deferred<T> {
|
||||
|
||||
interface CoroutineContext
|
||||
|
||||
object DefaultDispatcher : CoroutineContext
|
||||
object Dispatchers {
|
||||
object Default : CoroutineContext
|
||||
}
|
||||
|
||||
enum class CoroutineStart {
|
||||
DEFAULT,
|
||||
@@ -15,30 +17,28 @@ enum class CoroutineStart {
|
||||
UNDISPATCHED
|
||||
}
|
||||
|
||||
interface Job
|
||||
|
||||
fun <T> async(
|
||||
context: CoroutineContext = DefaultDispatcher,
|
||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||
parent: Job? = null,
|
||||
f: suspend () -> T
|
||||
): Deferred<T> {
|
||||
TODO()
|
||||
interface CoroutineScope {
|
||||
val coroutineContext: CoroutineContext get() = Dispatchers.Default
|
||||
}
|
||||
|
||||
fun <T> runBlocking(
|
||||
context: CoroutineContext = DefaultDispatcher,
|
||||
f: suspend () -> T
|
||||
) {
|
||||
object GlobalScope : CoroutineScope
|
||||
|
||||
fun <T> CoroutineScope.async(
|
||||
context: CoroutineContext = Dispatchers.Default,
|
||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||
block: suspend CoroutineScope.() -> T
|
||||
): Deferred<T> {
|
||||
TODO()
|
||||
}
|
||||
|
||||
suspend fun <T> withContext(
|
||||
context: CoroutineContext,
|
||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||
f: suspend () -> T
|
||||
block: suspend CoroutineScope.() -> T
|
||||
) {
|
||||
TODO()
|
||||
}
|
||||
|
||||
suspend fun <R> coroutineScope(block: suspend CoroutineScope.() -> R): R = GlobalScope.block()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// PROBLEM: none
|
||||
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test(ctx: CoroutineContext, scope: CoroutineScope) {
|
||||
// Does not work yet (1.3.11)
|
||||
scope.<caret>async(ctx) { 42 }.await()
|
||||
}
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
// PROBLEM: none
|
||||
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test(ctx: CoroutineContext) {
|
||||
<caret>async(parent = null) { 42 }.await()
|
||||
// Does not work yet (1.3.11)
|
||||
GlobalScope.<caret>async(ctx) { 42 }.await()
|
||||
}
|
||||
@@ -4,5 +4,7 @@
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test(ctx: CoroutineContext) {
|
||||
<caret>async(ctx) { 42 }.await()
|
||||
coroutineScope {
|
||||
<caret>async(ctx) { 42 }.await()
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,7 @@
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test(ctx: CoroutineContext) {
|
||||
withContext(ctx) { 42 }
|
||||
coroutineScope {
|
||||
withContext(ctx) { 42 }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// FIX: Merge call chain to 'withContext(DefaultDispatcher)'
|
||||
// FIX: Merge call chain to 'withContext(Default)'
|
||||
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test() {
|
||||
<caret>async { 42 }.await()
|
||||
coroutineScope {
|
||||
<caret>async { 42 }.await()
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// FIX: Merge call chain to 'withContext(DefaultDispatcher)'
|
||||
// FIX: Merge call chain to 'withContext(Default)'
|
||||
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test() {
|
||||
withContext(DefaultDispatcher) { 42 }
|
||||
coroutineScope {
|
||||
withContext(Dispatchers.Default) { 42 }
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -3,5 +3,7 @@
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test(ctx: CoroutineContext) {
|
||||
<caret>async(ctx, CoroutineStart.LAZY) { 42 }.await()
|
||||
coroutineScope {
|
||||
<caret>async(ctx, CoroutineStart.LAZY) { 42 }.await()
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -3,5 +3,7 @@
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test(ctx: CoroutineContext) {
|
||||
withContext(ctx, CoroutineStart.LAZY) { 42 }
|
||||
coroutineScope {
|
||||
withContext(ctx, CoroutineStart.LAZY) { 42 }
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -4,5 +4,7 @@
|
||||
package kotlinx.coroutines
|
||||
|
||||
suspend fun test(ctx: CoroutineContext) {
|
||||
<caret>async(start = CoroutineStart.LAZY) { 42 }.await()
|
||||
coroutineScope {
|
||||
<caret>async(start = CoroutineStart.LAZY) { 42 }.await()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user