Async/await when calling a Meteor method from another method

I’m using the AWS sdk in my app. The sdk returns promises so I’m using async/await and that’s working. For example, here is a method that calls the describeAlarms api.

'aws.describeAlarms': async function(awsConfig, alarmName){
		console.log('aws.describeAlarms: ' );

		if (Meteor.isServer) {
			const creds = new AWS.Credentials({
				accessKeyId: awsConfig.accessKeyId,
				secretAccessKey: awsConfig.secretAccessKey
			});

			const cloudwatch = new AWS.CloudWatch({ region: awsConfig.region, credentials: creds });
			const params = ( (alarmName === undefined)? {} : { AlarmNames: [alarmName]});
			const result = await cloudwatch.describeAlarms(params).promise();
			console.log('aws.describeAlarms returning... ' );
			return result;
		}
	}

The issue is that I want to make a method that calls other methods. From the docs, it says “If you do not pass a callback on the server, the method invocation will block until the method is complete.”

'aws.describeServices' : async function(awsConfig){
		console.log('aws.describeServices');
		if (Meteor.isServer) {

			//TODO: this doesn't work
			const alarms = Meteor.call('aws.describeAlarms', awsConfig);
			console.log('aws.describeServices returning...');
			return alarms;
		}
	}

Looking at the console logging, I can see it’s not blocking. Doing

const alarms = await Meteor.call('aws.describeAlarms', awsConfig);

Doesn’t work either. What am I missing?

could be your issue here: https://github.com/meteor/meteor/issues/8367

It certainly could be. I’ll follow that issue. Thanks!

1 Like