Skip to content

JS API should probably be asynchronous #14226

@dae

Description

@dae

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions