Invokes any termination callbacks.

@return Promise
5088
private static function terminate(): Promise
    {
        if (self::$onClose === null) {
            return Promise\any([]);
        }

        if (self::$signalWatchers) {
            foreach (self::$signalWatchers as $watcher) {
                Loop::cancel($watcher);
            }
        }

        $onClose = self::$onClose;
        self::$onClose = null;

        $promises = [];
        foreach ($onClose as $callable) {
            $promises[] = call($callable);
        }

        return Promise\any($promises);
    }
1065172
function caller() {
  const returnedArgs = Array.prototype.slice.call(arguments)
  const fn = returnedArgs.shift()
  const self = this

  return wrapPromise(function (resolve, reject) {
    returnedArgs.push(function (err, args) {
      if (err) {
        reject(err)
        return
      }

      resolve(args)
    })

    fn.apply(self, returnedArgs)
  })
}
859880
protected function resolve($value = null): void
    {
        if (~$this->state & AbstractPromise::PENDING) {
            return;
        }
        
        if ($value instanceof Promise) {
            $value->when(function (?\Throwable $e, $v = null): void {
                if ($e === null) {
                    $this->resolve($v);
                } else {
                    $this->fail($e);
                }
            });
            
            return;
        }
        
        $callbacks = $this->result;
        
        $this->state ^= AbstractPromise::PENDING | AbstractPromise::SUCCEEDED;
        $this->result = $value;
        
        if ($this instanceof Cancellable) {
            $this->context->unregisterCancellation($this);
        }
        
        if ($callbacks) {
            if (\is_array($callbacks)) {
                foreach ($callbacks as $callback) {
                    try {
                        $callback(null, $value);
                    } catch (\Throwable $e) {
                        $this->context->handleError($e);
                    }
                }
            } else {
                try {
                    $callbacks(null, $value);
                } catch (\Throwable $e) {
                    $this->context->handleError($e);
                }
            }
        }
    }
301918
public function cliRegister() : Closure
  {
    return function($exception, $inspector, $run) {
      Output::error($exception);
      die($exception . PHP_EOL);
      exit;
    };
  }
1179234
private function createPipelineCallback() : Closure
    {
        return function ($stack, $pipe) {
            return function ($request) use ($stack, $pipe) {
                if ($pipe instanceof Closure) {
                    return call_user_func($pipe, $request, $stack);
                } elseif (!is_object($pipe)) {
                    list($callback, $parameters) = $this->createParameters($pipe, $request, $stack, true);
                } else {
                    if (!method_exists($pipe, $this->method)) {
                        throw new PipelineException(sprintf("%s::%s doesn't exist", get_class($pipe), $this->method));
                    }

                    list($callback, $parameters) = $this->createParameters($pipe, $request, $stack);
                }

                return $this->call($callback, $parameters);
            };
        };
    }
88127
function close(): \React\Promise\PromiseInterface {
        if($this->goingAway) {
            return $this->goingAway;
        }
        
        $deferred = new \React\Promise\Deferred();
        $this->goingAway = $deferred->promise();
        
        $closes = array();
        
        /** @var \Plasma\DriverInterface  $conn */
        foreach($this->connections->all() as $conn) {
            $closes[] = $conn->close();
            $this->connections->delete($conn);
        }
        
        /** @var \Plasma\DriverInterface  $conn */
        foreach($this->busyConnections->all() as $conn) {
            $closes[] = $conn->close();
            $this->busyConnections->delete($conn);
        }
        
        \React\Promise\all($closes)->then(array($deferred, 'resolve'), array($deferred, 'reject'));
        return $this->goingAway;
    }
365081
public function finalize()
	{
		try
		{
			if (isset($this->bufferAdd))
			{
				$this->bufferAdd->flush($this->overwrite, $this->commitWithin);
			}
			return null;
		}
		catch (\Solarium\Exception\HttpException $e)
		{
			$body = json_decode($e->getBody());
			$message = isset($body->error->msg) ? $body->error->msg : $e->getStatusMessage();
			return $message;
		}
	}
