Let’s get started with fast clarification of prefix operator and then create our customized takeUntil writer operator.
Discard any pieces emitted via an upstream writer after a 2d writer emits an merchandise.
This definition with the exception of the phase that mentions, “takeUntil operator additionally terminates upstream writer if 2d writer emits termination or error out” is taken from (*2*)takeUntil operator definition of ReactiveX. (*1*)PrefixUntilOutput doesn’t put in force this option simply asand with our customized takeUntil writer, we will be able to attempt to put in force it.
On above take a look at, downstream subscriber won simplest [0, 1] values which might be despatched after 1 2d. It were given crowning glory 2 seconds later via price that finisher topic despatched. Values after which might be left out. Simply PrefixUntilOutput operator writer ignores occasions after finisher emits price.
However I were given some surprising behaviors on my prefixUntil checks. Based on used scheduler on subscribe(on:) manner, occasionally there are order of execution issues. Sometimes downstream subscriber couldn’t emit .completed tournament as a result of finisher topic emits price prior to downstream subscriber will get subscription object and occasionally if finisher is started working on serial dispatch queue, it would ship crowning glory tournament with out downstream subscriber will get subscription object and requests call for for it.
It seems like within obtain(subscriber:) manner of PrefixUntilOutput writer, finisher and supply publishers get started prior to offering subscription to downstream subscriber and getting call for request.
Above take a look at, emits all values from supply publishers and in spite of everything receives crowning glory tournament. Finisher writer doesn’t ship any price to break upstream writer. However if we need to exchange our PassthroughSubject with a CurrentValueSubject, then as CurrentValueSubject holds a price to begin with, we think our upstream writer to obtain crowning glory prior to emitting any price from supply writer.
(*5*)However checks occasionally fail if schedulers that they have got known as on subscribe(on:) manner, aren’t correctly configured.
On above implementation, if we simplest exchange PassthroughSubject with CurrentValueSubject then all publishers subscribe on present scheduler which is major queue. Based on following output, PrefixUntilOutput writer begins with finisher writer subscription. After finisher subscription is won, it requests call for as .max(1) and receives price this is outlined to begin with on CurrentValueSubject. After emitting price, it tries to ship crowning glory tournament to downstream subscriber even prior to supply and prefixUntil subscriptions are equipped. Normally upstream writer receives subscription after supply has won its subscription if all of them run on serial schedulers.
In present implementation of PrefixUntilOutput writer, it instantly tries to ship completed tournament to downstream subscriber. However even downstream subscriber emits crowning glory in this case. if we set scheduler on supply and upstream writer the usage of subscribe(on:) then downstream subscriber doesn’t emit crowning glory as it has no longer won subscription but;
Finisher begins subscription on scheduler this is set via upstream writer, and couldn’t ship completed tournament to downstream subscriber effectively.
It is in reality bizarre edge case that may create issues if upstream execution doesn’t fulfill timing.