I'm using TypeScript and wondering if there's a better way to await a MapView than what I'm currently doing. The example in the documentation shows how to supply a callback for the then promise when using vanilla JavaScript:
var view = new MapView();
view.then(function(){
// This code will execute once the promise is resolved
});
What I'd like to do is use the await keyword to avoid the nested function call. This is the only way I've been able get this to work:
let view = new MapView();
await view.then(() => {});
// This code will execute once the promise is resolved
Ideally I would be able to write something like this:
let view = new MapView();
await view;
// this code will execute after the promise is resolved
Although it doesn't compile with this error:
Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.
Thanks,
Alan
I haven't started using await yet but if I get a chance I'll try this out and see if I can replicate this issue.
Promises returned by the JS API tend to be a little different from the standard JS promises and this could possibly be related to this issue (the type is IPromise, based on dojo/deferred): jsapi-resources/arcgis-js-api.d.ts at master · Esri/jsapi-resources · GitHub