__construct() public method

public __construct ( $computation = NULL )
Esempio n. 1
0
 public function __construct($executor = null)
 {
     parent::__construct();
     if (is_callable($executor)) {
         $self = $this;
         call_user_func($executor, function ($value) use($self) {
             $self->resolve($value);
         }, function ($reason) use($self) {
             $self->reject($reason);
         });
     }
 }
Esempio n. 2
0
 /**
  * @param \Generator $generator
  */
 public function __construct(Generator $generator)
 {
     parent::__construct();
     $this->generator = $generator;
     /**
      * @param mixed $value The value to send to the generator.
      */
     $this->send = function ($value = null) {
         if ($this->paused) {
             // If paused, save callable and value for resuming.
             $this->next = [$this->send, $value];
             return;
         }
         try {
             // Send the new value and execute to next yield statement.
             $this->next($this->generator->send($value));
         } catch (Throwable $exception) {
             $this->reject($exception);
             $this->close();
         }
     };
     /**
      * @param \Exception $exception Exception to be thrown into the generator.
      */
     $this->capture = function (Throwable $exception) {
         if ($this->paused) {
             // If paused, save callable and exception for resuming.
             $this->next = [$this->capture, $exception];
             return;
         }
         try {
             // Throw exception at current execution point.
             $this->next($this->generator->throw($exception));
         } catch (Throwable $exception) {
             $this->reject($exception);
             $this->close();
         }
     };
     try {
         $this->next($this->generator->current());
     } catch (Throwable $exception) {
         $this->reject($exception);
         $this->close();
     }
 }
Esempio n. 3
0
 /**
  * @param \Generator $generator
  */
 public function __construct(Generator $generator)
 {
     parent::__construct();
     $this->generator = $generator;
     /**
      * @param mixed $value The value to send to the generator.
      */
     $this->send = function ($value = null) {
         if ($this->busy) {
             Loop\queue($this->send, $value);
             // Queue continuation to avoid blowing up call stack.
             return;
         }
         try {
             // Send the new value and execute to next yield statement.
             $this->next($this->generator->send($value));
         } catch (Throwable $exception) {
             $this->reject($exception);
         }
     };
     /**
      * @param \Throwable $exception Exception to be thrown into the generator.
      */
     $this->capture = function (Throwable $exception) {
         if ($this->busy) {
             Loop\queue($this->capture, $exception);
             // Queue continuation to avoid blowing up call stack.
             return;
         }
         try {
             // Throw exception at current execution point.
             $this->next($this->generator->throw($exception));
         } catch (Throwable $exception) {
             $this->reject($exception);
         }
     };
     try {
         $this->next($this->generator->current());
     } catch (Throwable $exception) {
         $this->reject($exception);
     }
 }
Esempio n. 4
0
 /**
  * @param \Generator $generator
  */
 public function __construct(Generator $generator)
 {
     parent::__construct();
     $this->generator = $generator;
     /**
      * @param mixed $value The value to send to the generator.
      */
     $this->send = function ($value = null) {
         if (null === $this->generator) {
             // Coroutine may have been cancelled.
             return;
         }
         try {
             // Send the new value and execute to next yield statement.
             $this->next($this->generator->send($value));
         } catch (Throwable $exception) {
             $this->reject($exception);
         }
     };
     /**
      * @param \Throwable $exception Exception to be thrown into the generator.
      */
     $this->capture = function (Throwable $exception) {
         if (null === $this->generator) {
             // Coroutine may have been cancelled.
             return;
         }
         try {
             // Throw exception at current execution point.
             $this->next($this->generator->throw($exception));
         } catch (Throwable $exception) {
             $this->reject($exception);
         }
     };
     try {
         $this->next($this->generator->current());
     } catch (Throwable $exception) {
         $this->reject($exception);
     }
 }