async / await

ikod igor.khasilev at
Fri Oct 8 10:19:40 UTC 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 

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!

More information about the Digitalmars-d mailing list