How can I wait all 'put' actions finished in running parallel?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
const data = yield all([
// @TODO: Should be use action function.
yield put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
When I run this function the 'DATA >>>' run before actions such as: '@@app/PCPPRIMARYSPECIALTY/QUERY', '@@app/PCPNAME/QUERY'....
How can I wait all the actions finished?
Updated
Example of action: @@app/SERVICETYPE/QUERY
takeLatest('@@app/SERVICETYPE/QUERY', query)
...
function* query(action: any) {
try {
const resData = yield call(axios.get('/myserver'))
yield put(saveDataInStorage(resData))
} catch (err) {
}
}
javascript redux redux-saga
add a comment |
const data = yield all([
// @TODO: Should be use action function.
yield put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
When I run this function the 'DATA >>>' run before actions such as: '@@app/PCPPRIMARYSPECIALTY/QUERY', '@@app/PCPNAME/QUERY'....
How can I wait all the actions finished?
Updated
Example of action: @@app/SERVICETYPE/QUERY
takeLatest('@@app/SERVICETYPE/QUERY', query)
...
function* query(action: any) {
try {
const resData = yield call(axios.get('/myserver'))
yield put(saveDataInStorage(resData))
} catch (err) {
}
}
javascript redux redux-saga
add a comment |
const data = yield all([
// @TODO: Should be use action function.
yield put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
When I run this function the 'DATA >>>' run before actions such as: '@@app/PCPPRIMARYSPECIALTY/QUERY', '@@app/PCPNAME/QUERY'....
How can I wait all the actions finished?
Updated
Example of action: @@app/SERVICETYPE/QUERY
takeLatest('@@app/SERVICETYPE/QUERY', query)
...
function* query(action: any) {
try {
const resData = yield call(axios.get('/myserver'))
yield put(saveDataInStorage(resData))
} catch (err) {
}
}
javascript redux redux-saga
const data = yield all([
// @TODO: Should be use action function.
yield put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
yield put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
yield put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
When I run this function the 'DATA >>>' run before actions such as: '@@app/PCPPRIMARYSPECIALTY/QUERY', '@@app/PCPNAME/QUERY'....
How can I wait all the actions finished?
Updated
Example of action: @@app/SERVICETYPE/QUERY
takeLatest('@@app/SERVICETYPE/QUERY', query)
...
function* query(action: any) {
try {
const resData = yield call(axios.get('/myserver'))
yield put(saveDataInStorage(resData))
} catch (err) {
}
}
javascript redux redux-saga
javascript redux redux-saga
edited Dec 3 '18 at 3:02
Le Tom
asked Nov 29 '18 at 4:02
Le TomLe Tom
779
779
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Your actions do not return generator functions. The action is simply dispatched into the redux flow for other middleware, the reducers and eventually any sagas that take
them. The return value from put
is simply the action.
So, as soon as the actions are dispatched, the all
block is complete - regardless of whether any of the actions that get take
en have completed anything.
If you want to run a bunch of other sagas in parallel and block until they're all done, you can just call the other sagas, and use all
to call them in parallel, as per the docs:
Yielding to an array of nested generators will start all the sub-generators in parallel, wait for them to finish, then resume with all the results
function* mainSaga(getState) {
const results = yield all([call(task1), call(task2), ...])
yield put(showResults(results))
}
const data = yield all([
yield call(PCPNAME_QUERY), // where PCPNAME_QUERY is a saga
yield call(PCPREGIONNAME_QUERY),
yield call(PCPGROUPNAME_QUERY),
yield call(SERVICETYPE_QUERY),
yield call(PCPPRIMARYSPECIALTY_QUERY),
])
console.log('DATA >>>', data)
I'm so appreciate @Edward M Smith
– Le Tom
Dec 7 '18 at 3:21
add a comment |
From documentation all
effect already accepts effects. Therefore the problem in your code is yield
before put
.
const data = yield all([
// @TODO: Should be use action function.
put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
Should work
Thanks AyJay, but it seem still not waiting all dispatch function finished. It look like 'all' function only support 'call' func
– Le Tom
Nov 30 '18 at 2:48
Hmmm... That is strange. I useall
for effects in my codebase all the time. Maybe your actions return Promise? in that case you might need to useput.resolve
– AyJay
Nov 30 '18 at 13:50
Thanks for your reply. My actions return generator function (in saga). In case it can called async func. I tried put.resolve but still not working. I updated the question above.
– Le Tom
Dec 3 '18 at 2:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53531648%2fhow-can-i-wait-all-put-actions-finished-in-running-parallel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your actions do not return generator functions. The action is simply dispatched into the redux flow for other middleware, the reducers and eventually any sagas that take
them. The return value from put
is simply the action.
So, as soon as the actions are dispatched, the all
block is complete - regardless of whether any of the actions that get take
en have completed anything.
If you want to run a bunch of other sagas in parallel and block until they're all done, you can just call the other sagas, and use all
to call them in parallel, as per the docs:
Yielding to an array of nested generators will start all the sub-generators in parallel, wait for them to finish, then resume with all the results
function* mainSaga(getState) {
const results = yield all([call(task1), call(task2), ...])
yield put(showResults(results))
}
const data = yield all([
yield call(PCPNAME_QUERY), // where PCPNAME_QUERY is a saga
yield call(PCPREGIONNAME_QUERY),
yield call(PCPGROUPNAME_QUERY),
yield call(SERVICETYPE_QUERY),
yield call(PCPPRIMARYSPECIALTY_QUERY),
])
console.log('DATA >>>', data)
I'm so appreciate @Edward M Smith
– Le Tom
Dec 7 '18 at 3:21
add a comment |
Your actions do not return generator functions. The action is simply dispatched into the redux flow for other middleware, the reducers and eventually any sagas that take
them. The return value from put
is simply the action.
So, as soon as the actions are dispatched, the all
block is complete - regardless of whether any of the actions that get take
en have completed anything.
If you want to run a bunch of other sagas in parallel and block until they're all done, you can just call the other sagas, and use all
to call them in parallel, as per the docs:
Yielding to an array of nested generators will start all the sub-generators in parallel, wait for them to finish, then resume with all the results
function* mainSaga(getState) {
const results = yield all([call(task1), call(task2), ...])
yield put(showResults(results))
}
const data = yield all([
yield call(PCPNAME_QUERY), // where PCPNAME_QUERY is a saga
yield call(PCPREGIONNAME_QUERY),
yield call(PCPGROUPNAME_QUERY),
yield call(SERVICETYPE_QUERY),
yield call(PCPPRIMARYSPECIALTY_QUERY),
])
console.log('DATA >>>', data)
I'm so appreciate @Edward M Smith
– Le Tom
Dec 7 '18 at 3:21
add a comment |
Your actions do not return generator functions. The action is simply dispatched into the redux flow for other middleware, the reducers and eventually any sagas that take
them. The return value from put
is simply the action.
So, as soon as the actions are dispatched, the all
block is complete - regardless of whether any of the actions that get take
en have completed anything.
If you want to run a bunch of other sagas in parallel and block until they're all done, you can just call the other sagas, and use all
to call them in parallel, as per the docs:
Yielding to an array of nested generators will start all the sub-generators in parallel, wait for them to finish, then resume with all the results
function* mainSaga(getState) {
const results = yield all([call(task1), call(task2), ...])
yield put(showResults(results))
}
const data = yield all([
yield call(PCPNAME_QUERY), // where PCPNAME_QUERY is a saga
yield call(PCPREGIONNAME_QUERY),
yield call(PCPGROUPNAME_QUERY),
yield call(SERVICETYPE_QUERY),
yield call(PCPPRIMARYSPECIALTY_QUERY),
])
console.log('DATA >>>', data)
Your actions do not return generator functions. The action is simply dispatched into the redux flow for other middleware, the reducers and eventually any sagas that take
them. The return value from put
is simply the action.
So, as soon as the actions are dispatched, the all
block is complete - regardless of whether any of the actions that get take
en have completed anything.
If you want to run a bunch of other sagas in parallel and block until they're all done, you can just call the other sagas, and use all
to call them in parallel, as per the docs:
Yielding to an array of nested generators will start all the sub-generators in parallel, wait for them to finish, then resume with all the results
function* mainSaga(getState) {
const results = yield all([call(task1), call(task2), ...])
yield put(showResults(results))
}
const data = yield all([
yield call(PCPNAME_QUERY), // where PCPNAME_QUERY is a saga
yield call(PCPREGIONNAME_QUERY),
yield call(PCPGROUPNAME_QUERY),
yield call(SERVICETYPE_QUERY),
yield call(PCPPRIMARYSPECIALTY_QUERY),
])
console.log('DATA >>>', data)
answered Dec 3 '18 at 21:31
Edward M SmithEdward M Smith
10k14048
10k14048
I'm so appreciate @Edward M Smith
– Le Tom
Dec 7 '18 at 3:21
add a comment |
I'm so appreciate @Edward M Smith
– Le Tom
Dec 7 '18 at 3:21
I'm so appreciate @Edward M Smith
– Le Tom
Dec 7 '18 at 3:21
I'm so appreciate @Edward M Smith
– Le Tom
Dec 7 '18 at 3:21
add a comment |
From documentation all
effect already accepts effects. Therefore the problem in your code is yield
before put
.
const data = yield all([
// @TODO: Should be use action function.
put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
Should work
Thanks AyJay, but it seem still not waiting all dispatch function finished. It look like 'all' function only support 'call' func
– Le Tom
Nov 30 '18 at 2:48
Hmmm... That is strange. I useall
for effects in my codebase all the time. Maybe your actions return Promise? in that case you might need to useput.resolve
– AyJay
Nov 30 '18 at 13:50
Thanks for your reply. My actions return generator function (in saga). In case it can called async func. I tried put.resolve but still not working. I updated the question above.
– Le Tom
Dec 3 '18 at 2:58
add a comment |
From documentation all
effect already accepts effects. Therefore the problem in your code is yield
before put
.
const data = yield all([
// @TODO: Should be use action function.
put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
Should work
Thanks AyJay, but it seem still not waiting all dispatch function finished. It look like 'all' function only support 'call' func
– Le Tom
Nov 30 '18 at 2:48
Hmmm... That is strange. I useall
for effects in my codebase all the time. Maybe your actions return Promise? in that case you might need to useput.resolve
– AyJay
Nov 30 '18 at 13:50
Thanks for your reply. My actions return generator function (in saga). In case it can called async func. I tried put.resolve but still not working. I updated the question above.
– Le Tom
Dec 3 '18 at 2:58
add a comment |
From documentation all
effect already accepts effects. Therefore the problem in your code is yield
before put
.
const data = yield all([
// @TODO: Should be use action function.
put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
Should work
From documentation all
effect already accepts effects. Therefore the problem in your code is yield
before put
.
const data = yield all([
// @TODO: Should be use action function.
put({
type: '@@app/PCPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPREGIONNAME/QUERY',
payload: {},
}),
put({
type: '@@app/PCPGROUPNAME/QUERY',
payload: {},
}),
put({
type: '@@app/SERVICETYPE/QUERY',
payload: {},
}),
put({
type: '@@app/PCPPRIMARYSPECIALTY/QUERY',
payload: {},
}),
])
console.log('DATA >>>', data)
Should work
answered Nov 29 '18 at 20:56
AyJayAyJay
214412
214412
Thanks AyJay, but it seem still not waiting all dispatch function finished. It look like 'all' function only support 'call' func
– Le Tom
Nov 30 '18 at 2:48
Hmmm... That is strange. I useall
for effects in my codebase all the time. Maybe your actions return Promise? in that case you might need to useput.resolve
– AyJay
Nov 30 '18 at 13:50
Thanks for your reply. My actions return generator function (in saga). In case it can called async func. I tried put.resolve but still not working. I updated the question above.
– Le Tom
Dec 3 '18 at 2:58
add a comment |
Thanks AyJay, but it seem still not waiting all dispatch function finished. It look like 'all' function only support 'call' func
– Le Tom
Nov 30 '18 at 2:48
Hmmm... That is strange. I useall
for effects in my codebase all the time. Maybe your actions return Promise? in that case you might need to useput.resolve
– AyJay
Nov 30 '18 at 13:50
Thanks for your reply. My actions return generator function (in saga). In case it can called async func. I tried put.resolve but still not working. I updated the question above.
– Le Tom
Dec 3 '18 at 2:58
Thanks AyJay, but it seem still not waiting all dispatch function finished. It look like 'all' function only support 'call' func
– Le Tom
Nov 30 '18 at 2:48
Thanks AyJay, but it seem still not waiting all dispatch function finished. It look like 'all' function only support 'call' func
– Le Tom
Nov 30 '18 at 2:48
Hmmm... That is strange. I use
all
for effects in my codebase all the time. Maybe your actions return Promise? in that case you might need to use put.resolve
– AyJay
Nov 30 '18 at 13:50
Hmmm... That is strange. I use
all
for effects in my codebase all the time. Maybe your actions return Promise? in that case you might need to use put.resolve
– AyJay
Nov 30 '18 at 13:50
Thanks for your reply. My actions return generator function (in saga). In case it can called async func. I tried put.resolve but still not working. I updated the question above.
– Le Tom
Dec 3 '18 at 2:58
Thanks for your reply. My actions return generator function (in saga). In case it can called async func. I tried put.resolve but still not working. I updated the question above.
– Le Tom
Dec 3 '18 at 2:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53531648%2fhow-can-i-wait-all-put-actions-finished-in-running-parallel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown