Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to name async method

Tags:

api-design

Where is an API of, let’s say, one method: “DoSomething()”. There should be two versions of the method: asynchronous and synchronous. We should encourage API users to use async one so sync one probably should get more complicated and explicit name. So the problem is: how should we name this pair. To the date we’ve came up with:

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

None of above schemes seems like optimal for us. Any suggestion folks?

Update. BTW do not hesitate to post one of the above as an answer if it fit you.

like image 905
Artem Tikhomirov Avatar asked Feb 03 '23 15:02

Artem Tikhomirov


1 Answers

If you want to encourage your user to use async ones over sync, then I'd go for this one : DoSomethingSync() / DoSomething()

However, tell your users loud and clear that all methods are async if not told otherwise.

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

But the most important is to stick with the one you chose.

like image 120
Clement Herreman Avatar answered Apr 28 '23 20:04

Clement Herreman