Created
January 21, 2020 12:07
-
-
Save adamw/075818c2777b4dbef57f68cb9901ad16 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
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