{@inheritdoc}
@return \React\Promise\ExtendedPromiseInterface
492753
function clear($guild) {
        $guild = $this->getGuildID($guild);
        
        $this->settings->delete($guild);
        return $this->db->execute('DELETE FROM settings WHERE guild = ?', array($guild));
    }
920863
public function callAllPromises()
    {
        $pool = $this->pool;

        usort($pool, function ($a, $b) {
            return $a['priority'] - $b['priority'];
        });

        foreach ($pool as $node) {
            $promise = $node['promise'];
            $promise();
        }
    }
1000683
final public function buffer(): Promise
    {
        if ($this->promise) {
            return $this->promise;
        }

        return $this->promise = call(function () {
            $buffer = '';
            if ($this->lastRead && null === yield $this->lastRead) {
                return $buffer;
            }

            while (null !== $chunk = yield $this->stream->read()) {
                $buffer .= $chunk;
            }
            return $buffer;
        });
    }
2595
protected function carry()
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                $method = $this->method;
                if (is_callable($pipe)) {
                    // If the pipe is an instance of a Closure, we will just call it directly but
                    // otherwise we'll resolve the pipes out of the container and call it with
                    // the appropriate method and arguments, returning the results back out.
                    return $pipe($passable, $stack);
                } elseif (is_object($pipe)) {
                    // If the pipe is already an object we'll just make a callable and pass it to
                    // the pipe as-is. There is no need to do any extra parsing and formatting
                    // since the object we're given was already a fully instantiated object.
                    $parameters = [$passable, $stack];
                } else {
                    list($name, $methodFromString, $parameters, $needContainer) = $this->parsePipeData($pipe);
                    if ($methodFromString) {
                        $method = $methodFromString;
                    }

                    if (!$parameters) {
                        $parameters = [];
                    }

                    // If the pipe is a string we will parse the string and resolve the class out
                    // of the dependency injection container. We can then build a callable and
                    // execute the pipe function giving in the parameters that are required.
                    if (is_string($name)) {
                        //$pipe = $this->getContainer()->get($name);
                        $pipe = $this->getPipeStageFromContainer($name);
                    } else {
                        $pipe = $name;
                    }

                    $parameters = array_merge([$passable, $stack], $parameters);
                    //
                    if ($needContainer) {
                        $this->initialize($pipe);
                        $pipeReturn = function ($data, $next) use ($pipe, $method) {
                            if ($method) {
                                $data = $pipe->{$method}($data);
                            } else {
                                $data = $pipe($data);
                            }
                            return $next($data);
                        };
                        return $pipeReturn(...$parameters);
                    }
                }

                $this->initialize($pipe);

                if ($method) {
                    if (method_exists($pipe, $method)) {
                        return $pipe->{$method}(...$parameters);
                    }
                    throw new Exception('Method ' . $method . ' does not exist in stage with class ' . get_class($pipe));
                } else if ($pipe instanceof StageInterface) {
                    return $pipe->execute(...$parameters);
                } else {
                    return $pipe(...$parameters);
                }
            };
        };
    }
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);
    }
343339
private function createCommandHandler()
    {
        return function (CommandInterface $command) {
            return Promise\coroutine(function () use ($command) {
                // Prepare the HTTP options.
                $opts = $command['@http'] ?: [];
                unset($command['@http']);

                try {
                    // Prepare the request from the command and send it.
                    $request = $this->transformCommandToRequest($command);
                    $promise = $this->httpClient->sendAsync($request, $opts);

                    // Create a result from the response.
                    $response = (yield $promise);
                    yield $this->transformResponseToResult($response, $request, $command);
                } catch (\Exception $e) {
                    throw CommandException::fromPrevious($command, $e);
                }
            });
        };
    }
1023579
function spawn($gen) {
		$send  = array($gen, 'send');
		$throw = array($gen, 'throw');
		$run = function($fn, $in) use ($gen, $send, $throw, &$run) {
			try {
				while (true) {
					$val = Promise::interpret( $fn ? $fn($in) : $gen->current() );
					if ( ! $gen->valid() ) { $this->resolve( $fn == $throw ? null : $in); return; }
					if ( ! $val instanceof PromiseInterface ) {
						$fn = $send;  $in = $val;
					} else if ( $val->getState() === PromiseInterface::REJECTED ) {
						$fn = $throw; $in = GP\exception_for( GP\inspect($val)['reason'] );
					} else {
						$val->then(
							function($val) use($run, $send)  { $run( $send, $val ); },
							function($err) use($run, $throw) { $run( $throw, GP\exception_for($err) ); }
						);
						return;
					}
				}
			} catch (\Exception $e) {
				$this->reject($e);
			} catch (\Throwable $t) {
				$this->reject($t);
			}
		};
		if ( $gen instanceof \Generator ) {
			$run( null, null );
		} else {
			$this->resolve($gen);
		}
		if ( $this->getState() === PromiseInterface::FULFILLED )
			return $this->wait();
		return $this;
	}
331842
public function freshen()
    {
        if (! isset($this->endpoints['all'])) {
            return \React\Promise\reject(new \Exception('You cannot freshen this repository.'));
        }

        $deferred = new Deferred();

        $this->http->get(
            $this->replaceWithVariables(
                $this->endpoints['all']
            )
        )->then(function ($response) {
            $this->fill([]);

            foreach ($response as $value) {
                $value = array_merge($this->vars, (array) $value);
                $part = $this->factory->create($this->part, $value, true);

                $this->push($part);
            }
        }, function ($e) use ($deferred) {
            $deferred->reject($e);
        });
    }