741094
public function process() {
        $this->promise = new Promise(function($r, $c, $n) {
            $this->resolve = $r;
            $this->createRejectFunction($c);
            $this->notify = $n;
            $this->executionCallback(null, true);
        });

        return $this->promise;
    }
407816
public function listen(): Promise
    {
        return call(function () {
            while (null !== ($chunk = yield $this->stream->read())) {
                foreach ($this->onNewFrameCallables as $newFrameCallable) {
                    $newFrameCallable($this->transformChunk($chunk));
                }
            }
        });
    }
116818
public function unlock(): Promise
    {
        return $this->pending = call(function () {
            if ($this->pending) {
                yield $this->pending;
            }

            if (!$this->isLocked()) {
                return;
            }

            if ($this->openCount === 1) {
                yield $this->storage->unlock($this->id);
                $this->status &= ~self::STATUS_LOCKED;
            }

            --$this->openCount;
        });
    }
97387
private function finalise()
    {
        // Send output to email
        $this->emailOutput();

        // Call any callback defined
        if (is_callable($this->after)) {
            call_user_func($this->after, $this->output, $this->returnCode);
        }
    }
11097
public function stop()
    {
        $deferred = new Deferred();

        $onStop = $this->onStop;
        $onStop()
            ->then(function () use (&$deferred) {
                $this->ariClient->onClose(function () use (&$deferred) {
                    $this->eventLoop->stop();
                    $deferred->resolve();
                });
                $this->wsClient->close();
            });

        return $deferred->promise();
    }
574366
public function close() : Promised
    {
        return
            ($this->pool
                ? $this->pool->shutdown()
                : (
                    $this->session
                        ? $this->session->close()
                        : Promise::resolved()
                )
            )->sync($this->closed())
        ;
    }
700500
public function stop()
    {
        if (!$this->running) {
            return;
        }

        $this->running = false;

        $promise = call(function () {
            $promises = [];
            foreach (clone $this->workers as $worker) {
                \assert($worker instanceof Internal\IpcParent);
                $promises[] = call(function () use ($worker) {
                    list($process, $promise) = $this->workers[$worker];
                    \assert($process instanceof Process);

                    try {
                        yield $worker->shutdown();
                        yield Promise\timeout($promise, self::WORKER_TIMEOUT);
                    } catch (ContextException $exception) {
                        // Ignore if the worker has already died unexpectedly.
                    } finally {
                        if ($process->isRunning()) {
                            $process->kill();
                        }
                    }
                });
            }

            list($exceptions) = yield Promise\any($promises);

            $this->workers = new \SplObjectStorage;

            if (!empty($exceptions)) {
                $exception = new MultiReasonException($exceptions);
                $message = \implode('; ', \array_map(function (\Throwable $exception): string {
                    return $exception->getMessage();
                }, $exceptions));
                throw new ClusterException("Stopping the cluster failed: " . $message, 0, $exception);
            }
        });

        $this->deferred->resolve($promise);
    }
1160385
public function invokeLastCall()
    {
        if (! $this->last_call) {
            return;
        }
        $args = $this->last_call;
        $func = array_shift($args);
        call_user_func_array($func, $args);
    }
129448
public function end()
    {
        $key = $this->queue->generateListKey();
        $key = "$key:" . $this->id;

        $retry = $this->getRetry();
        $result = $this->queue->getClient()->getRedis()->multi()
            ->del($key)
            ->hset(\date('Y-m-d') . '_pass', (string)\time(), \json_encode([
                'class' => $this->getWorkerClass(),
                'args' => $this->getArgs(),
                'retry' => \gettype($retry) === 'boolean' ? (bool)$retry : (int)($retry - 1),
                'priority' => (float)$this->getPriority(),
                'id' => $this->getId()
            ]))
            ->exec();

        return $result[0];
    }
28447
public function unlisten(): Promise
    {
        if (!$this->unlisten) {
            throw new \Error("Already unlistened on this channel");
        }

        /** @var Promise $promise */
        $promise = ($this->unlisten)($this->channel);
        $this->unlisten = null;

        return $promise;
    }