ストライプノードAPIを使用しているすべての顧客のリストをコンパイルしようとしています。一度に100人の顧客を継続的に取得する必要があります。非同期待機を使用するためにAPI呼び出し内でPromiseを使用する必要があると私は信じていますが、私の人生にとってはどこに置くのか分かりません。この要点を一般に使用することを願って、私はそれを正しく、感謝したい。すべてのストライプ顧客を非同期で取得することをお待ちしております
getAllCustomers()
function getMoreCustomers(customers, offset, moreCustomers, limit) {
if (moreCustomers) {
stripe.customers.list({limit, offset},
(err, res) => {
offset += res.data.length
moreCustomers = res.has_more
customers.push(res.data)
return getMoreCustomers(customers, offset, moreCustomers, limit)
}
)
}
return customers
}
async function getAllCustomers() {
const customers = await getMoreCustomers([], 0, true, 100)
const content = JSON.stringify(customers)
fs.writeFile("/data/stripe-customers.json", content, 'utf8', function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
のように固定することができる... '偶然約束を返しstripe.customers.list'ん? –
@JaromandaXはいそれは – user4815162342
約束どおりに解決しますか?コールバックの 'res'と同じですか? –