php-try
php-try copied to clipboard
Some API suggestions
I've some suggestions for the API after trying this a bit. Basically, I'm wondering what you think about something like this:
Attempt::call($someCallable)
->forAll($onSuccess)
->always($always) // Finally semantics (called regardless of success/failure)
->throwIfFailed()
;
This would be equivalent to:
try {
$rs = $someCallable();
$onSuccess($rs);
} finally {
$always();
}
Not sure if this is already supported in another way, but I haven't found anything. What do you think?