return fetch(url, {
credentials: 'same-origin',
...options
})
.then(response => response.json())
.then(function*(response) {
console.log("httpStatusCode", response.httpStatusCode)
})
Is the above possible ? I'm not getting the consoled output when the callback function is a generator, which means that the control is not passing to the callback function(generator). The real reason I want to do it this way is that I have to call another fetch request using the 'call' helper function of redux-saga from the above callback which can be called only from a generator function.
No. The
then
method will simply call the generator function and create a generator, but thendiscard itfulfill the chained promise, without advancing it. Whenever you want to use generators, you actually need something that runs them.Nope. You don't have to call
call
from an arbitrary generator function. You can can call andyield
acall()
from a generator function that is used by redux-saga.In any case, your code should look like this:
Taking a long shot here. In order to iterate through a generator function you need to be able to call 'gen.next()'. Which is not possible after providing an anonymous function to '.then'.
I am not familiar with redux-saga, but from what I understand you try something similar.
You can then pass
gen
to be used in redux-saga.I guess you can do. When the generator function is run it will generate a generator object and it will be passed to the next then stage at where you can initiate the generator. Let's see...