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

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