From 658edf33f74d1709e22f50395eb35d00df2d4e93 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 11 Aug 2016 13:33:51 -0500 Subject: [PATCH] Use Closure::fromCallable() in 7.1 --- lib/Emitter.php | 15 +++++++-------- lib/Internal/Producer.php | 11 ++++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Emitter.php b/lib/Emitter.php index b2a60ce..5e07407 100644 --- a/lib/Emitter.php +++ b/lib/Emitter.php @@ -11,14 +11,13 @@ final class Emitter implements Observable { public function __construct(callable $emitter) { $this->init(); - /** - * @param mixed $value - * - * @return \Interop\Async\Awaitable - */ - $emit = function ($value) { - return $this->emit($value); - }; + if (PHP_VERSION_ID >= 70100) { + $emit = \Closure::fromCallable([$this, 'emit']); + } else { + $emit = function ($value) { + return $this->emit($value); + }; + } $result = $emitter($emit); diff --git a/lib/Internal/Producer.php b/lib/Internal/Producer.php index e46ab68..f56cccd 100644 --- a/lib/Internal/Producer.php +++ b/lib/Internal/Producer.php @@ -50,9 +50,14 @@ trait Producer { */ private function init() { $this->waiting = new Future; - $this->unsubscribe = function ($id) { - $this->unsubscribe($id); - }; + + if (PHP_VERSION_ID >= 70100) { + $this->unsubscribe = \Closure::fromCallable([$this, 'unsubscribe']); + } else { + $this->unsubscribe = function ($id) { + $this->unsubscribe($id); + }; + } } /**