Created
November 2, 2022 16:15
-
-
Save BetterProgramming/8777b652b88053f8a3f90136db9cfbe5 to your computer and use it in GitHub Desktop.
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
val stateJob = flowToCallback( | |
adapterScope, speechRecognizerStateFlow, | |
speechRecognizerStateCallback | |
) | |
fun <T> flowToCallback(scope: CoroutineScope, flow: Flow<T>, | |
callback: Consumer<T>): Job { | |
return scope.launch { | |
try { | |
flow.collect { | |
// invokes the closure which will call C calback | |
callback.accept(it) | |
} | |
} catch (e: CancellationException) { | |
println("collect cancelled") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment