I want to have a JS generator function that returns a series of some stuff, let's say its suggestions for dinner. It knows names of some dishes, but if I don't like any of them, it will need to fetch more suggestions from a remote server. So I'd like this to work:
const dishSuggestions = function* (){
yield "pancakes";
yield "pizza";
fetchMealSuggestions().then(suggestions => { // Or even better await.
for (const suggestion of suggestions)
yield suggestion;
});
};
This won't work obviously because I cannot yield from an inner function. So my question is: how to get that behaviour? Can I? Or is this the wrong tool?