import { actionPending } from "./actionPending";
import { actionResolved } from "./actionResolved";
import { actionRejected } from "./actionRejected";

export const actionPromise = (name, promise) => async (dispatch) => {
  dispatch(actionPending(name));
  try {
    let payload = await promise;
    dispatch(actionResolved(name, payload));
    return payload;
  } catch (error) {
    dispatch(actionRejected(name, error));
  }
};
