digitalmars.D - async / await
- Imperatorn (11/11) Oct 07 2021 1. What are the hurdles to overcome to enable the async / await
- Dukc (5/7) Oct 07 2021 What it would benefit to have them as keywords? Don't the
- Imperatorn (3/10) Oct 07 2021 Mainly when porting from other languages, but it's also faster to
- russhy (5/5) Oct 07 2021 I don't think trying to replicate C# async/await is a good idea,
- Imperatorn (3/8) Oct 07 2021 I think you misunderstood me. What I meant was just the
- bauss (10/20) Oct 07 2021 No, he understood you and is talking about the method
- Imperatorn (10/32) Oct 08 2021 But, I wasn't talking about the implementation. I just used C# as
- ikod (14/25) Oct 08 2021 This is not always useful to have different names for interfaces,
- bauss (3/31) Oct 08 2021 I'm not saying it's the best way to do it. I'm just stating
- Imperatorn (7/18) Oct 08 2021 If not integrated in the language via keywords, how could one
- jfondren (16/22) Oct 08 2021 D doesn't have AST macros, which is what the usual transformation
- Imperatorn (2/7) Oct 08 2021 Sad
- jfondren (7/16) Oct 08 2021 D doesn't have any syntax to support an actor framework either,
- Imperatorn (2/19) Oct 08 2021 Hmm, I just assumed that it did because it's so similar to Erlang
1. What are the hurdles to overcome to enable the async / await keywords in D? shorten a lot of code. (https://docs.microsoft.com/en-us/dotnet/api/system.threading.task .task?view=net-5.0) in D? I began making a list of corresponding language constructs work. But then there's that async stuff...
Oct 07 2021
On Thursday, 7 October 2021 at 12:47:16 UTC, Imperatorn wrote:1. What are the hurdles to overcome to enable the async / await keywords in D?What it would benefit to have them as keywords? Don't the [functions in Vibe.d](https://vibed.org/api/vibe.core.concurrency/) work just as well?
Oct 07 2021
On Thursday, 7 October 2021 at 20:31:42 UTC, Dukc wrote:On Thursday, 7 October 2021 at 12:47:16 UTC, Imperatorn wrote:Mainly when porting from other languages, but it's also faster to write asynchronous logic with it in general.1. What are the hurdles to overcome to enable the async / await keywords in D?What it would benefit to have them as keywords? Don't the [functions in Vibe.d](https://vibed.org/api/vibe.core.concurrency/) work just as well?
Oct 07 2021
it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult) https://kristoff.it/blog/zig-colorblind-async-await/ Zig's approach is cleaner imo
Oct 07 2021
On Thursday, 7 October 2021 at 22:35:23 UTC, russhy wrote:idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult) https://kristoff.it/blog/zig-colorblind-async-await/ Zig's approach is cleaner imoI think you misunderstood me. What I meant was just the async/await keywords
Oct 07 2021
On Thursday, 7 October 2021 at 23:20:15 UTC, Imperatorn wrote:On Thursday, 7 October 2021 at 22:35:23 UTC, russhy wrote:No, he understood you and is talking about the method But tbh. the solution is to provide both an asynchronous and a synchronous version of the method. Ex. DownloadFile() would be synchronous, whereas DownloadFileAsync() would then be async. That avoids the whole problem of calling an async method synchronous, because in general you shouldn't ever do that anyway!idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult) https://kristoff.it/blog/zig-colorblind-async-await/ Zig's approach is cleaner imoI think you misunderstood me. What I meant was just the async/await keywords
Oct 07 2021
On Friday, 8 October 2021 at 06:38:17 UTC, bauss wrote:On Thursday, 7 October 2021 at 23:20:15 UTC, Imperatorn wrote:an example rather than for example Zig. The keywords are separate from the implementation. The same way that if we didn't have foreach as a keyword and decided to introduce it. I was mainly talking about the purely syntactic aspect of the source code. It would (also) make the porting of Zig/[insert language here] to D easier.On Thursday, 7 October 2021 at 22:35:23 UTC, russhy wrote:No, he understood you and is talking about the method But tbh. the solution is to provide both an asynchronous and a synchronous version of the method. Ex. DownloadFile() would be synchronous, whereas DownloadFileAsync() would then be async. That avoids the whole problem of calling an async method synchronous, because in general you shouldn't ever do that anyway!idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult) https://kristoff.it/blog/zig-colorblind-async-await/ Zig's approach is cleaner imoI think you misunderstood me. What I meant was just the async/await keywords
Oct 08 2021
On Friday, 8 October 2021 at 06:38:17 UTC, bauss wrote:On Thursday, 7 October 2021 at 23:20:15 UTC, Imperatorn wrote:On Thursday, 7 October 2021 at 22:35:23 UTC, russhy wrote:idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult)Ex. DownloadFile() would be synchronous, whereas DownloadFileAsync() would then be async.This is not always useful to have different names for interfaces, especially when application developer decide for some performance/scalability/etc reason to port sync code to async environment. DownloadFile can be implemented such that it detects if it work in sync or async environment like (in pseudocode): void DownloadFile() { if (activeEventLoopDetected) { wait asyncCode } else { call syncCode } }That avoids the whole problem of calling an async method synchronous, because in general you shouldn't ever do that anyway!
Oct 08 2021
On Friday, 8 October 2021 at 10:19:40 UTC, ikod wrote:On Friday, 8 October 2021 at 06:38:17 UTC, bauss wrote:I'm not saying it's the best way to do it. I'm just statingOn Thursday, 7 October 2021 at 23:20:15 UTC, Imperatorn wrote:On Thursday, 7 October 2021 at 22:35:23 UTC, russhy wrote:idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult)Ex. DownloadFile() would be synchronous, whereas DownloadFileAsync() would then be async.This is not always useful to have different names for interfaces, especially when application developer decide for some performance/scalability/etc reason to port sync code to async environment. DownloadFile can be implemented such that it detects if it work in sync or async environment like (in pseudocode): void DownloadFile() { if (activeEventLoopDetected) { wait asyncCode } else { call syncCode } }That avoids the whole problem of calling an async method synchronous, because in general you shouldn't ever do that anyway!
Oct 08 2021
On Thursday, 7 October 2021 at 12:47:16 UTC, Imperatorn wrote:1. What are the hurdles to overcome to enable the async / await keywords in D? also shorten a lot of code. (https://docs.microsoft.com/en-us/dotnet/api/system.threading.task .task?view=net-5.0) in D? I began making a list of corresponding language constructs work. But then there's that async stuff...If not integrated in the language via keywords, how could one accomplish it using the "keywords" anyway? Could udas be used? async await? Could "compile time magic" lower to something? I find it hard to believe that it would be *impossible* since D is one of the most plastic statically typed languages I know.
Oct 08 2021
On Friday, 8 October 2021 at 11:14:54 UTC, Imperatorn wrote:If not integrated in the language via keywords, how could one accomplish it using the "keywords" anyway? Could udas be used? async await? Could "compile time magic" lower to something?D doesn't have AST macros, which is what the usual transformation requires: https://github.com/nim-lang/Nim/blob/devel/lib/pure/asyncmacro.nim#L253 That's just syntax, though. It's putting the cart a hundred miles before the horse to want syntax from dmd when the functionality it would lower to is also not there. You could easily build something over vibe's fiber scheduler and std.concurrency, but code with very different performance characteristics. It'd be like dmd adding a goroutine syntax that lowers to the phobos FiberShcheduler, where some benchmarks in Learn have it 8x slower than go: it would be better to rethink that code for D. If you want the familiar syntax, the better immediate goal is some existing D syntax that works with a tokio/asyncdispatch/etc.-competitive async scheduler.I find it hard to believe that it would be *impossible* since D is one of the most plastic statically typed languages I know.
Oct 08 2021
On Friday, 8 October 2021 at 11:34:29 UTC, jfondren wrote:On Friday, 8 October 2021 at 11:14:54 UTC, Imperatorn wrote:Sad[...]D doesn't have AST macros, which is what the usual transformation requires: [...]
Oct 08 2021
On Friday, 8 October 2021 at 12:21:50 UTC, Imperatorn wrote:On Friday, 8 October 2021 at 11:34:29 UTC, jfondren wrote:D doesn't have any syntax to support an actor framework either, but it still has a very natural one in std.concurrency. It doesn't have any syntax to support pattern matching over ML datatypes but it has std.sumtype. If you focus on functionality first and syntax later, you might find you want that much for syntax in the end.On Friday, 8 October 2021 at 11:14:54 UTC, Imperatorn wrote:Sad[...]D doesn't have AST macros, which is what the usual transformation requires: [...]
Oct 08 2021
On Friday, 8 October 2021 at 12:30:18 UTC, jfondren wrote:On Friday, 8 October 2021 at 12:21:50 UTC, Imperatorn wrote:Hmm, I just assumed that it did because it's so similar to ErlangOn Friday, 8 October 2021 at 11:34:29 UTC, jfondren wrote:D doesn't have any syntax to support an actor framework either, but it still has a very natural one in std.concurrency. It doesn't have any syntax to support pattern matching over ML datatypes but it has std.sumtype. If you focus on functionality first and syntax later, you might find you want that much for syntax in the end.On Friday, 8 October 2021 at 11:14:54 UTC, Imperatorn wrote:Sad[...]D doesn't have AST macros, which is what the usual transformation requires: [...]
Oct 08 2021