Skip to main content
Tweeted twitter.com/StackSoftEng/status/1114407465653813248
Question Protected by gnat
Copy edited (e.g. ref. <http://en.wikipedia.org/wiki/JavaScript>).
Source Link

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.

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 Javascript 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 Swift language.

Is it possible? It may be a terrible idea/a utopia... I don't know

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 JavaScript 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 Swift language.

Is it possible? It may be a terrible idea/a utopia... I don't know.

Question Unprotected by Mason Wheeler
Question Protected by gnat

I didhave not findfound 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 a javascriptsome Javascript code which retrieves the number of users stored in a database (asynchronousan asynchronous operation):

getNbOfUsers(function (nbOfUsers) { console.log(nbOfUsers) });

It would be nice to be able to write something like thatthis:

const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);

And so the compilatorcompiler would automatically take care of waiting for the response toand then execute console.log. It will always wait for the asynchronous operations to answercomplete before the results have to be used anywhere else. We would usemake so much less oftenuse of callbacks, promises, async/await or whatever, and would never have to worry ifwhether the result of an operation is available immediately or not.

Errors would still be manageable (doesdid nbOfUsers gotget an integer or an error?) using try/catch, or something like optionals like in the Swift language.

Is it possible? It may be a terrible idea/a utopia... I don't know

I did not find 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 a javascript code which retrieves the number of users stored in a database (asynchronous operation):

getNbOfUsers(function (nbOfUsers) { console.log(nbOfUsers) });

It would be nice to be able to write something like that:

const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);

And so the compilator would automatically take care of waiting for the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.

Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.

Is it possible? It may be a terrible idea/a utopia... I don't know

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 Javascript 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 Swift language.

Is it possible? It may be a terrible idea/a utopia... I don't know

I did not find much ressourcesmany resources about this, iI was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way.

For example here is a javascript code which retrieveretrieves the number of users stored in a database (asynchronous operation):

getNbOfUsers(function (nbOfUsers) { console.log(nbOfUsers) });

It would be nice to be able to write something like that:

const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);

And so the compilator would automatically take care of waiting for the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.

Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.

Is isit possible? It may be a terrible idea/ana utopia... iI don't know

I did not find much ressources 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 a javascript code which retrieve the number of users stored in a database (asynchronous operation):

getNbOfUsers(function (nbOfUsers) { console.log(nbOfUsers) });

It would be nice to be able to write something like that:

const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);

And so the compilator would automatically take care of waiting the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.

Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.

Is is possible? It may be a terrible idea/an utopia... i don't know

I did not find 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 a javascript code which retrieves the number of users stored in a database (asynchronous operation):

getNbOfUsers(function (nbOfUsers) { console.log(nbOfUsers) });

It would be nice to be able to write something like that:

const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);

And so the compilator would automatically take care of waiting for the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.

Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.

Is it possible? It may be a terrible idea/a utopia... I don't know

Became Hot Network Question
deleted 8 characters in body
Source Link
Cinn
  • 483
  • 1
  • 4
  • 8
Loading
Source Link
Cinn
  • 483
  • 1
  • 4
  • 8
Loading