Add promise to runner.

@param PromiseCore $core
778149
public function add(PromiseCore $core): void
    {
        foreach ($this->cores as $existed) {
            if ($existed === $core) {
                return;
            }
        }

        $this->cores[] = $core;

        if (null === $this->multiHandle) {
            $this->multiHandle = curl_multi_init();
        }
        curl_multi_add_handle($this->multiHandle, $core->getHandle());
    }
251143
private function createPromiseForPush(PushInterface $push, RecipientInterface $recipient): PromiseInterface {
        return $this->client->sendAsync($this->prepareRequest($push->getMessage(), $recipient))
            ->otherwise(function (\Exception $exception) use ($push, $recipient) {
                $push->setFailedFor($recipient, $exception);
            });
    }
1315938
def promise(*args, &callback)
      parent, headers, flags = *args
      promise = new_stream(parent: parent)
      promise.send(
        type: :push_promise,
        flags: flags,
        stream: parent.id,
        promise_stream: promise.id,
        payload: headers.to_a,
      )

      callback.call(promise)
    end
471175
public function handle(Message $message, array $options=[]) : PromiseInterface
    {
        $promise = new Promise(function () use (&$promise, $message, $options) {
            $promise->resolve(call_user_func(
                $this->callback,
                $message,
                $options
            ));
        });

        return $promise;
    }
133236
public function enqueue_core() {

		// Register uix core asset.
		$this->core_assets();
		$this->enqueue_actions();
		// push assets to ui manager.
		uix()->set_assets( $this->assets );
		// done enqueuing - dpo inline or manual enqueue.
		$this->set_active_styles();
	}
527945
public function promise(): Promise
    {
        return new class($this) implements Promise {

            private $defer;

            public function __construct(Deferred $defer)
            {
                $this->defer = $defer;
            }

            /**
             * {@inheritdoc}
             */
            public function when(callable $callback): void
            {
                if ($this->defer->state & AbstractPromise::SUCCEEDED) {
                    try {
                        $callback(null, $this->defer->result);
                    } catch (\Throwable $e) {
                        $this->defer->context->handleError($e);
                    }
                } elseif ($this->defer->state & AbstractPromise::FAILED) {
                    try {
                        $callback($this->defer->result);
                    } catch (\Throwable $e) {
                        $this->defer->context->handleError($e);
                    }
                } elseif ($this->defer->result) {
                    if (\is_array($this->defer->result) && isset($this->defer->result[0])) {
                        $this->defer->result[] = $callback;
                    } else {
                        $this->defer->result = [
                            $this->defer->result,
                            $callback
                        ];
                    }
                } else {
                    $this->defer->result = $callback;
                }
            }
        };
    }
883495
public function addPromise(string $name, callable $promise, ?int $priority = null)
    {
        $this->wpProvider
            ->addFilter($name, $promise, $priority);
    }
247166
protected function send(PromiseInterface $promise)
    {
        $pid     = $this->protocol->getPid();
        $origin  = $this->protocol->getOrigin();
        $message = $this->message;
        $channel = $this->channel;

        if ($message instanceof Error || $message instanceof Exception)
        {
            $answer = $channel
                ->createProtocol($message->getMessage())
                ->setPid($pid, true)
                ->setException(get_class($message), true)
            ;
        }
        else
        {
            $answer = $channel
                ->createProtocol($message)
                ->setPid($pid, true)
            ;
        }

        $this->channel->send(
            $origin,
            $answer,
            Channel::MODE_BUFFER_ONLINE
        );

        return $promise->resolve();
    }
335216
@SafeVarargs
    public final PromiseAggregator<V, F> add(Promise<V>... promises) {
        if (promises == null) {
            throw new NullPointerException("promises");
        }
        if (promises.length == 0) {
            return this;
        }
        synchronized (this) {
            if (pendingPromises == null) {
                int size;
                if (promises.length > 1) {
                    size = promises.length;
                } else {
                    size = 2;
                }
                pendingPromises = new LinkedHashSet<Promise<V>>(size);
            }
            for (Promise<V> p : promises) {
                if (p == null) {
                    continue;
                }
                pendingPromises.add(p);
                p.addListener(this);
            }
        }
        return this;
    }
560151
public function start(Context $context, array $args = []): Promise
    {
        $factory = $context->lookup(ProcessFactory::class);
        
        if ($factory === null) {
            throw new \RuntimeException('Cannot launch an async process without a process factory');
        }
        
        $options = [];
        
        foreach ($this->options as $k => $v) {
            if (\strlen($k) === 1) {
                $name = '-' . $k;
            } else {
                $name = '--' . $k;
            }
            
            if ($v === null) {
                $options[] = $name;
            } else {
                foreach ($v as $val) {
                    $options[] = $name;
                    $options[] = $val;
                }
            }
        }
        
        return $context->task($factory->createProcess($context, $this->command, \array_merge($options, $args), $this->dir, $this->env));
    }
