rap2hpoutre / nestor
执行任务,如果出现错误则回滚。就像数据库事务一样。
v0.0.3
2015-10-02 15:22 UTC
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-09-05 20:35:58 UTC
README
安装
composer require rap2hpoutre/nestor
使用
运行一些任务。在这个例子中,第二个任务失败,所有内容都将回滚。
$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();
你应该看到
task 1 done
task 2 cancelled
task 1 cancelled
为什么?
待办:解释原因。
关于
感谢 DonoSybrix。欢迎贡献力量。