I'm using PromiseKit 6
to make async requests. Think paginated requests:
api/v1/resource?
api/v1/resource?offset=5
api/v1/resource?offset=10
...
api/v1/resource?offset=50
What I do currently is this:
let paginatedResources: [Promise<Car>] = (0...<50).map({
self.getPaginatedCar(offset: $0)
})
when(fulfilled: paginatedResources).compactMap { cars in
print(cars)
}
This works fine and all, but now my pages are going be a lot higher than this (think like 100 paginated requests that need to be done). This causes a problem because as I make too many requests at a same time, more and more of them fail. I want to maybe break that down a little bit.
For example, if I have to make 100 requests, I'll probably chunk them to 10 requests at a time. How do I chain my when(fulfilled:)
?
I'm thinking something like, but it's obviously not the right way to do this...
when(fulfilled: paginatedResources).compactMap { p in
when(fulfilled: paginatedResources).compactMap { p in
when(fulfilled: paginatedResources).compactMap { p in
when(fulfilled: paginatedResources).compactMap { p in
when(fulfilled: paginatedResources).compactMap { p in
}
}
}
}
}