top | item 34659386

(no title)

dial9-1 | 3 years ago

generator functions exist, which is not even needed in this case, you could just pass a promise as an argument

discuss

order

eyelidlessness|3 years ago

To be fair, my first thought was that generators solve this roughly with the same (JS-equivalent) semantics. But my second thought was that bidirectional JS generators are painful to write and use. They’re objectively better (particularly because they’re not inherently infectious when they yield), but they’re also unergonomic as heck.

pcattori|3 years ago

The main trick on display here is that you can store a reference to the `resolve` method of a promise that normally would have to be called within the promise definition itself.

Of course, you don't need a channel abstraction to do that. To me, channels are the most intuitive and self-contained way to solve the problem, so I wanted to use that model of concurrency in JS.