-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
JS API should probably be asynchronous #14226
Description
The JS API is currently synchronous, and I think it might be a good idea to rethink this before people start using it in earnest. There may be a non-trivial delay between the time a request is made and it can be fulfilled, as another operation may already be running on the collection, and I/O may be slow. While the handler on the Kotlin side is called in a background thread, the JS side will block during that time, so the web interface will appear stuck until the request completes.
One way to resolve this would be to switch from using addJavascriptInterface() to instead defining a promise-based API. The API would internally send a message to the Kotlin side, and then resolve once a reply had been received. #14171 has introduced AnkiServer into the reviewer page to support custom scheduling, and it would probably be simplest to pass the messages back and forth using a post request to the server.
@krmanik thoughts? No rush; I know you're busy at the moment.