Skip to content

Instantly share code, notes, and snippets.

@bjonnh
Created February 11, 2019 20:24
Show Gist options
  • Save bjonnh/e561789061e9738776676b7530bd484d to your computer and use it in GitHub Desktop.
Save bjonnh/e561789061e9738776676b7530bd484d to your computer and use it in GitHub Desktop.
fun run(): arrow.core.Tuple2<IO<ResultSet>, () -> kotlin.Unit> {
val (localExec, cancelQuery) = fxCancellable {
createQueryExecutionInExternalLib(…Some query…) // returns immediately with an object that allows to abort
}
val (localResult, cancelResult) = fxCancellable {
localExec.bind().executequery() // Blocking task
}
return fx { localResult.bind() } toT {
cancelQuery()
cancelResult()
fx { localExec.bind().abort() }.unsafeRunSync()
} // Here I return a function for the cancellable, that allows me to cancel all the tasks (and call the abort on the object for cleanup)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment