rap2hpoutre / nestor
Do task, rollback if something goes wrong. Just like database transactions.
Installs: 10 151
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 0
Open Issues: 0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-11-05 21:05:08 UTC
README
Installation
composer require rap2hpoutre/nestor
Usage
Run some tasks. In this example, the second task fails, everything will be rolled back.
$nestor = new Nestor\Servant; // Create 1st task $nestor->task() ->up(function (){ echo "task 1 done\n"; }) ->down(function () { echo "task 1 cancelled\n"; }); // Create 2nd task (will fail) $nestor->task() ->up(function ($nestor) { $nestor->fail(); echo "task 2 done\n"; }) ->down(function () { echo "task 2 cancelled\n"; }); // Run all tasks, rollback on fail (LIFO stack) $nestor->run();
You should see:
task 1 done
task 2 cancelled
task 1 cancelled
Why?
Todo: Explain why.
About
Thanks to DonoSybrix. Feel free to contribute.