How to use async await inside redux saga?
How to use async await inside redux saga?
I'm trying to use ES javascript api to get data from Elastic Search and show it in my React Redux Redux-Saga code.
function* getData()
const response = async () => await client.msearch(
body: [
// match all query, on all indices and types
,
query: match_all: ,
// query_string query, on index/mytype
index: 'myindex', type: 'mytype' ,
query: query_string: query: '"Test 1"' ,
],
);
yield put(Success(
Data: response(),
));
The problem is I don't know how to make the yield wait for the response to be resolved.
Is there any other way to use a promise inside redux saga and es javascript-client ?
1 Answer
1
I figured it out. Putting the answer here for anyone looking for it.
function* getData(data)
const response = yield call(fetchSummary, data);
yield put(Success(
Data: response,
));
async function fetchSummary(data)
return await client.msearch(
body: [
// match all query, on all indices and types
,
query: match_all: ,
// query_string query, on index/mytype
index: 'myindex', type: 'mytype' ,
query: query_string: query: data.query ,
],
);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.