S
S
sanke462020-05-09 11:05:31
Java
sanke46, 2020-05-09 11:05:31

How to make N-number of requests and send their result to the server [RXjava]?

Request to create tags = N (any) number of requests for the same thing, for example, create a tag (the request returns the created tag with an ID)
Saving a list of tags to the user = One request in which you need to fit a list of results from tags (list of IDs)

How to implement it correctly such an idea in RXjava?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WelloGraphics, 2020-05-14
@sanke46

If I understand the question correctly, then something like this.

Single<Long> createTag(String tag) {
// creating tag, returning long id
}

Single<List<Long>> createTags(List<String> tags) {
    return Observable.fromIterable(tags)
        .flatMap(this::createTag)
        .toList();
}

Completable attachTagsToUser(List<String> tags, User user) {
    return createTags(tags)
        .flatMapCompletable(tagIds -> /* do what you want, here the ids */);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question