/** * Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an * observable sequence. * * @param callable $action * @param SchedulerInterface $scheduler * @return AnonymousObservable * * @demo start/start.php * @operator * @reactivex start */ public static function start(callable $action, SchedulerInterface $scheduler = null) { $scheduler = $scheduler ?: new ImmediateScheduler(); $subject = new AsyncSubject(); $scheduler->schedule(function () use($subject, $action) { $result = null; try { $result = call_user_func($action); } catch (\Exception $e) { $subject->onError($e); return; } $subject->onNext($result); $subject->onCompleted(); }); return $subject->asObservable(); }