同步返回 AWS SDK 承诺的结果?

Synchronously returning the result of an AWS SDK promise?

我正在使用 AWS SDK 并承诺:

public function foo(){
    ...
    $pool = new CommandPool($client, $commands, [
        ....
    ]);
    $promise = $pool->promise();
    $result = $promise->wait();
    $promise->then(function () {
          return 'ok';
    });
}

如何从 foo 同步 return promise 的结果?

我试过:

return $promise->then(function () {
       return 'ok';
 });

但是这个 return 是 promise 本身,而不是 'ok',并导致我的框架出错:

The Response content must be a string or object implementing __toString(), "object" given.

AWS SDK使用guzzle/promises,可以使用wait方式同步解析:

return $promise->then(function () { return 'ok'; })->wait();

参见https://github.com/guzzle/promises#synchronous-wait and http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/promises.html