private function createPromise()
    {
        // Create the promise
        $promise = call_user_func($this->promiseCreator, $this);
        $this->promiseCreator = null;

        // Cleans up the promise state and references.
        $cleanup = function () {
            $this->before = $this->client = $this->queue = null;
        };

        // When done, ensure cleanup and that any remaining are processed.
        return $promise->then(
            function () use ($cleanup)  {
                return Promise\promise_for($this->flushQueue())
                    ->then($cleanup);
            },
            function ($reason) use ($cleanup)  {
                $cleanup();
                return Promise\rejection_for($reason);
            }
        );
    }