Johannes Schlüter wrote on 28/10/2015 22:56:
On Wed, 2015-10-28 at 16:45 +, Rowan Collins wrote:
On the downside, it's worth noting that while PHP destructors are
technically deterministic, the language can actually prevent them
running on scope exit, because Exceptions hold references to
Thanks for your input.
I did not try-catch because it doesn't really work, you either
duplicate rollback code or get excessive nesting. Real code will
obviously be more complicated than the examples.
Also in both cases the handlers are many lines apart from the actual
transaction call.
Duplicate
On Wed, 2015-10-28 at 11:00 +0100, Erik van Velzen wrote:
> Subject says it all.
>
> I want to make a small "ScopeGuard" library for exception-safe
> transactions, like the following:
>
> $scope = new ScopeGuard;
>
> $scope->onSucces(function() { logTransactionOne(); });
>
I didn't see how it could be generalized but your example clears that up.
- Erik
2015-10-28 15:40 GMT+01:00 Rowan Collins :
>
> Did you see Johannes' suggestion re explicit success vs implicit failure?
>
> $scope = new ScopeGuard;
>
> $scope->onSucces(function() {
Erik van Velzen wrote on 28/10/2015 13:28:
try {
$scope = new ScopeGuard;
$scope->onSucces(function() { logTransactionOne(); });
$scope->onFailure(function() { rollbackTransationOne(); });
doTransactionOne();
$scope->onSuccess(function() {
Hi Erik,
On Wed, 28 Oct 2015 16:28:59 +0300, Erik van Velzen wrote:
Thanks for your input.
I did not try-catch because it doesn't really work, you either
duplicate rollback code or get excessive nesting. Real code will
obviously be more complicated than the examples.
Also in
Subject says it all.
I want to make a small "ScopeGuard" library for exception-safe
transactions, like the following:
$scope = new ScopeGuard;
$scope->onSucces(function() { logTransactionOne(); });
$scope->onFailure(function() { rollbackTransationOne(); });
doTransactionOne();
Erik van Velzen wrote on 28/10/2015 15:02:
The ScopeGuard's destructor can now detect the condition:
if ( $this->success_registered ) {
// Function reached checkpoint for this scope
$this->callSuccessHandlers();
} else {
// Function aborted early, due to a throw or early return
On Wed, 2015-10-28 at 16:45 +, Rowan Collins wrote:
> On the downside, it's worth noting that while PHP destructors are
> technically deterministic, the language can actually prevent them
> running on scope exit, because Exceptions hold references to everything
> used as a parameter in
On Wed, 2015-10-28 at 16:02 +0100, Erik van Velzen wrote:
> I didn't see how it could be generalized but your example clears that up.
Quick attempt of a generalization:
abstract class AbstractRAIIGuard {
private $succeeded = false;
protected abstract function fail();
protected
10 matches
Mail list logo