Weird variable errors with await?

I’m totally confused at this point. I’m trying to use a request to grab an image from mapquest, but I’m getting an Unexpected indentifier.

I’m using a request elsewhere successfully, but I have something like:

		let mapUrl = `${mapKey}&locations=${car_data.latitude},${car_data.longitude}&zoom=${mapZoomLevel}&format=png&size=${mapSizeQuery}&type=${mapType}&defaultMarker=marker-${mapIconColorPosition}`;
		var req = new Request(mapUrl);
		let mapImage = await req.loadImage();

But I get an “Unexpected identifier ‘req’. Expected ‘;’ after variable declaration.” on the last line.

I will admit that this is buried in some code that updates an object function:

	theme.medium.draw = function(widget,car_data,colors){
		blah... blah...

Which is probably related, but I have zero clue what the problem is. Anyone have some insight into this?

When you use await in a function you have to explicitly declare that function as async. If you need the return value or continue only when your function has finished then you have to await it too. If this last await is again in a function you have to declare it as async and so on…

1 Like