In the Saga API it says it is possible the pass a function to a call that is not another saga/generator, nor is it a function that returns a promise. In other words, a saga call can call a basic sync javascript function :
If fn is a normal function and returns a Promise, the middleware will suspend the Generator until the Promise is settled. After the promise is resolved the Generator is resumed with the resolved value, or if the Promise is rejected an error is thrown inside the Generator.
If the result is not an Iterator object nor a Promise, the middleware will immediately return that value back to the saga, so that it can resume its execution synchronously.
My question is what is the point of this?
Is there any difference between this :
export function* mySaga(myParam: string) {
const result = yield call(func, myParam);
return result;
}
function func(myParam) {
//do something
}
and this :
export function* mySaga(myParam: string) {
const result = func(myParam);
return result;
}
function func(myParam) {
//do something
}
I am in a new project where they do this a lot. I am just a bit confused to why it is done this way, and what the point is of calling another function with a "call" even if it is a normal sync javascript function.