Created
December 17, 2017 21:07
-
-
Save abdurahmanadilovic/7ecf111a161faba5cbf2e17eb1922aa5 to your computer and use it in GitHub Desktop.
suspendCoroutine example with firebase
This file contains 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
override suspend fun getBooleanValue(key: String, default: Boolean): Boolean = suspendCoroutine { continuation -> | |
fireBaseDb.child("keys").child(key).addListenerForSingleValueEvent(object : ValueEventListener { | |
override fun onCancelled(p0: DatabaseError?) { | |
continuation.resume(default) | |
} | |
override fun onDataChange(p0: DataSnapshot?) { | |
if (p0 != null) { | |
continuation.resume(p0.getValue(Boolean::class.java) ?: default) | |
} else { | |
continuation.resume(default) | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment