Created
July 24, 2022 12:37
-
-
Save devrath/76fe776f3f130a700fdf89b4c4f7902f to your computer and use it in GitHub Desktop.
Sample for callback returning from flow
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
| 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