Re: resume after exception

From: Date: Mon, 02 Apr 2012 22:43:00 +0000
Subject: Re: resume after exception
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-59333@lists.php.net to get a copy of this message
Magnus Holm has an excellent proof of concept for this in Ruby, which supports continuations: http://timelessrepo.com/never-gonna-let-you-go On Apr 2, 2012 10:44 PM, "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? > > Fictive example: > > function test() > { > echo "Begin Test!\n"; > > throw new Interrupt(); > > echo "Execution resumed!"; > } > > try > { > test(); > } > catch (Interrupt $e) > { > echo "Execution interrupted.\n"; > resume; > } > > The output of this would be: > > Begin Test! > Execution interrupted. > Execution resumed! > > In other words, Interrupt is a new type of Exception, from which you can > recover, using the new resume keyword. > > 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. > > I'm sure there are lots of problems with this idea, and perhaps it's not a > good fit for PHP at all, but I figured it couldn't harm to put the idea out > there anyway :-) > > Any thoughts? >

« previous php.internals (#59333) next »