3 ms·
Async/await doesn't only work on promises, it works on any object that has a method named `then`. What's problematic is that you have no control or extension po
by esailija 11y ago
Async/await doesn't only work on promises, it works on any object that has a method named `then`. What's problematic is that you have no control or extension points in the runner so you cannot implement something like Go's defer statement. With generators (which can be made work like async/await, only you say yield instead of await) you can implement the defer statement and more.
- scotty79 11y agoGood that it works on any object with then. Shame that it's not more flexible. What I said was more general argument about what each new syntax should support at minimum. What you are saying is like having operator overload, but not ability to define new custom operators, or not being able to define 3 or more arguments operators or default arguments for operators, or quoted arguments for operators. Or regretting that C# foreach works on every Enumerable but takes every item one after another (preventing from implementing collection that would have parallel behaviour with foreach) It's good if you can do a lot with new syntax but that's nice to have and case by case. What I was talking about I consider general and pretty much mandatory. Lots of people feel that if you look at the piece of code you should be immediately be able to tell what it's doing without any context. It's intuitively attractive goal but I think that most measures that achieve that also result in putting obstacles in software usual evolution making people do very contorted things when they need to add yet another feature with limited time.