Maciek
12/11/2020, 4:54 PMdoWork
during the work being done for the first entity I want it to be queued and wait for it to be finished. At first, I was trying to figure out some clever internal queue based on subject, but failed. Then I thought that simple semaphore will do the job just fine (but also will block the thread). Do you see any problems with such implementations or can it be achieved with similar simplicity with streams without thread blocking?
class Foo {
private val sem = Semaphore(permit = 1)
fun doWork(): Completable =
Completable.fromCallable { sem.acquire() }
.andThen { doWorkInternal() }
.doOnError { sem.release() }
.doOnComplete { sem.release() }
}
alexsullivan114
12/11/2020, 8:28 PMSubject
. Every time you want to do some "work", you pipe a value through the subject. Then you subscribe to that subject and flatmap to your completable. Natural queuing/ordering ensues.StavFX
12/12/2020, 1:29 AMandThen
with curly braces instead of parens