528609
public function addProcessor(ProcessorInterface $processor)
    {
        $this->processors[] = $processor;
        $this->logDebug('Added processor: ' . get_class($processor));
    }
548079
public function get(string $uri): PromiseInterface
    {
        $request = new Request($uri);

        return $this->processRequest($request);
    }
1330767
public function promise($hydrationMode = self::RESULT_TYPE_HYDRATED)
    {
        /** @var PromiseInterface $promise */
        $promise = new Promise(function () use (&$promise, $hydrationMode) {
            $promise->resolve($this->execute($hydrationMode));
        });

        return $promise;
    }
1288698
public function optimize($core = null)
    {
        if ($core === null) {
            $core = $this->getCore();
        }

        return $this->request('GET', $core.'/update', ['optimize' => 'true']);
    }
209058
public function addAnonymousPromise(callable $promise, ?int $priority = null)
    {
        $priority = $priority ?? static::DEFAULT_PRIORITY;

        $this->pool[] = compact('priority', 'promise');
    }
1212547
public void add(Object msg, ChannelPromise promise) {
        assert ctx.executor().inEventLoop();
        if (msg == null) {
            throw new NullPointerException("msg");
        }
        if (promise == null) {
            throw new NullPointerException("promise");
        }
        // It is possible for writes to be triggered from removeAndFailAll(). To preserve ordering,
        // we should add them to the queue and let removeAndFailAll() fail them later.
        int messageSize = size(msg);

        PendingWrite write = PendingWrite.newInstance(msg, messageSize, promise);
        PendingWrite currentTail = tail;
        if (currentTail == null) {
            tail = head = write;
        } else {
            currentTail.next = write;
            tail = write;
        }
        size ++;
        bytes += messageSize;
        tracker.incrementPendingOutboundBytes(write.size);
    }
