Skip to content

Instantly share code, notes, and snippets.

@adamw
Created January 21, 2020 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamw/075818c2777b4dbef57f68cb9901ad16 to your computer and use it in GitHub Desktop.
Save adamw/075818c2777b4dbef57f68cb9901ad16 to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.future.await
import java.util.concurrent.CompletableFuture
internal class Example3(private val database: Database) {
suspend fun activateUser(userId: Long?): Boolean {
val user = database.findUser(userId).await()
if (user != null && !user.isActive) {
database.activateUser(userId).await()
return true
} else {
return false
}
}
}
internal interface Database {
fun findUser(id: Long?): CompletableFuture<User?>
fun activateUser(id: Long?): CompletableFuture<Void?>
}
internal interface User {
val isActive: Boolean
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment