Hello ,
I used to make sync request but this is not more the way to do it, how then ?
Let’s say I want to query collections to give some stats about the user or the server in the welcome mail…
subject(user) {
let subject = WhateverCollection.find().countAsync() + " other things to see" ;
return subject;
}
I have tried to set subject async and await the response but the email is empty.
Any idea ?
Yep not really.
Is async request mandatory in Meteor 3 ?
The code used to work with 2.X .
I think your code above is missing an await.
Those email methods are being called synchronous like once you need to send it, you send it and forget.
This means that everything inside the email object needs to be available at the time the email has to go.
If you build some data in the email using async function (get data from the DB), this data will be awaited asynchronously into a synchronous function so … those results/data will be undefined
.
One way to avoid this is to have your Email method inside a Meteor methods that prepares your data before the Email method is being called.
In Meteor 3 not everything has to be async but everything that calls something (from) outside Node (clients, MongoDb, Fetch) needs to be async.
sure, but await don’t solve the probleme because email template are not expected to be async … so there are no content in the mail.