3 ms·
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 lis
by amelius 9y ago
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.
- kevincox 9y agoWhy 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?
- amelius 9y agoI'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.
- skybrian 9y agoFor that use case, maybe an event emitter would work better?