Simple queue system for redux. Use with redux-thunk.
npm install --save redux-enqueue
Create Store
Create a redux store using the enqueue middleware.
// createStore.jsimport { createStore, applyMiddleware } from 'redux';import thunkMiddleware from 'redux-thunk';import enqueueMiddleware from 'redux-enqueue';const middlewares = applyMiddleware( thunkMiddleware, enqueueMiddleware);return createStore(reducers, initialState, middlewares);
Integrate into Actions
Call await dispatch(enqueue(queueId)), which will return a function that you must call when the action is finished. This will ensure that actions sharing a queueIds will not be run concurrently, but actions with other queueIds may be.
Note that we're using try/finally. This is recommended: the code in the finally block is guaranteed to be run.
The below example will load messages for an id unless they've already been loaded. Fetching messages for different ids can happen concurrently. Fetching for the same id will not be able to happen in parallel, and no subsequent calls for this id will be executed after the first successful run.