Closed tiggem1993 closed 3 years ago
Does dispatch() return an async function?
Does dispatch() return an async function?
Hi @aearly , I am not sure, but since I have change my logic and the bug is resolved. You can go through my code as follows:
import async from 'async';
import {ajaxCall} from '../api';
import {GET, DISCOVERY, POST} from '../constants/apiMethods';
export const getResult = (params) => {
return(dispatch) => {
async.parallel([
function personalInfo(callback){
dispatch(getMyPersonalInfo(params, (personalInfoCallBack)=>{
callback(personalInfoCallBack, 'My personal info');
}))
},
function officialInfo(callback){
dispatch(getMyOfficialInfo(params, (officialInfoCallBack)=>{
callback(officialInfoCallBack, 'My official info');
}))
},
],(err, results)=>{
//Do something after all API response fetched
if(err){
console.log("ERROR");
}else {
console.log("SUCCESS :",results);//Expected Result ['My personal info','My official info']
}
})
}
}
export const getMyPersonalInfo = (params, personalInfoCallBack) => {
return(dispatch) => {
const userID = params.userid;
const apiName = `api/${userID}/personalinfo`;
dispatch(
ajaxCall( GET, '', apiName, (resp) => {
personalInfoCallBack(resp.callBackStatus);
})
)
}
}
export const getMyOfficialInfo = (params, officialInfoCallBack) => {
return(dispatch) => {
const userID = params.userid;
const apiName = `api/${userID}/officialinfo`;
dispatch(
ajaxCall( GET, '', apiName, (resp) => {
officialInfoCallBack(resp.callBackStatus);
})
)
}
}
So that I got error removed, Thanks
Hi, I am trying to work with async in node js, to control the flow of execution of some functions. In the code below I have three declared functions, where getMyInfo is main function which call two other function getMyPersonalInfo and getMyOfficialInfo. These two functions provide my personal and official info via fetching my APIs. Therefore I can execute further once both APIs return the data. That's why I have used async's parallel method.
So that I got error
I have ported according to documentation which is mentioned below
Note: I am using axios and redux in ReactNative and these functions are define in my Action library.
To sum up, please let me know what could be the best way to fix this?
Thanks in advance!