How to yield inside a forEach
See original GitHub issueSay for example we have a forEach loop which needs to yield.
function* mySaga() {
[1,2,3].forEach(function* (x) {
yield call(foo, bar);
});
}
What syntax would you use in mySaga to denote it to the middleware?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:21
- Comments:12 (4 by maintainers)
Top Results From Across the Web
javascript - Can I yield from an inner function? - Stack Overflow
No, you can't yield from a callback (technically, it's not an "inner function", which ...
Read more >yield statement - provide the next element in an iterator
yield return : to provide the next value in iteration, as the following example shows: C# Copy. Run. foreach (int i in ProduceEvenNumbers(9))...
Read more >generators vs forEach - ESDiscuss.org
The support for nested generators ("yield*") differs from normal function call operation. ... forEach(Array, GeneratorFunction) with yield* in the body.
Read more >yield - JavaScript - MDN Web Docs - Mozilla
The yield operator is used to pause and resume a generator function.
Read more >How to Use Generators and yield in Python
But now, you can also use it as you see in the code block above, where i takes the value that is yielded....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Use
map
to yield a parallel effect. If you want to yield effect in sequence (wait for 1st effect to terminate before yielding the 2nd) use a normal for loopjust do the simplest thing
ive corrected your example a little bit
fork
instead ofcall
to achieve a non-blocking effect which will return a task descriptor