Created
October 25, 2018 04:35
-
-
Save jcuffe/d6b50bc8677ab9987c47ac8ff60472bc to your computer and use it in GitHub Desktop.
Making 1000 requests without angering the remote server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ordersEpic = (action$, state$) => action$.pipe( | |
// Listen for this action | |
ofType(type.GET_ORDERS), | |
// Replace the action with the list of active IDs | |
mapTo(state$.value.market.ids), | |
// Turn the list into a stream of ids | |
flatMap(from), | |
// Add a 1 second delay to each emit | |
concatMap(id => of(id).pipe(delay(1000))), | |
// Replace the id with the http response for orders of that id | |
switchMap(id => ajax(endpoints.orders(10000002, id)) | |
.pipe(map(({ response }) => response))), | |
// Send the orders to state storage | |
map(setOrders) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment