I'm having trouble finding out why my code never ends execution and gets stuck. It logs done
before doing anything in the async run()
block. The code just hangs with an output of:
done
test
test
async function successfullyPaid(doc){
return await updateMongoDBStuff();
}
async function run() {
findMongoDBstuff();
await cursor.forEach(async (doc) => { //forEach being Mongo's cursor iterator, not the Native JS one
console.log('test')
if (doc.plan.nextPayment <= getUnixTimeSeconds()) {
if (parseInt(doc.plan.remaining) >= 0){
allProds = client.db('ProductsDB').collection('allProds')
let prod = await allProds.findOne({})
amount = prod.recurring.periods[doc.plan.period]
let data = {
"transaction": {
"amount" : "1000",
"payment_method_token": `visa_card`,
"currency_code": "USD",
"retain_on_success": true,
"email" : doc.client.email}}
let response = await superagent.post(`https://example.com`).send(data).set('accept', 'json').auth('xxxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxxx');
if (response.body.transaction.succeeded == true){
await successfullyPaid(doc)
}
else{
console.log(response)
}
}}});
}
run().catch((error)=>{console.log(error);}).then(console.log('done'));
Any ideas?