Jump to page: 1 2
Thread overview
async / await
Oct 07, 2021
Imperatorn
Oct 07, 2021
Dukc
Oct 07, 2021
Imperatorn
Oct 07, 2021
russhy
Oct 07, 2021
Imperatorn
Oct 08, 2021
bauss
Oct 08, 2021
Imperatorn
Oct 08, 2021
ikod
Oct 08, 2021
bauss
Oct 08, 2021
Imperatorn
Oct 08, 2021
jfondren
Oct 08, 2021
Imperatorn
Oct 08, 2021
jfondren
Oct 08, 2021
Imperatorn
October 07, 2021
  1. What are the hurdles to overcome to enable the async / await keywords in D?

Would make the porting process from C# to D much easier and also shorten a lot of code.

  1. Is there something similar to C# Task (https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=net-5.0) in D?

Would make the porting process from C# to D even easier.

I began making a list of corresponding language constructs between C# and D and you can get pretty far without doing much work. But then there's that async stuff...

There's a lot of C# out there waiting to become D 🍀

October 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 work just as well?

October 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:

>
  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 work just as well?

Mainly when porting from other languages, but it's also faster to write asynchronous logic with it in general.

October 07, 2021

I don't think trying to replicate C# async/await is a good idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult)

https://kristoff.it/blog/zig-colorblind-async-await/

Zig's approach is cleaner imo

October 07, 2021

On Thursday, 7 October 2021 at 22:35:23 UTC, russhy wrote:

>

I don't think trying to replicate C# async/await is a good idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult)

https://kristoff.it/blog/zig-colorblind-async-await/

Zig's approach is cleaner imo

I think you misunderstood me. What I meant was just the async/await keywords

October 08, 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:

>

I don't think trying to replicate C# async/await is a good idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult)

https://kristoff.it/blog/zig-colorblind-async-await/

Zig's approach is cleaner imo

I think you misunderstood me. What I meant was just the async/await keywords

No, he understood you and is talking about the method implementations in C#.

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!

October 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:

>

I don't think trying to replicate C# async/await is a good idea, it promotes creating bad APIs (GetThisAsync | GetThisAsync.ButSyncThisTimeToGetResult)

https://kristoff.it/blog/zig-colorblind-async-await/

Zig's approach is cleaner imo

I think you misunderstood me. What I meant was just the async/await keywords

No, he understood you and is talking about the method implementations in C#.

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!

But, I wasn't talking about the implementation. I just used C# as 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.

October 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:
>>> I don't think trying to replicate C# async/await is a good 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!


October 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?

Would make the porting process from C# to D much easier and also shorten a lot of code.

  1. Is there something similar to C# Task (https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=net-5.0) in D?

Would make the porting process from C# to D even easier.

I began making a list of corresponding language constructs between C# and D and you can get pretty far without doing much work. But then there's that async stuff...

There's a lot of C# out there waiting to become D 🍀

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.

October 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 it's not going to sell D to 'port' C# by transliterating it into 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.

« First   ‹ Prev
1 2