3 ms·
This doesn't make JavaScript actually run in parallel, does it? I.e if there is any IO to wait on then JS runs, but if there are multiple pure JS asyncs schedul
by kreetx 3y ago
This doesn't make JavaScript actually run in parallel, does it? I.e if there is any IO to wait on then JS runs, but if there are multiple pure JS asyncs scheduled to run then these will still run one at a time?
Secondly, there is async iteration which is already pretty good syntax wise.
- joeycumines 3y agoYep, JS is still single threaded, and all that. I agree async iteration is pretty good - the `Chan` class implements both `Iterable` and `AsyncIterable`. For quite a few scenarios, async generators are a better choice. They do have limitations, however. For example, you _can_ implement fan-in, but there's no easy mechanism to fan-in in a blocking manner, from sources that aren't known ahead of time. It's also hard to implement a "fair" mechanism, that doesn't bias certain inputs (like you might desire if multiplexing logs, for example).
- felipellrocha 3y agoCouldn’t you spin N workers and assign work to them?
- joeycumines 3y agoFan-in is the other way, but yeah you can do batches of concurrent operations in JS fairly easily. I still like "pipelining" over that, but that can also be implemented with just an iterator, pretty trivially.
- kreetx 3y agoThe value proposition of the library became much clearer, thanks for explaining!