News for hackers. Stuff that matters.
Re:Async Iterators: These Promises Are Killing My Performance by skybrian on Sunday August 27, 2017 @05:27PM (#15112881)
I think it's less of a design flaw and more a conceptual issue. Since a Promise is just a value, it can be stored in an arbitrary data structure on the heap with no listeners. But the then() method can be called any time later. So, a promise being potentially "listened to" is really just being reachable by the garbage collector.

There's no reason the source of the promise can't implement a cancel() method, though.

Re:Async Iterators: These Promises Are Killing My Performance by amelius on Sunday August 27, 2017 @05:51PM (#15113016)
But a cancel() method would not be a "clean" solution if there potentially are multiple listeners.

I really want to compute things if and only if there are listeners.

Re:Async Iterators: These Promises Are Killing My Performance by kevincox on Sunday August 27, 2017 @06:43PM (#15113215)
Why are you generating the promise in the first place if there are no listeners? Why don't you return a function which can be used to generate the promise instead?
Re:Async Iterators: These Promises Are Killing My Performance by amelius on Sunday August 27, 2017 @07:12PM (#15113331)
I'm not sure what would be the advantage.

The number of listeners can go up and down during the computation. When that number reaches zero, the computation needs to be stopped.

When the number becomes nonzero again, the computation needs to be restarted.

Those are the requirements, basically.

Re:Async Iterators: These Promises Are Killing My Performance by skybrian on Sunday August 27, 2017 @08:24PM (#15113603)
For that use case, maybe an event emitter would work better?