Asynchronous – rxjava adds items after creating observable

I just started using RX Java and I got stuck Maybe I don't use rxjava in the right way, but I need to add it to observable. Java after creation So I understand that you can call observable Just ("some", "items"), subscribers will receive them, but if I have an asynchronous task, I need to add some items in a later task. Are you finished? I can't find anything like observable Additems ("some", "more", "items")

Solution

What you may need is a theme – http://reactivex.io/documentation/subject.html

It is an object, both observer and observable, so you can subscribe to it and send out new items For example:

PublishSubject<String> subject = PublishSubject.create();
subject.subscribe(System.out::println);
subject.onNext("Item1");
subject.onNext("Item2");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>