Last active
October 25, 2017 14:50
-
-
Save droibit/4ec6da9be8742f7b3c3ee1acac29ffcf to your computer and use it in GitHub Desktop.
Sample of combine coroutine context.
This file contains hidden or 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 parentJob = Job() | |
launch(parentJob + CommonPool) { | |
try { | |
Timber.d("[${Thread.currentThread().name}]: start job1.") | |
delay(1500L) | |
Timber.d("[${Thread.currentThread().name}]: stop job2.") | |
} catch (e: CancellationException) { | |
Timber.d("[${Thread.currentThread().name}]: cancel job1.") | |
} | |
} | |
launch(parentJob + CommonPool) { | |
try { | |
Timber.d("[${Thread.currentThread().name}]: start job2.") | |
delay(1050L) | |
Timber.d("[${Thread.currentThread().name}]: stop job2.") | |
} catch (e: CancellationException) { | |
Timber.d("[${Thread.currentThread().name}]: cancel job2.") | |
} | |
} | |
launch { | |
delay(1000) | |
parentJob.cancel() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment