This is one way to structure it but not the only. Scheme's call-with-current-continuation comes to mind here.
Continuation-based web frameworks are really nifty, but have potential scaling bottlenecks. IIRC HN originally used some type of continuation web framework with Arc, but ran into scaling and caching headaches. Dunno how it works these days.
The above is succinctly implemented in wat: https://github.com/manuel/wat-js (also see forks for more documented versions).