Using functions with async callback
Solved
Hi,
Problem:
We're having a situation where we want to call a function with an async callback.
The issue that arises is that the script thread terminates before the callback is executed.
Is there any way to prevent the script thread from terminating before we get the callback?
Background:
We're intending to read a collection containing phone numbers, call Twilio Api (an sms service) to send a message, and finally store the status from Twilio into another collection.
- db.users.find({...}).forEach((user) => {
- sendSms(user.phone, "A short message", (status) => {
- db.smsDeliveries.insert(status);
- });
- });
Immensely thankfull for any kind of help, input or suggestion that can make us able to achieve this.
PS! This task is an ad-hoc task in our work flow, otherwise we would have done this as part of our application.
Best regards,
Christian
Hi,
Thank you for your feedback.
MongoBooster has a build-in function await. It can await a promise or a promise array.
Please try the following code:
Hi,
Thank you for your feedback.
MongoBooster has a build-in function await. It can await a promise or a promise array.
Please try the following code:
Hi,
Thank you for your feedback.
MongoBooster has a build-in function await. It can await a promise or a promise array.
Please try the following code:
Hi,
Thank you for your feedback.
MongoBooster has a build-in function await. It can await a promise or a promise array.
Please try the following code:
That was exactly what I was looking for!
Thank you for saving the day ;)
Best regards,
Christian
That was exactly what I was looking for!
Thank you for saving the day ;)
Best regards,
Christian
Replies have been locked on this page!