Javascript 使用Promise.all:TypeError时出错:中间值在

Javascript 使用Promise.all:TypeError时出错:中间值在,javascript,node.js,Javascript,Node.js,我正在尝试停止sql实例列表,因为它是异步的,所以我使用的是Promise.all 代码在以下情况下失败: TypeError: (intermediate value) is not iterable at Promise.all.sqlInstancesList.map (/workspace/index.js:40:53) at process._tickCallback (internal/process/next_tick.js:68:7) 我做错了什么 代码如下:

我正在尝试停止sql实例列表,因为它是异步的,所以我使用的是
Promise.all

代码在以下情况下失败:

TypeError: (intermediate value) is not iterable
    at Promise.all.sqlInstancesList.map (/workspace/index.js:40:53)
    at process._tickCallback (internal/process/next_tick.js:68:7)
我做错了什么
代码如下:

const { google } = require('googleapis')
const { auth } = require('google-auth-library')
const sqladmin = google.sqladmin('v1beta4')
​

exports.stopSqlInstance = async (event, context, callback) => {
        try {
​
                const authRes = await auth.getApplicationDefault()
​
                var sqlInstancesList = ["my-instance-name"];
​
                await Promise.all(
                        sqlInstancesList.map(async (instance) => {
                                console.info("stopping " + instance);
                                var request = {
                                        auth: authRes.credential,
                                        project: "my-project-id",
                                        instance: instance,
                                        requestBody: {
                                                 "settings": {
                                                          "activationPolicy": "NEVER"
                                                 }
                                         }  
                                }       
                                const [operation] = await sqladmin.instances.patch(request);
                                // Operation pending
                                return operation.promise();
                         })
                 );
​
                // Operation complete. Instance successfully stopped.
                const message = `Successfully stopped instance(s)`;
                console.log(message);
                callback(null, message);
​
        } catch(err) {
                console.error(err);
                callback(err);
        }

}

您是否尝试过返回操作而不是操作。promise()


因为如果您正在等待,则无需再次返回promise()

Is
var sqlInstancesList=[“我的实例名”]您的实际代码?是的,这是为了调试目的,在我完成这项工作后,我将从输入中获取实例列表(列表包含一个或多个)。如果您仍在调试,请尝试记录/检查
sqlInstancesList.map(…)
调用的结果。
const [operation] = await sqladmin.instances.patch(request);
                                // Operation pending
 return operation  // instead of operation.promise()