in Education by
This question already has answers here: RxJava delay for each item of list emitted (17 answers) Closed 5 years ago. I have an observable I've created from a list of objects. For each object in the list I make a network request but I'd like to put a delay between each item in the list as to space out the requests a bit. Here's a snippet of my code. return Observable.from(documentGroupModels).flatMap(new Func1>() { @Override public Observable call(DocumentGroupModel documentGroupModel) { return refreshDocumentWithUri(documentGroupModel.getUri(), documentGroupModel.sectionGroupId, includeExceptions, false); } }); Using delay or buffer doesn't quite work for this scenario as far as I can tell. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use a combination of Zip and interval operator if your delay is static, so you can emit an item of your zip every time configure on your interval. Check the example @Test public void delaySteps() { long start = System.currentTimeMillis(); Subscription subscription = Observable.zip(Observable.from(Arrays.asList(1, 2, 3)), Observable.interval(200, TimeUnit.MILLISECONDS), (i, t) -> i) .subscribe(n -> System.out.println("time:" + (System.currentTimeMillis() - start))); new TestSubscriber((Observer) subscription).awaitTerminalEvent(3000, TimeUnit.MILLISECONDS); } Also you can create an Observable with your list and use concatMap, then you can use delay for every item emitted. Maybe this solution is more elegant and no so Hacky @Test public void delayObservableList() { Observable.from(Arrays.asList(1, 2, 3, 4, 5)) .concatMap(s -> Observable.just(s).delay(100, TimeUnit.MILLISECONDS)) .subscribe(n -> System.out.println(n + " emitted"), e -> { }, () -> System.out.println("All emitted")); new TestSubscriber().awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); } You can see another examples of delay here https://github.com/politrons/reactive/blob/master/src/test/java/rx/observables/utils/ObservableDelay.java

Related questions

0 votes
    What does stack overflow' refer to? a. accessing item from an undefined stack b. index out of bounds exception ... from an empty stack Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    What does stack overflow' refer to? a. accessing item from an undefined stack b. index out of bounds exception ... from an empty stack Select the correct answer from above options...
asked Nov 29, 2021 in Education by JackTerrance
0 votes
    What is the most efficient way to remove duplicate items from an array under the constraint that axillary ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    What is the most efficient way to remove duplicate items from an array under the constraint that axillary ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    What is the most efficient way to remove duplicate items from an array under the constraint that axillary ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    What is the most efficient way to remove duplicate items from an array under the constraint that axillary ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 8, 2022 in Education by JackTerrance
0 votes
    This question is often asked and resolved in many ways, but if I come back to the same question, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    If end to end delay is given by dend-end = N(dproc + dtrans + dprop) is a non congested network. The number of routers between source and destination is? A. N/2 B. N C. N-1 D. 2N...
asked Jan 8, 2023 in Technology by JackTerrance
0 votes
    What is the use of Observable class? (a) It is used to create global subclasses (b) It is used to ... More Utility Classes of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What is the use of Observable class? (a) It is used to create global subclasses (b) It is used ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    I am newbie to android development and learning it to my own. I have a very strange problem of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am newbie to android development and learning it to my own. I have a very strange problem of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    What is the difference between HttpContext.Current.Items and HttpContext.Current.Session in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    Propagation delay depends on ___________. A. Packet length B. Transmission rate C. Distance between the routers D. Speed of the CPU...
asked Jan 9, 2023 in Technology by JackTerrance
0 votes
    Transmission delay does not depend on _____________. A. Packet length B. Distance between the routers C. Transmission rate D. Bandwidth of medium...
asked Jan 9, 2023 in Technology by JackTerrance
...