Skip to content

Instantly share code, notes, and snippets.

@devrath
Created July 24, 2022 12:37
Show Gist options
  • Select an option

  • Save devrath/76fe776f3f130a700fdf89b4c4f7902f to your computer and use it in GitHub Desktop.

Select an option

Save devrath/76fe776f3f130a700fdf89b4c4f7902f to your computer and use it in GitHub Desktop.
Sample for callback returning from flow
fun readMessage(dialog: QBChatDialog): Flow<ArrayList<QBChatMessage>> {
val historyDeferred = CompletableDeferred<ArrayList<QBChatMessage>>()
chatHelper.ReadChatHistory(dialog, object : QBEntityCallback<ArrayList<QBChatMessage>> {
override fun onSuccess(listmessage: ArrayList<QBChatMessage>?, p1: Bundle?) {
historyDeferred.complete(listmessage ?: arrayListOf())
}
override fun onError(p0: QBResponseException?) {
historyDeferred.completeExceptionally(p0 ?: CancellationException())
}
})
return flow {
try {
emit(historyDeferred.await())
} catch (e: Exception) {
Log.e(TAG, "Reading Message Exceptionn: $e")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment