async / await

bauss jj_1337 at live.dk
Fri Oct 8 12:14:51 UTC 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:
>> 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!

I'm not saying it's the best way to do it. I'm just stating 
that's the standard way in C#.


More information about the Digitalmars-d mailing list