43389
public function compile(Core $core, ITemplate $template)
    {
        // init vars
        //		$compiled = '';
        $tpl                  = $template->getSource();
        $ptr                  = 0;
        $this->core           = $core;
        $this->template       = $template;
        $this->templateSource = &$tpl;
        $this->pointer        = &$ptr;

        while (true) {
            // if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed
            if ($ptr === 0) {
                // resets variables
                $this->usedPlugins     = array();
                $this->data            = array();
                $this->scope           = &$this->data;
                $this->scopeTree       = array();
                $this->stack           = array();
                $this->line            = 1;
                $this->templatePlugins = array();
                // add top level block
                $compiled                 = $this->addBlock('TopLevelBlock', array(), 0);
                $this->stack[0]['buffer'] = '';

                if ($this->debug) {
                    echo "\n";
                    echo 'COMPILER INIT' . "\n";
                }

                if ($this->debug) {
                    echo 'PROCESSING PREPROCESSORS (' . count($this->processors['pre']) . ')' . "\n";
                }

                // runs preprocessors
                foreach ($this->processors['pre'] as $preProc) {
                    if (is_array($preProc) && isset($preProc['autoload'])) {
                        $preProc = $this->loadProcessor($preProc['class'], $preProc['name']);
                    }
                    if (is_array($preProc) && $preProc[0] instanceof Processor) {
                        $tpl = call_user_func($preProc, $tpl);
                    } else {
                        $tpl = call_user_func($preProc, $this, $tpl);
                    }
                }
                unset($preProc);

                // show template source if debug
                if ($this->debug) {
                    echo '<pre>'.print_r(htmlentities($tpl), true).'</pre>'."\n";
                }

                // strips php tags if required by the security policy
                if ($this->securityPolicy !== null) {
                    $search = array('{<\?php.*?\?>}');
                    if (ini_get('short_open_tags')) {
                        $search = array('{<\?.*?\?>}', '{<%.*?%>}');
                    }
                    switch ($this->securityPolicy->getPhpHandling()) {
                        case SecurityPolicy::PHP_ALLOW:
                            break;
                        case SecurityPolicy::PHP_ENCODE:
                            $tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl);
                            break;
                        case SecurityPolicy::PHP_REMOVE:
                            $tpl = preg_replace($search, '', $tpl);
                    }
                }
            }

            $pos = strpos($tpl, $this->ld, $ptr);

            if ($pos === false) {
                $this->push(substr($tpl, $ptr), 0);
                break;
            } elseif (substr($tpl, $pos - 1, 1) === '\\' && substr($tpl, $pos - 2, 1) !== '\\') {
                $this->push(substr($tpl, $ptr, $pos - $ptr - 1) . $this->ld);
                $ptr = $pos + strlen($this->ld);
            } elseif (preg_match('/^' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', substr($tpl, $pos), $litOpen)) {
                if (!preg_match('/' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) {
                    throw new CompilationException($this, 'The {literal} blocks must be closed explicitly with {/literal}');
                }
                $endpos = $litClose[0][1];
                $this->push(substr($tpl, $ptr, $pos - $ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos - $pos - strlen($litOpen[0])));
                $ptr = $endpos + strlen($litClose[0][0]);
            } else {
                if (substr($tpl, $pos - 2, 1) === '\\' && substr($tpl, $pos - 1, 1) === '\\') {
                    $this->push(substr($tpl, $ptr, $pos - $ptr - 1));
                    $ptr = $pos;
                }

                $this->push(substr($tpl, $ptr, $pos - $ptr));
                $ptr = $pos;

                $pos += strlen($this->ld);
                if ($this->allowLooseOpenings) {
                    while (substr($tpl, $pos, 1) === ' ') {
                        $pos += 1;
                    }
                } else {
                    if (substr($tpl, $pos, 1) === ' ' || substr($tpl, $pos, 1) === "\r" || substr($tpl, $pos, 1) === "\n" || substr($tpl, $pos, 1) === "\t") {
                        $ptr = $pos;
                        $this->push($this->ld);
                        continue;
                    }
                }

                // check that there is an end tag present
                if (strpos($tpl, $this->rd, $pos) === false) {
                    throw new CompilationException($this, 'A template tag was not closed, started with "' . substr($tpl, $ptr, 30) . '"');
                }

                $ptr += strlen($this->ld);
                $subptr = $ptr;

                while (true) {
                    $parsed = $this->parse($tpl, $subptr, null, false, 'root', $subptr);

                    // reload loop if the compiler was reset
                    if ($ptr === 0) {
                        continue 2;
                    }

                    $len = $subptr - $ptr;
                    $this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n"));
                    $ptr += $len;

                    if ($parsed === false) {
                        break;
                    }
                }
            }
        }

        $compiled .= $this->removeBlock('TopLevelBlock');

        if ($this->debug) {
            echo 'PROCESSING POSTPROCESSORS' . "\n";
        }

        foreach ($this->processors['post'] as $postProc) {
            if (is_array($postProc) && isset($postProc['autoload'])) {
                $postProc = $this->loadProcessor($postProc['class'], $postProc['name']);
            }
            if (is_array($postProc) && $postProc[0] instanceof Processor) {
                $compiled = call_user_func($postProc, $compiled);
            } else {
                $compiled = call_user_func($postProc, $this, $compiled);
            }
        }
        unset($postProc);

        if ($this->debug) {
            echo 'COMPILATION COMPLETE : MEM USAGE : ' . memory_get_usage() . "\n";
        }

        $output = "<?php\n/* template head */\n";

        // build plugin preloader
        foreach ($this->getUsedPlugins() as $plugin => $type) {
            if ($type & Core::CUSTOM_PLUGIN) {
                continue;
            }

            switch ($type) {
                case Core::CLASS_PLUGIN:
                case Core::CLASS_PLUGIN + Core::BLOCK_PLUGIN:
                    if (class_exists('Plugin' . $plugin) !== false) {
                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    } else {
                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_BLOCKS . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    }
                    break;
                case Core::CLASS_PLUGIN + Core::FUNC_PLUGIN:
                    if (class_exists('Plugin' . $plugin) !== false) {
                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    } else {
                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    }
                    break;
                case Core::FUNC_PLUGIN:
                    if (function_exists('Plugin' . $plugin) !== false) {
                        $output .= "if (function_exists('" . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    } else {
                        $output .= "if (function_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    }
                    break;
                case Core::SMARTY_MODIFIER:
                    $output .= "if (function_exists('smarty_modifier_$plugin')===false)".
                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
                    break;
                case Core::SMARTY_FUNCTION:
                    $output .= "if (function_exists('smarty_function_$plugin')===false)".
                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
                    break;
                case Core::SMARTY_BLOCK:
                    $output .= "if (function_exists('smarty_block_$plugin')===false)".
                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
                    break;
                case Core::PROXY_PLUGIN:
                    $output .= $this->getCore()->getPluginProxy()->getLoader($plugin);
                    break;
                default:
                    throw new CompilationException($this, 'Type error for ' . $plugin . ' with type' . $type);
            }
        }

        foreach ($this->templatePlugins as $function => $attr) {
            if (isset($attr['called']) && $attr['called'] === true && !isset($attr['checked'])) {
                $this->resolveSubTemplateDependencies($function);
            }
        }
        foreach ($this->templatePlugins as $function) {
            if (isset($function['called']) && $function['called'] === true) {
                $output .= $function['body'] . PHP_EOL;
            }
        }

        $output .= $compiled . "\n?>";

        $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*' . preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/') . ')/', ";\n", $output);
        $output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output);

        // handle <?xml tag at the beginning
        $output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output);

        // add another line break after PHP closing tags that have a line break following,
        // as we do not know whether it's intended, and PHP will strip it otherwise
        $output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0' . "\n", $output);

        if ($this->debug) {
            echo '=============================================================================================' . "\n";
            $lines = preg_split('{\r\n|\n|<br />}', $output);
            array_shift($lines);
            foreach ($lines as $i => $line) {
                echo ($i + 1) . '. ' . $line . "\r\n";
            }
            echo '=============================================================================================' . "\n";
        }

        $this->template = $this->dwoo = null;
        $tpl            = null;

        return $output;
    }