Last active
December 21, 2018 06:22
-
-
Save SUPERCILEX/ebacfb46c24156c7af020da63cf37822 to your computer and use it in GitHub Desktop.
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
public suspend inline fun <T : Closeable?, R> T.useCancellably( | |
crossinline block: (T) -> R | |
): R = suspendCancellableCoroutine { cont -> | |
cont.invokeOnCancellation { this?.close() } | |
cont.resume(use(block)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment