Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What you're describing is CPS, but that's not how continuations would typically be used in a webapp, it's actually a compiler technique (I've always thought it was crazy that node.js forces you to do by hand something that should be done by the compiler). A language that supports full continuations as first class objects, for example some Scheme implementations, allow you to actually suspend the current execution (including the entire call stack) and store it somewhere, and then start executing it again at a later point in time. So your web container can start running a thread of execution for a particular request, suspend it after it writes its response then resume it again when it receives the next request corresponding to this web session. It allows you to write code like:

    function handleSession() {
      renderFormPage()   // writes response with HTML for form
      suspend()          // wait for next request in the session
      processForm()      // process the form data - notice this is the same function
    }
It's a very powerful technique and can make web programming very intuitive since you can have a single linear flow for a complex web interaction.

Check out Chris Double's tutorial on this:

http://double.co.nz/scheme/modal-web-server.html

Or SISC-Web for a simple but complete implementation:

http://siscweb.sourceforge.net/overview.html



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: