I'm new to web development. Coming from Delphi/pascal. My long term goal is to convert a legacy application to a web environment. (I am using this application: <http://smartmobilestudio.com/> to cross compile pascal to javascript, but that shouldn't impact this question). My legacy program uses synchronous remote procedure calls (RPC's) to a server. I am using a technology named EWD.js (<http://robtweed.wordpress.com/2014/01/23/ewd-js-on-fhir/comment-page-1/>) that makes asynchronous calls via node.js. I have read many many posts here about synchronous vs synchronous calls. And I fear that I am just out of luck if I can't make EWD act in a synchronous fashion. But I want to understand this better.

Consider this pseudocode:

```
RPCcall
//business logic
RPCCall
//business logic
RPCCall
//business logic.

```

If any of the RPC calls fail, then the entire application should fail. I have read of coding in a "continuation style", which I take to be that each asynchronous call tells where to pick up the patch upon completion by having the onMessage handler call the callback function upon receipt of return message:

```
MyProc()
  RPCCall(<name>,MyProc_2);
end;

MyProc2()
  //business logic
  RPCCall(<name, MyProc_3);
end;

MyProc3()
  //business logic
  RPCCall(<name, MyProc_3);
end.

```

And this would be possible, though awkward / ugly. But what about situations like this?

```
RPCcall
//business logic
if conditionA then begin
  if conditionA2 then begin
    RPCCall
    //business logic
  end else
    RPCCall
    //business logic
  end else begin
    for i=1 to 10 do begin
      RPCCall
      //business logic
    end;
  end
end

```

I don't see realistically how to convert the above to continuation style. If there is a call in the middle of a logic tree, or loop, how can I jump back into that state? How has this been done before? It is not realistic to completely recode the legacy application. It is very very large and complex.

Any help will be appreciated. 
Thanks