Created
January 14, 2020 19:15
-
-
Save oscarg798/3dca6b80b2f2d200ae922e6e45958ff3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val m : (Int, Int) -> Unit = {x, y -> | |
print("::::$x $y") | |
} | |
CoroutineScope(Dispatchers.Default).launch { | |
print("Corutine 1 $this\n") | |
val mm = this | |
withContext(Dispatchers.IO) { | |
print("Corutine 2 $this\n") | |
print("Corutine 3 $this\n") | |
val x = async(Dispatchers.IO){ | |
delay(100) | |
print("Corutine 4 $this ${Thread.currentThread()}\n") | |
mm.cancel() | |
4 | |
} | |
val y = async(Dispatchers.Unconfined){ | |
delay(200) | |
print("Corutine 5 $this ${Thread.currentThread()}\n") | |
3 | |
} | |
m.invoke(x.await(), y.await()) | |
} | |
} | |
CoroutineScope(Dispatchers.Default).launch { | |
print("Corutine 1 $this\n") | |
val mm = this | |
runBlocking { | |
print("Corutine 2 $this\n") | |
print("Corutine 3 $this\n") | |
val x = async(Dispatchers.IO){ | |
delay(100) | |
print("Corutine 4 $this ${Thread.currentThread()}\n") | |
mm.cancel() | |
4 | |
} | |
val y = async(Dispatchers.Unconfined){ | |
delay(200) | |
print("Corutine 5 $this ${Thread.currentThread()}\n") | |
3 | |
} | |
m.invoke(x.await(), y.await()) | |
} | |
} | |
//This one will not block the parent coroutine |
Author
oscarg798
commented
Jan 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment