I have not found many resources about this: I was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way.
For example, here is some JavascriptJavaScript code which retrieves the number of users stored in a database (an asynchronous operation):
getNbOfUsers(function (nbOfUsers) { console.log(nbOfUsers) });
It would be nice to be able to write something like this:
const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);
And so the compiler would automatically take care of waiting for the response and then execute console.log. It will always wait for the asynchronous operations to complete before the results have to be used anywhere else. We would make so much less use of callbacks promises, async/await or whatever, and would never have to worry whether the result of an operation is available immediately or not.
Errors would still be manageable (did nbOfUsers get an integer or an error?) using try/catch, or something like optionals like in the SwiftSwift language.
Is it possible? It may be a terrible idea/a utopia... I don't know.