Provide a Mechanism for Simpler Batch Requests #44

Open
opened 2020-06-11 04:04:14 +01:00 by SethFalco · 0 comments
SethFalco commented 2020-06-11 04:04:14 +01:00 (Migrated from gitlab.com)

The following is currently how one can perform batch requests.

/** It's even possible to perform batch requests! */                                                                                 
public static void batchExample() {                                                                                                                               
    List<Observable<Player>> requests = Stream.of("SethX3", "Rheannon")                      
        .map(osu::getPlayer)                                                       
        .map(Maybe::toObservable)                                                  
        .collect(Collectors.toList());                                             
                                                                                       
    Observable<List<Player>> singlePlayers = Observable.zip(requests, (objects) -> 
        Stream.of(objects).map((o) -> (Player)o).collect(Collectors.toList())      
    );                                                                             

    singlePlayers.subscribe((players) -> players.forEach(System.out::println));    
}                                                                                  

This is a bit on the bulky side, while it's trivial to further simplify how to do this we should provide a utility method to make batch requests easier, for example, something like:

public static void batchRequests() {                                                
    List<Maybe<Player>> requests = Stream.of("SethX3", "Rheannon")
        .map(osu::getPlayer())
        .collect(Collectors.toList());

    Single<List<Player>> batch = RxUtils.batch(requests);            
    batch.subscribe((players) -> players.forEach(System.out::println));    
}                                                                                  

Preferably something a little more fluent, but the above was just for showing some kind of example.

The following is currently how one can perform batch requests. ```java /** It's even possible to perform batch requests! */ public static void batchExample() { List<Observable<Player>> requests = Stream.of("SethX3", "Rheannon") .map(osu::getPlayer) .map(Maybe::toObservable) .collect(Collectors.toList()); Observable<List<Player>> singlePlayers = Observable.zip(requests, (objects) -> Stream.of(objects).map((o) -> (Player)o).collect(Collectors.toList()) ); singlePlayers.subscribe((players) -> players.forEach(System.out::println)); } ``` This is a bit on the bulky side, while it's trivial to further simplify how to do this we should provide a utility method to make batch requests easier, for example, something like: ```java public static void batchRequests() { List<Maybe<Player>> requests = Stream.of("SethX3", "Rheannon") .map(osu::getPlayer()) .collect(Collectors.toList()); Single<List<Player>> batch = RxUtils.batch(requests); batch.subscribe((players) -> players.forEach(System.out::println)); } ``` Preferably something a little more fluent, but the above was just for showing some kind of example.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
SethFalco/elypiai#44
No description provided.