public function waitFor(AbstractDialog $dialog)
    {
        $done = false;
        $ret  = null;
        $loop = $this->loop;

        $process = $this->launch($dialog);

        $process->then(function ($result) use (&$ret, &$done, $loop) {
            $ret = $result;
            $done = true;

            $loop->stop();
        }, function () use (&$ret, &$done, $loop) {
            $ret = false;
            $done = true;

            $loop->stop();
        });

        if (!$done) {
            $loop->run();
        }

        return $ret;
    }