Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A queue of background tasks in rxjava

Is it possible to implement a queue of background tasks using rxjava? I need possibility to add task at any time and only one tasks executed simultaneously. I have tried PublishSubject, but when i'm pushing execution to the new thread observeOn(Schedulers.newThread()) it starts more than one task at time.

UPDATE: Is it possible to implement something like producer-consumer pattern using rxjava?

like image 370
MightySeal Avatar asked Jul 16 '15 07:07

MightySeal


1 Answers

Just use a scheduler based on a single thread executor:

Scheduler scheduler = Schedulers.from(Executors.newSingleThreadExecutor());
observable.observeOn(scheduler). ...
like image 84
Dave Moten Avatar answered Nov 16 '22 21:11

Dave Moten