I am running into an issue where photo:requestJpegThumbnail is called more than once.
Basically, inside a LrTask, I am looping through a selection of photos and I am calling photo:requestJpegThumbnail for each of them. Since it seems there is no way I can pause my task during the callback is executed, I have a look with a sleep. I would prefer to use a promise for this if possible but I didn't find a way to do it. It actually works without any problem but... the callback of photo:requestJpegThumbnail is sometimes called more than once. I can use a isFirstTry variable in there and then it works but I want to avoid using any hack. Here is what my (pseudo) code looks like.
-- 'photos' is a selection of photos from the catalog
-- 'total' is the total number of photos and 'current' starts at 1
while not current < total do
local isRunning = true
current = current + 1
photo = photos[current]
thumbnail = photo:requestJpegThumbnail( 400, 400, function ( thumbnail )
-- hello! I am sometimes called more than once for the same photo
isRunning = false
while isRunning do
LrTasks.sleep( 1 / 5 )
I don't use requestJpegThumbnail, because of a multitude of problems I had with it. I use a proprietary reverse-engineered method instead.
That said, one thing of note:
If you reload the plugin, it won't auto-kill asynchronous tasks, so it's possible to have them stack up.
So, if you have any long-running tasks, it's good to have a LrShutdownPlugin module which sets a global 'shutdown' flag, then code your task functions thusly:
if killTask then return end
if shutdown then return end
Dunno if that will help your problem or not.
Similarly, use context:addCleanupHandler( function() killTask = true end ) kinda code to make sure tasks are killed in case of error..
Also, it would be good to put a watchdog timer on your calls to requestJpegThumbnail, so you're not wholly dependent on trust in callback to keep plugin from hanging.
I exactly did that, I am now using some kind of shutdown flag everywhere! I am not sure what else I have changed since 2 months ago but I don't have this issue at all anymore, maybe thanks to that.
Now I have some more work to do with the addCleanupHandler, I have to admit I don't use it for all my tasks...
Thanks for your help always Rob!