0

Then following occurs frequently:

someAsynchOp(a,b,theRestOfMyCode);
function theRestOfMyCode(){
    //several hundred lines of code making up the rest of the file
  }

This works perfectly fine. However it is ugly and decreases human readability.

How can I make the Asynchronous operation behave as though it is synchronous or blocking? To avoid needing to wrap the remainder of my file in the function?

I understand why you almost always want to let asynchronous run asynchronous; but there are use cases where there are in fact no lines would want to execute prior to the asynchronous code finishing, and therefore relying on the above structure is probably unnecessarily clunky and hard to read.

COMisHARD
  • 867
  • 3
  • 13
  • 36
  • Not certain what Question is? – guest271314 Jan 21 '17 at 07:38
  • How can I make the Asynchronous operation behalf as though it is synchronous or blocking? What could I write as a utility function to achieve that result? – COMisHARD Jan 21 '17 at 07:40
  • It is really bad practice to try to turn asynchronous behaviour into synchronous code execution, which will block the script. You may think it is ugly to use callback functions (or promises), but that is the way to do it. After a while you'll find it is not ugly at all. – trincot Jan 21 '17 at 07:59
  • 1
    Tell me. Why is it bad practice in the use case described in my post? – COMisHARD Jan 21 '17 at 11:43

0 Answers0