Pablichjenkov
09/03/2019, 8:57 PMFlow
. Or in other words the create
and just
operator equivalents.
Observable
.create(
{ emitter: Emitter<Boolean> ->
// Do stuff and onNext
},
Emitter.BackpressureMode.BUFFER
)
// Also for this
Observable.just(true)
I am using bellow builder but wanted to see other alternatives
flow { flowCollector -> ...// Do stuff and emit }
elizarov
09/03/2019, 9:02 PMObservable.just(x)
-> flowOf(x)
Observable.create { e -> ... e.onNext(x) }
-> flow { ... emit(x) }
elizarov
09/03/2019, 9:03 PMBackpressureMode.BUFFER
-> append .buffer()
operatorPablichjenkov
09/03/2019, 9:04 PMPaul Woitaschek
09/04/2019, 9:36 AMelizarov
09/04/2019, 9:38 AMObservable.create({ e -> ... e.onNext(x) }, BUFFERED)
-> callbackFlow { ... offer(x) }
elizarov
09/04/2019, 9:39 AMcallbackFlow
is buffered by default)Paul Woitaschek
09/04/2019, 9:44 AMnonThreadSafeFlow
instead of flow
😉elizarov
09/04/2019, 9:49 AMFlow
is a sequential, not a thread-safe primitive by design.elizarov
09/04/2019, 9:50 AMChannel
elizarov
09/04/2019, 9:51 AMFlow
-> emit
, Channel
-> `send`/`offer`.Paul Woitaschek
09/04/2019, 10:06 AMemit
says This method is not thread-safe and should not be invoked concurrently.
Paul Woitaschek
09/04/2019, 10:07 AMflow<Int> { emitAll(flowOf(1, 2, 3)) }
And this isnt?
flow<Int> {
coroutineScope {
launch { emitAll(flowOf(1, 2, 3)) }
launch { emitAll(flowOf(1, 2, 3)) }
}
gildor
09/04/2019, 10:25 AMPablichjenkov
09/04/2019, 11:15 PMflow.emitt()
from multiple threads does not garantee the events get pipelined? Is that correct?
Unless the flow is backed up by a channel?