import AsyncQueue from '../utils/asyncQueueStructures';

let asyncQueue = new AsyncQueue();

const endAsync = () => {
  return { type: 'ASYNC_INACTIVE' };
};

const callAsync = (dispatchFn, delay = 500, dispatchEnd, newState) => {
  if (!asyncQueue.size) {
    asyncQueue.listenForEnd(dispatchEnd);
  }
  asyncQueue.add(dispatchFn, delay, newState);
  return { type: 'ASYNC_ACTIVE' };
};

const setDelay = (newDelay) => {
  return {
    type: 'SET_DELAY',
    newDelay
  };
};

export default {
  callAsync,
  endAsync,
  setDelay
};

import AsyncQueue from '../utils/asyncQueueStructures';

let asyncQueue = new AsyncQueue();

const endAsync = () => ({ type: 'ASYNC_INACTIVE' });

const startAsync = () => ({ type: 'ASYNC_ACTIVE' });

const callAsync = (dispatchFn, newState) => (dispatch, getState) => {
  if (!asyncQueue.size) {
    asyncQueue.listenForEnd(dispatch.bind(null, endAsync));
  }
  asyncQueue.add(dispatchFn, getState().async.delay, newState);
  dispatch(startAsync());
};

const setDelay = (newDelay) => {
  return {
    type: 'SET_DELAY',
    newDelay
  };
};

export default {
  callAsync,
  endAsync,
  setDelay,
  startAsync
};

Use thunx to access delay state
Use thunx to access delay state
