I'm trying to use Flow inside a CoroutineWorker (WorkManager) and the flow should be listening for a value in the repository for 5 seconds, if you get the value within that time frame you return Result.success()
and then ignore/cancel the timer, if the time passed you return Result.failure()
.
Right now I have something like that and I'm trying to incorporate the timeout there.
repository.getListeningValue.onEach {
//doStuff here with the result
}.map{
Result.success()
}.first()