Re: resume after exception

From: Date: Mon, 02 Apr 2012 19:56:22 +0000
Subject: Re: resume after exception
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-59327@lists.php.net to get a copy of this message
On Mon, Apr 2, 2012 at 5:44 AM, Rasmus Schultz <rasmus@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>.

« previous php.internals (#59327) next »