如何等待函数调用才能返回?

时间:2018-06-14 08:17:57

标签: javascript promise async-await

我尝试使用async / await然后我把await放在函数调用上,但即使它还没有完成它已经执行了下一行。

async function listFreeAccounts() {
    let rnds = [];
    await gun.get('freeAccounts').map().once((v, k) => {
        // this will be called many times defending on the number of values exists.
        // then push it on the array.
        rnds.push(k);
    });

    // Premature returns here, making the rnds values empty.
    return rnds;
};

如何在返回之前等待rnds中的所有值?

感谢。

修改

我正在使用gundb gun.get(...代码。

0 个答案:

没有答案
相关问题