public function resolve($value) { if ($value === $this) { $this->reject(new TypeError('Self resolution')); return; } if (isFuture($value)) { $value->fill($this); return; } if ($value !== NULL and is_object($value) or is_string($value)) { if (method_exists($value, 'then')) { $then = array($value, 'then'); $notrun = true; $self = $this; try { call_user_func($then, function ($y) use(&$notrun, $self) { if ($notrun) { $notrun = false; $self->resolve($y); } }, function ($r) use(&$notrun, $self) { if ($notrun) { $notrun = false; $self->reject($r); } }); } catch (UncatchableException $e) { throw $e->getPrevious(); } catch (Exception $e) { if ($notrun) { $notrun = false; $this->reject($e); } } catch (Throwable $e) { if ($notrun) { $notrun = false; $this->reject($e); } } return; } } if ($this->state === self::PENDING) { $this->state = self::FULFILLED; $this->value = $value; while (count($this->subscribers) > 0) { $subscriber = array_shift($this->subscribers); $this->privateResolve($subscriber['onfulfill'], $subscriber['next'], $value); } } }
public function unsubscribe($name, $id = null, $callback = null) { $self = $this; if (!is_string($name)) { throw new TypeError('topic name must be a string'); } if ($id === null && $callback === null) { unset($this->topics[$name]); return; } if (is_callable($id) && !is_callable($callback)) { $callback = $id; $id = null; } if ($id === null) { if ($this->id === null) { if (isset($this->topics[$name])) { $topics = $this->topics[$name]; $ids = array_keys($topics); foreach ($ids as $id) { $this->delTopic($topics, $id, $callback); } } } else { $this->id->then(function ($id) use($self, $name, $callback) { $self->unsubscribe($name, $id, $callback); }); } } elseif (isFuture($id)) { $id->then(function ($id) use($self, $name, $callback) { $self->unsubscribe($name, $id, $callback); }); } else { $this->delTopic($this->topics[$name], $id, $callback); } if (isset($this->topics[$name]) && count($this->topics[$name]) === 0) { unset($this->topics[$name]); } }
function toPromise($obj) { if (isFuture($obj)) { return $obj; } if (class_exists("\\Generator") && $obj instanceof \Generator) { return co($obj); } if (is_array($obj)) { return arrayToPromise($obj); } if (is_object($obj)) { return objectToPromise($obj); } return value($obj); }
function internalPush($topic, $id, $result) { if (isFuture($result)) { $self = $this; return $result->complete(function ($value) use($self, $topic, $id) { return $self->internalPush($topic, $id, $value); }); } $topics = $this->getTopics($topic); if (!isset($topics[$id])) { return value(false); } if (isset($topics[$id]->request)) { $topics[$id]->request->resolve($result); unset($topics[$id]->request); $this->setTimer($topics, $topic, $id); return value(true); } else { $detector = new Future(); $message = new stdClass(); $message->detector = $detector; $message->result = $result; $topics[$id]->messages->push($message); $this->setTimer($topics, $topic, $id); return $detector; } }
<label for="enabled">Enabled</label> <input type="checkbox" name="enabled" value="1" <?php if ($row['enabled']) { echo 'checked'; } ?> > </div> <div class='one columns small' style="float: right; margin-right: 30px;"> <input type='submit' class='slide_form button-primary' value='Update'/> </div> <div class='one columns medium'> <?php if (isFuture($row)) { echo "<h3 class='yellow'>Future</h3>"; } else { if (expired($row)) { echo "<h3 class='red'>Expired</h3>"; } else { echo "<h3 class='green'>Active</h3>"; } } ?> </div> <div class='one columns small' style="float: right; margin-right: 30px;"> <input type='hidden' name='id' value="<?php echo $row['id'];