Comments (3)
Hmmm. So first things first: your use-case is probably best served by an async generator and not a repeater:
async function *gen() {
await checkSomethingAsynchronously();
yield *someOtherRepeater;
}
Think of it like the Promise
constructor: if you have a promise already then using the Promise
constructor is probably a mistake. Same goes for repeaters: if you have an async iterator, you should probably be using an async generator and not a repeater. Choosing between the two can be tricky and I’ve thought about making a flow-chart for the different use-cases. It really depends on the sources that you’re pulling from. If they’re callback-based, use repeaters obviously. If they’re promises or async iterators, then it depends on how complicated the pulling algorithm is. If you’re simply pulling in series, then async generators and yield
/yield*
work. If you’re pulling from them concurrently, then repeaters can help.
didn't we come to the conclusion awhile back that using
for..await
like this is dangerous
The problem was with using async generators and for...await
. Calling return
on an async generator object paused at the top of a for...await
loop wouldn’t work until the loop resumed, potentially causing deadlocks. The same would be true with a Repeater
, but you could mitigate this issue by racing iteration with the stop
promise.
from repeater.
Oh yeah, I didn't think of just using an async generator.
Calling return on an async generator object paused at the top of a for...await loop wouldn’t work until the loop resumed, potentially causing deadlocks.
I wonder if this is the case for yield *
also though?
from repeater.
I think I checked and found that yield *
propagates return into the inner iterator immediately.
from repeater.
Related Issues (20)
- Missing documentation for packages HOT 2
- Not that great for implementing transducers? HOT 31
- Should the Repeater automatically stop when its executor fulfills? HOT 5
- Doesn't quite match AsyncIterable interface? HOT 3
- Some of the more fragile tests are failing in newer versions of node HOT 1
- Question about the abilities of async iteration HOT 2
- Repeater.race typings are incorrect HOT 1
- Aggressive memory leak in Repeater.race HOT 2
- 4.0 changes HOT 4
- TypeError: Invalid attempt to iterate non-iterable instance. HOT 5
- WeakMap error at Repeater.return HOT 8
- RepeatOrNot HOT 1
- Question about merging two Repeaters HOT 2
- Help with map transducer? HOT 13
- Stop promise not entirely compatible with Promise.race
- Event loop can die if stop() not called
- TS errors when using "module": "NodeNext" and module type is commonjs
- Version 3.0.5 is available on NPM, but not on git. HOT 1
- Should push() wait for buffering, instead of a call to next()? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from repeater.