By the way, it’s possible to use async/await with current non-promise Meteor APIs. For example, here’s how we can promisify a Meteor.call() so that we can await on it:
function callMeteorMethod(methodName, ...args) {
return new Promise((resolve, reject) => {
Meteor.call(methodName, ...args, (error, result) => {
if (error) reject(error)
else resolve(result)
})
})
}
async function main() {
let result = await callMeteorMethod('foo', 1, 2, 3)
console.log(result)
}
main()
Now you can use callMeteorMethod everywhere, instead of Meteor.call. If you happen to use it outside of an async function, you an still handle the result as you normally would with a promise:
function notAsync() {
callMeteorMethod('foo', 1, 2, 3)
.then(result => console.log(result))
}
notAsync()
You may have to take certain extra care (maintaining the Fibers context) in order to implement callMeteorMethod on the server-side.