On Mon, Apr 2, 2012 at 5:44 AM, Rasmus Schultz <ras...@mindplay.dk> wrote:
> I was just reading about the new async/await keywords in C# 5.0, and while > this has no particular relevance to PHP as such, it got me thinking about > this idea... > > What if you could resume execution after an exception was thrown? > > This is beginning to sound a lot like Common LISP's conditions<http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html>, which isn't necessarily a bad thing. To get it to work, PHP would have to preserve the stack when an exception is thrown (until the catch block is exited), or store the exception/condition handler and execute it when the exception is thrown/condition is signaled before unwinding the stack frame. > Taking this one step further, imagine it were also possible to serialize() > an Interrupt - and resume it at a later time. This would open up entirely > new possibilities for (AJAX) web-application frameworks, which would be > able to suspend execution, serialize the script state, return a response, > wait for further interaction from the user, and then resume execution. > > This feels an unnatural use for an Interrupt, which models messages between different levels of the execution stack. What you're describing is better done with continuations <http://double.co.nz/pdf/continuations.pdf> (PDF), where you have an execution tree<http://en.wikipedia.org/wiki/Saguaro_stack> rather than a stack. While continuations would certainly be cool, there are definite performance and memory usage concerns involved with the various implementations <http://c2.com/cgi/wiki?ContinuationImplementation>.