Created
August 20, 2016 00:46
-
-
Save bangarharshit/4e5899c565be6a0686a49fec820bcec1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rx.Observable; | |
import java.util.Queue; | |
import java.util.concurrent.ConcurrentLinkedQueue; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.ScheduledExecutorService; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* Created by harshitbangar on 19/08/16. | |
*/ | |
public class QueueLibraryManager { | |
Queue<QueueLibrary> strings = new ConcurrentLinkedQueue<QueueLibrary>(); | |
public Observable<String> addToQueue(String s) { | |
QueueLibrary queueLibrary = new QueueLibrary(s); | |
strings.add(queueLibrary); | |
return queueLibrary.stringPublishSubject; | |
} | |
public QueueLibraryManager() { | |
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); | |
exec.scheduleAtFixedRate(new Runnable() { | |
@Override | |
public void run() { | |
while (!strings.isEmpty()) { | |
QueueLibrary queueLibrary = strings.poll(); | |
queueLibrary.stringPublishSubject.onNext(queueLibrary.s); | |
} | |
} | |
}, 0, 5, TimeUnit.SECONDS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment