3 ms·
The concepts are similar. However: - Promises don't block the caller. You don't wait, you provide a method to call on completion. - 'Signaling' a promise (com
by Strilanc 14y ago
The concepts are similar. However:
- Promises don't block the caller. You don't wait, you provide a method to call on completion.
- 'Signaling' a promise (completing it) causes all callbacks to run, instead of just one.
- Promises never transition from completed to not-completed. They settle.
- Promises naturally propagate values.
Semaphores can be useful for implementing a promise, but they're not quite the same.
- seivan 14y ago1) Yeah I guess that's what semaphores are for, but the way to mitigate that is to block in a different queue. :-) Not saying this is the right way, I am saying this is part of me refactoring deep nested blocks. It's the middle ground before doing it properly. 2) Not sure what you mean here. A semaphore has a counter. You can signal for one run and only one if you want. 3)Not sure what this means, I suppose I gotta' read up 4) Yeah, this is where semaphores get ugly. Thanks for taking your time. Appreciate it.