Created
October 23, 2020 10:50
-
-
Save latant/54ed54f21565072d7259aa629db853fe to your computer and use it in GitHub Desktop.
A coroutine function that suspends until a shutdown is requested
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
| import kotlin.concurrent.thread | |
| import kotlin.coroutines.resume | |
| import kotlin.coroutines.suspendCoroutine | |
| suspend fun awaitShutdown() { | |
| suspendCoroutine<Unit> { c -> | |
| Runtime.getRuntime().addShutdownHook(thread(start = false) { | |
| c.resume(Unit) | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment