LrCatalog withWriteAccessDo - How to determine if the write to catalog has completed?
I'm in the midst of developing a plugin for Lightroom Classic, and was wondering if anyone had any tips on how to wait for a withWriteAccessDo() block to complete before proceeding with the code beyond it.
Essentially, I am writing to the catalog [via photo:applyDevelopSettings() method] and later need to access these updated settings from the stored photo in the catalog [via photo:getDevelopSettings() method].
Referencing the API documentation for withWriteAccessDo() in the Lightroom Classic SDK, it would seem that it is no longer designed to be update immediately:
As of version 3.0, changes you make to the database within this call do not have immediate effect, but are written to the database upon successful completion of the callback function. This means, in general, that if you create a new item (for instance, by calling catalog:createCollection()), you cannot retrieve information about that item until the with___AccessDo has finished. There are some special cases where you can reference the newly-created item; for instance, after creating a collection set, you can create a collection within that set. These cases are noted in the API documentation.
Does anyone have a suggestion as to how to wait until this block has completed execution? I wonder if it's possible to set up a polling function on a variable...though I've not yet been able to implement such a solution successfully.
The one way I've gotten it to work thus far is by adding a manual delay [via LrTasks.sleep(1.0) method] immediately after the withWriteAccessDo() block. This delays the timing of things and the later code runs correctly - however I worry that the required delay would vary based on a user's hardware, and am sure there is a better way to do this.
Any advice would be appreciated.
