Skip to content

Instantly share code, notes, and snippets.

@objcode
Last active May 21, 2019 08:00
Show Gist options
  • Save objcode/6c6896031fc3a9665b46d7e6e56c4385 to your computer and use it in GitHub Desktop.
Save objcode/6c6896031fc3a9665b46d7e6e56c4385 to your computer and use it in GitHub Desktop.
Example version of cancelPreviosThenRun.
// see the complete implementation at
// https://gist.github.com/objcode/7ab4e7b1df8acd88696cb0ccecad16f7
suspend fun cancelPreviousThenRun(block: suspend () -> T): T {
// If there is an activeTask, cancel it because it's result is no longer needed
activeTask?.cancelAndJoin()
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment