問題タブ [rx-java]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
reactive-programming - RxJava: map の代わりに flatMap を使用する実際のライブ シナリオを教えてください
マップの代わりにフラットマップを使用するタイミングがよくわかりません。また、良い例も見つかりません。
マップではなくフラット マップを選択するための適切なシナリオを思いつくことができますか?
ありがとう。
scala - `observeOn` メソッドの `Scheduler` を作成するにはどうすればよいですか?
Scala プロジェクトで RxJava を使用してObservable
おり、別のスレッドで実行する必要があります。observeOn
これを実現するには、メソッドを呼び出して、のインスタンスをrx.lang.scala.Scheduler
引数として渡す必要があることを知っています。
しかし、どうすればそのインスタンスを作成できますか? rx.lang.scala.Scheduler
トレイトをインスタンス化する明らかな方法は見つかりませんでした。たとえば、次のコードがあります。
Observable.from(List(1,2,3)).observeOn(scheduler)
scheduler
誰かがトリックを行う作業変数の例を提供できますか?
multithreading - 別のスレッドで `Observable` を実行するにはどうすればよいですか?
私は Scala プロジェクトで RxJava を使用しており、この単純なものがあると言いますObservable
:
while
スレッドがブロックされているため、「hello」メッセージが表示されません。Observable
ブロックを回避するために別のスレッドで実行するにはどうすればよいですか?
==================================
私はobserveOn
助けることができると思っていましたが、そうではありません。これを実行する:
...まだ「こんにちは」を出力しません。observeOn
make を追加すると、ブロック自体 OnNext
ではなく別のスレッドで呼び出されると思いますか?while
==================================
もちろん、次のようにラップwhile
することもできFuture
ます。
しかし、おそらく、これを行う rx 慣用的な方法が他にも存在しますか?
reactive-programming - Observable から BehaviorSubject を作成する
observableA
重いネットワークからデータを要求しようとするたびに、このオブザーバブルを購読すると、ネットワークからデータを取得して発行する があるとします。
BehaviorSubject を作成して observableA に接続し、他のスレッド/オブジェクトが BehaviorSubject をサブスクライブして、最新の出力データを取得できるようにします。
これまでのところ、コードを管理できませんでした。空の BehaviorSubject を作成して observableA 内で呼び出すことはできません。これらは互いに関連していないためです。observableA にサブスクライブできず、BehaviorSubject をオブザーバーとして取得できません。どうすれば達成できますか? それとももっと良いですか?
algorithm - 非同期、早期終了、連結 Observable
A、B、およびCの3 つのオブザーバブルがあるとします。3つすべてを同時に実行する必要があります(素人の場合は非同期で)が、次のとおりです。
- Aから何かを取得した場合は、それを発行します...他には何も発行しないでください。
- Aが何も発行せずに完了した場合、ルール 1 をBに適用します。
- Bが何も発行せずに完了した場合、 Cから項目を発行します。
- Cが何も発行せずに完了した場合、デフォルト項目を発行します。
私は昨日これを理解しようと何時間も費やしましたが、これを可能にする操作上の組み合わせがRxJavaには既にないようです。
左から右にカスケードする値を考えることができます。
A --> B --> C
また、カスケードはブロックされますが、それぞれが非同期で実行され、値がキャッシュされます。
A (何もない) --> B (何もない) --> C (何もない) --> デフォルト項目
明確にするために、Aは、他のオブザーバーから何かが発行される前に完了する必要があります。A、B、C が何も出力しない場合、B、C の同じロジックがデフォルトになります。
明らかにキャッシュが含まれており、オブザーバブルをリプレイしたくありません。キャッシュされた値を再生する必要があります。それは各ゲートで開催されます。
動作はconcat()と非常に似ていますが、チェーンの次の部分は、その前にエミッションがあった場合に解き放たれることはありません。
scala - ヘッドがサブスクリプションをキャンセルしない理由
Observable
次のものがあるとしましょうrxjava-scala-0.18.4
2 番目のアサーションは失敗します。つまり、head
サブスクライブは解除されません。Observables の私の理解は間違っていますか、それともhead
最初の要素が発行された後に登録を解除する必要がありますか?
android - Handling API exceptions in RxJava
I'm trying to wrap my head around RxJava currently, but I'm having a little trouble with handling service call exceptions in an elegant manner.
Basically, I have a (Retrofit) service that returns an Observable<ServiceResponse>
. ServiceResponse
is defined like so:
Now what I want is to map that generic response to a List<Account>
contained within the data JsonElement field (I assume you don't care what the Account
object looks like, so I won't pollute the post with it). The following code works really well for the success case, but I can't find a nice way to handle my API exceptions:
Is there a better way to do this? This does work, onError will fire to my observer, and I will receive the error that I threw, but it definitely does not seem like I'm doing this right.
Thanks in advance!
Edit:
Let me clarify exactly what I want to achieve:
I want to have a class that can be called from the UI (e.g. an Activity, or Fragment, or whatever). That class would take an Observer<List<Account>>
as a parameter like so:
That method would return a subscription that can be unsubscribed when the UI is detached/destroyed/etc.
The parameterized observer would handle onNext for the successful responses passing in a list of Accounts. OnError would handle any exceptions, but would also get passed any API exceptions (e.g. if the response status != 200 we would create a Throwable and pass it to onError). Ideally I don't want to just "throw" the Exception, I want to pass it directly to the Observer. That's what all the examples I see do.
The complication is that my Retrofit service returns a ServiceResponse
object, so my observer cannot subscribe to that. The best I've come up with is to create an Observer wrapper around my Observer, like so:
I still feel like I am not using this correctly though. I definitely haven't seen anyone else using an ObserverWrapper before. Perhaps I shouldn't be using RxJava, though the guys at SoundCloud and Netflix really sold me on it in their presentations and I'm pretty eager to learn it.
java - async Observable が完了するのを待つ方法
rxjava を使用してサンプルをビルドしようとしています。このサンプルは、 ReactiveWareService と ReactiveReviewService を調整して WareAndReview コンポジットを返す必要があります。
Observable を返したくないという事実を考えると、非同期 Observable (findReviewsByItem) が完了するのをどのように待つことができますか?