N
N
Nikita Shchypylov2018-03-31 12:00:22
JavaScript
Nikita Shchypylov, 2018-03-31 12:00:22

How to rewrite this saga so that f-I would be waiting for an answer?

Hello everyone
There is a code that sends a request for data from Firebase and displays the results. I'm trying to migrate to Saga, but for some reason the Worker does not wait for the result. Here is the code:

function fetchStories() {
  fire.database().ref("stories").on('value', function(snap) {
    console.log("--- snap.val()", snap.val());
    return snap.val();
  });
};

function* fetchStoriesWorker() {
  try {
    const response = yield call(fetchStories);
    console.log("--- response", response)
    const dog = response.data.message;
    yield put({type: "API_CALL_SUCCESS", dog});
  } catch (error) {
    yield put({type: "API_CALL_FAILURE", error});
  }
}

Console Output: 5abf4dde8a3ee494209711.jpeg
As you can see from p-ta, fetchStoriesWorker() does not wait for fetchStories() to complete. Why?
How to wait for execution return snap.val();, and then write data to response?
Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question