composer require proteins/deferred
Require the class via :
use Proteins\Deferred;
The passed callback will be queued for execution on Deferred object destruction.
function duel(){
echo "A: I will have the last word!\n";
echo "B: Wanna bet?\n";
$defer_B_last_word = new Deferred(function(){
echo "B: Haha! Gotcha!\n";
});
die("A: I WIN!\n"); // Hahaha!
echo "B: WUT?\n";
}
duel();
A: I will have the last word!
B: Wanna bet?
A: I WIN!
B: Haha! Gotcha!