rxjava delay: How to get variable delay on each item emitted from a list?

abhimskywalker

I want to have custom delays between each item emitted from an observable list as a function of the items themselves. Let's say we have a list as (item, delay):

[("item1", 2),("item2", 1),("item3", 2),("item4", 3),("item5", 2),("item6", 3)]

I want output to be something like:

0 seconds: 
1 seconds: 
item1
2 seconds: 
item2
3 seconds: 
4 seconds: 
item3
5 seconds: 
6 seconds: 
7 seconds: 
item4
8 seconds: 
9 seconds: 
item5
10 seconds: 
11 seconds: 
12 seconds: 
item6
Completed!
13 seconds: 

I am not sure how to best accomplish this with delay/timer operators. Went through delay documentation but couldn't figure out a straightforward way. Any pointers would be helpful. Thanks!

JohnWowUs

No need for anything fancy. Just use concatMap and delay operators

jla.concatMap(s -> Observable.just(s).delay(s.delay, TimeUnit.SECONDS))           
  .subscribe(s1 -> System.out.println(s1.name + " just came..."), 
             e -> {}, 
             () -> System.out.println("Everybody came!")); 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

RxJava delay for each item of list emitted

From Dev

How to emit items from list with delay between each item?

From Dev

How to emit items from list with delay between each item?

From Dev

Delay items emission until item is emitted from another observable

From Dev

How to emit items from a Collection with delay in RxJava?

From Dev

How to emit items from a Collection with delay in RxJava?

From Dev

How remove item from RecyclerView with delay

From Dev

How to delay blits being iterated from a list

From Dev

How to delay jQuery Waypoint for each item in order to create staggering effect?

From Dev

How to get frame delay from animated gif?

From Dev

How to add each item into List in RxJava Android

From Dev

How to make variable delay/sleep in JQuery for each loop

From Dev

how to get first element without any delay and delay from the second element?

From Dev

RxJava + retrofit, get a List and add extra info for each item

From Dev

SASS, animate each list items with a delay

From Dev

How to get AngularStrap delay working?

From Dev

How to get total delay from two columns group by day?

From Dev

How to insert delay between each requests in Jmeter

From Dev

Get the longest item from each element of the list

From Dev

How to get how many of each item is in a list?

From Dev

How can I toggle the value of a variable with a delay?

From Dev

How can I toggle the value of a variable with a delay?

From Dev

(After a click event) how to open a list of links in new tabs with a delay after each opening

From Dev

(After a click event) how to open a list of links in new tabs with a delay after each opening

From Dev

How to get user lock / screensaver delay?

From Dev

How to delay pygame.key.get_pressed()?

From Dev

How to get my shot delay to work

From Dev

Open a list of URLs each with 20-30s delay

From Dev

makefile delay variable expansion

Related Related

  1. 1

    RxJava delay for each item of list emitted

  2. 2

    How to emit items from list with delay between each item?

  3. 3

    How to emit items from list with delay between each item?

  4. 4

    Delay items emission until item is emitted from another observable

  5. 5

    How to emit items from a Collection with delay in RxJava?

  6. 6

    How to emit items from a Collection with delay in RxJava?

  7. 7

    How remove item from RecyclerView with delay

  8. 8

    How to delay blits being iterated from a list

  9. 9

    How to delay jQuery Waypoint for each item in order to create staggering effect?

  10. 10

    How to get frame delay from animated gif?

  11. 11

    How to add each item into List in RxJava Android

  12. 12

    How to make variable delay/sleep in JQuery for each loop

  13. 13

    how to get first element without any delay and delay from the second element?

  14. 14

    RxJava + retrofit, get a List and add extra info for each item

  15. 15

    SASS, animate each list items with a delay

  16. 16

    How to get AngularStrap delay working?

  17. 17

    How to get total delay from two columns group by day?

  18. 18

    How to insert delay between each requests in Jmeter

  19. 19

    Get the longest item from each element of the list

  20. 20

    How to get how many of each item is in a list?

  21. 21

    How can I toggle the value of a variable with a delay?

  22. 22

    How can I toggle the value of a variable with a delay?

  23. 23

    (After a click event) how to open a list of links in new tabs with a delay after each opening

  24. 24

    (After a click event) how to open a list of links in new tabs with a delay after each opening

  25. 25

    How to get user lock / screensaver delay?

  26. 26

    How to delay pygame.key.get_pressed()?

  27. 27

    How to get my shot delay to work

  28. 28

    Open a list of URLs each with 20-30s delay

  29. 29

    makefile delay variable expansion

HotTag

Archive