Are Promises/A a good event design pattern to implement even in synchronous languages like PHP?
- by Xeoncross
I have always kept an eye out for event systems when writing code in scripting languages. Web applications have a history of allowing the user to add plugins and modules whenever needed.
In most PHP systems you have a global/singleton event object which all interested parties tie into and wait to be alerted to changes.
Event::on('event_name', $callback);
Recently more patterns like the observer have been used for things like jQuery.
$(el).on('event', callback);
Even PHP now has built in classes for it.
class Blog extends SplSubject {
public function save()
{
$this->notify();
}
}
Anyway, the Promises/A proposal has caught my eye. It is designed for asynchronous systems, but I'm wondering if it is also a good design to implement now that even synchronous languages like PHP are changing.
Combining Dependency Injection with Promises/A seems it might be the best combination for handling events currently.