Best way to name async method

Where the API, let's say one method: "DoSomething ()". There must be two versions of the method: asynchronous and synchronous. We should encourage API users to use async, so synchronization should probably be more complex and explicit. So the problem is how we should call this pair. To the date weve came up with:

  • DoSomethingAndWaitForResult () / DoSomething ()
  • DoSomething () / DoSomethingAsync ()
  • DoSomethingSync () / DoSomething ()
  • DoSomething () / RequestSomething ()

None of the above schemes seems to us optimal. Any suggestions?

Update BTW feel free to post one of the answers above if it suits you.

+6
source share
3 answers

If you want your user to use asynchronous syntax for synchronization, I would go for this: DoSomethingSync() / DoSomething()

However, tell your users aloud and clear that all methods are asynchronous unless otherwise specified.

Example: node.js uses this notation: fschmodSync and fschmod

But the most important thing is to stick to the one you have chosen .

+6
source

How about naming them the same way and having a different signature to differentiate them (one with a callback function, one without)?

Otherwise, Adobe uses the “Async” suffix for ActionScript, which also looks good enough: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html

+3
source

In the .NET Framework, async methods begin with "Begin": BeginDoSomething / DoSomething.

+1
source

Source: https://habr.com/ru/post/894186/


All Articles