921218
public function index(): Promise
    {
        return coroutine(function () {

            $pattern = Path::makeAbsolute('**/*.php', $this->rootPath);
            $uris = yield $this->filesFinder->find($pattern);

            $count = count($uris);
            $startTime = microtime(true);
            $this->client->window->logMessage(MessageType::INFO, "$count files total");

            /** @var string[] */
            $source = [];
            /** @var string[][] */
            $deps = [];

            foreach ($uris as $uri) {
                $packageName = getPackageName($uri, $this->composerJson);
                if ($this->composerLock !== null && $packageName) {
                    // Dependency file
                    if (!isset($deps[$packageName])) {
                        $deps[$packageName] = [];
                    }
                    $deps[$packageName][] = $uri;
                } else {
                    // Source file
                    $source[] = $uri;
                }
            }

            // Index source
            // Definitions and static references
            $this->client->window->logMessage(MessageType::INFO, 'Indexing project for definitions and static references');
            yield $this->indexFiles($source);
            $this->sourceIndex->setStaticComplete();
            // Dynamic references
            $this->client->window->logMessage(MessageType::INFO, 'Indexing project for dynamic references');
            yield $this->indexFiles($source);
            $this->sourceIndex->setComplete();

            // Index dependencies
            $this->client->window->logMessage(MessageType::INFO, count($deps) . ' Packages');
            foreach ($deps as $packageName => $files) {
                // Find version of package and check cache
                $packageKey = null;
                $cacheKey = null;
                $index = null;
                foreach (array_merge($this->composerLock->packages, (array)$this->composerLock->{'packages-dev'}) as $package) {
                    // Check if package name matches and version is absolute
                    // Dynamic constraints are not cached, because they can change every time
                    $packageVersion = ltrim($package->version, 'v');
                    if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) {
                        $packageKey = $packageName . ':' . $packageVersion;
                        $cacheKey = self::CACHE_VERSION . ':' . $packageKey;
                        // Check cache
                        $index = yield $this->cache->get($cacheKey);
                        break;
                    }
                }
                if ($index !== null) {
                    // Cache hit
                    $this->dependenciesIndex->setDependencyIndex($packageName, $index);
                    $this->client->window->logMessage(MessageType::INFO, "Restored $packageKey from cache");
                } else {
                    // Cache miss
                    $index = $this->dependenciesIndex->getDependencyIndex($packageName);

                    // Index definitions and static references
                    $this->client->window->logMessage(MessageType::INFO, 'Indexing ' . ($packageKey ?? $packageName) . ' for definitions and static references');
                    yield $this->indexFiles($files);
                    $index->setStaticComplete();

                    // Index dynamic references
                    $this->client->window->logMessage(MessageType::INFO, 'Indexing ' . ($packageKey ?? $packageName) . ' for dynamic references');
                    yield $this->indexFiles($files);
                    $index->setComplete();

                    // If we know the version (cache key), save index for the dependency in the cache
                    if ($cacheKey !== null) {
                        $this->client->window->logMessage(MessageType::INFO, "Storing $packageKey in cache");
                        $this->cache->set($cacheKey, $index);
                    } else {
                        $this->client->window->logMessage(MessageType::WARNING, "Could not compute cache key for $packageName");
                    }
                }
            }

            $duration = (int)(microtime(true) - $startTime);
            $mem = (int)(memory_get_usage(true) / (1024 * 1024));
            $this->client->window->logMessage(
                MessageType::INFO,
                "All $count PHP files parsed in $duration seconds. $mem MiB allocated."
            );
        });
    }
582626
function remove($user = null) {
        if($user !== null) {
            $user = $this->client->users->resolve($user);
        }
        
        return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($user) {
            $this->client->apimanager()->endpoints->channel
                ->deleteMessageUserReaction($this->message->channel->getId(), $this->message->id, $this->emoji->identifier, ($user !== null ? $user->id : '@me'))
                ->done(function () use ($resolve) {
                    $resolve($this);
                }, $reject);
        }));
    }
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);
            });
    }
910749
public static function fromObservable(ObservableInterface $observable, Deferred $deferred = null): ReactPromise
    {

        $d = $deferred ?: new Deferred(function () use (&$subscription) {
            $subscription->dispose();
        });

        $value = null;

        $subscription = $observable->subscribe(
            function ($v) use (&$value) {
                $value = $v;
            },
            function ($error) use ($d) {
                $d->reject($error);
            },
            function () use ($d, &$value) {
                $d->resolve($value);
            }
        );

        return $d->promise();
    }
899053
protected function getResult()
    {
        while ($this->result instanceof Promise && null !== $this->result->result)
        {
            $this->result = $this->result->result;
        }

        return $this->result;
    }
870316
function resolve() {
    var promises = [];
    var args = flatten(arguments);
    for (var i = 0; i < args.length; i ++) {
      promises.push(Esquire.resolve(args[i], true, true));
    }

    /* Await for resolution of dependencies */
    return Promise.all(promises).then(function(result) {
      var modules = {};
      for (var i = 0; i < result.length; i ++) {
        var resolved = result[i];
        for (var name in resolved) {
          var module = resolved[name];
          if (module.$$dynamic) continue;
          modules[name] = resolved[name];
        }
      }
      return modules;
    });
  }
1304238
function createReadCursor(string $query, array $params = array()): \React\Promise\PromiseInterface {
        if($this->goingAway) {
            return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
        }
        
        $connection = $this->getOptimalConnection();
        
        try {
            return $connection->createReadCursor($this, $query, $params);
        } catch (\Throwable $e) {
            $this->checkinConnection($connection);
            throw $e;
        }
    }
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;
    }
1034527
public function fulfill($value = null)
    {
        if (self::PENDING !== $this->state) {
            throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
        }
        $this->state = self::FULFILLED;
        $this->value = $value;
        foreach ($this->subscribers as $subscriber) {
            $this->invokeCallback($subscriber[0], $subscriber[1]);
        }
    }