MapView doesnt work with async/await
See original GitHub issueThis probably applies to all interfaces that inherits from corePromise
If you try to return MapMiew instance in a promise using async
& await
you get compilation error:
Return expression in async function does not have a valid callable 'then' member.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Returning MapView instance from async function (or passing it ...
Somes ArcGIS JS API classes looks like promises as their instance present a then() method.
Read more >Swift Concurrency and Runtime - Esri Community
Introducing the ArcGIS Runtime async/await package. We're pleased to present a handy set of open source Swift files that fill the gap, ...
Read more >Programming patterns | ArcGIS Maps SDK for JavaScript 4.25
After getting the ArcGIS Maps SDK for JavaScript, use require() to asynchronously load ArcGIS Maps SDK for JavaScript classes into an application.
Read more >Implementing address autocomplete using SwiftUI and MapKit
I found it curious — to know how we can limit ourselves to using only SwiftUI and MapKit to solve a similar problem....
Read more >esri-loader - npm
A tiny library to help load ArcGIS API for JavaScript modules in ... Dojo's loader to require the classes loadModules(['esri/views/MapView', ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can convert any promise-like object such as IPromise into an ES6 promise by using Promise.resolve:
However, there is another issue that you will immediately run into. Several objects in the JavaScript API are promises that fullfill with themselves when resolved. When attempting to resolve such promises, promise implementations that follow the A+ promise specification must recurse forever (or optionally detect the cycle and reject with a TypeError). This applies to most browser’s native implementations and several popular polyfills such as Bluebird. If you run the above code in e.g. Google Chrome, it will simply hang forever. To get around this, I created the following helper function (written in TypeScript, which I infer is what you’re using):
The trick is that it returns a
Promise<void>
instead of e.g.Promise<MapView>
. The usage would then be:You might also find this helper useful as well:
Then you can do this if you need to load e.g. a layer:
Fixed in 4.6. See: https://blogs.esri.com/esri/arcgis/2017/12/14/making-better-promises/