News for hackers. Stuff that matters.
Re:Why async fn in traits are hard by continuational on Sunday October 27, 2019 @03:35AM (#21368352)
In all fairness, in other languages this usually looks like

    def getUser() : Future[User]
Re:Why async fn in traits are hard by cerebellum42 on Sunday October 27, 2019 @07:52AM (#21369158)
Even in Rust, it only looks like that in this very specific use case and is usually completely hidden from the programmer. It's the desugared output of a library.

Usually it would look like this in Rust:

fn get_user(&self) -> impl Future<Output = User>;

This isn't exactly the same functionally, but for most use cases it works just fine. The difference is that this uses static dispatch instead of dynamic dispatch and therefore can't support dynamically returning two different structs that both implement Future, it has to be one type.

Re:Why async fn in traits are hard by noncoml on Sunday October 27, 2019 @04:12AM (#21368444)
Not in dynamic languages, ie JavaScript
Re:Why async fn in traits are hard by littlestymaar on Sunday October 27, 2019 @04:38AM (#21368521)
It is. It's not visible if you the types aren't written, but under the hood, that's the type of things like this.
Re:Why async fn in traits are hard by noncoml on Sunday October 27, 2019 @04:45AM (#21368539)
Ehm. No. JavaScript will return a Promise. It’s “type” is Object as pretty much anything else in JavaScript.
Re:Why async fn in traits are hard by endless1234 on Sunday October 27, 2019 @04:51AM (#21368557)
But isn't a Promise for all intents and purposes the same as a Future here?
Re:Why async fn in traits are hard by marcoms on Sunday October 27, 2019 @07:13AM (#21369035)
Yes, but I think they are emphasising that only a promise will be returned. Any further type information is not given
Re:Why async fn in traits are hard by wwright on Sunday October 27, 2019 @08:16AM (#21369246)
Check out structural typing. I would say it’s the type system JavaScript uses for non-primitive values. The “dynamic” appearance is just that JavaScript doesn’t center the type system in its UX.