public function then($onfulfill, $onreject = NULL)
{
if (!is_callable($onfulfill)) {
$onfulfill = NULL;
}
if (!is_callable($onreject)) {
$onreject = NULL;
}
$next = new Future();
if ($this->state === self::FULFILLED) {
$this->privateResolve($onfulfill, $next, $this->value);
} elseif ($this->state === self::REJECTED) {
$this->privateReject($onreject, $next, $this->reason);
} else {
array_push($this->subscribers, array('onfulfill' => $onfulfill, 'onreject' => $onreject, 'next' => $next));
}
return $next;
}