public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
{
$disposed = false;
$disposable = new CompositeDisposable();
$selectObserver = new CallbackObserver(function ($nextValue) use($observer, &$disposed) {
$value = null;
try {
$value = call_user_func_array($this->selector, [$nextValue]);
} catch (\Exception $e) {
$observer->onError($e);
}
if (!$disposed) {
$observer->onNext($value);
}
}, [$observer, 'onError'], [$observer, 'onCompleted']);
$disposable->add(new CallbackDisposable(function () use(&$disposed) {
$disposed = true;
}));
$disposable->add($observable->subscribe($selectObserver, $scheduler));
return $disposable;
}