Skip navigation
Currently Being Moderated

Using startAsyncTask and getting a return value

Mar 25, 2012 1:45 PM



I'm just starting to try and learn LUA and the whole Lightroom SDK.  Here is a sample of my code:


local lrApplication = import 'LrApplication'

local LrTasks = import 'LrTasks'


local activeCatalog = lrApplication.activeCatalog()

local currentPhotos = activeCatalog:getMultipleSelectedOrAllPhotos()

local y = LrTasks.startAsyncTask(function() return currentPhotos[1]:getFormattedMetadata('fileName') end)


wheneven I check or try to use y it is nil.


Please someone tell me the stupid thing I'm doing wrong so I don't lose any more of my dwindling hair. 


I know that currentPhotos has 5 photos in it's collections because later on I do this:

     for i, onePhoto in ipairs(currentPhotos) do

and it loops through 5 times, which matches up to the number of photos in the folder I have selected in Lightroom.




  • Currently Being Moderated
    Mar 25, 2012 3:01 PM   in reply to ZoominX55_2

    start-async-task doesn't return a value, it just schedules a task and keeps on going - the task runs later.


    In general, it's best to start a task immediately in response to a button press or menu selection..., and do everything within that task. - then you don't have to start them anywhere else, unless you need them as true parallel processes, like background tasks.


    To keep multiple tasks from starting due to asyncronous events, use some form of recursion guarding.



    Mark as:
  • Currently Being Moderated
    Mar 25, 2012 4:15 PM   in reply to ZoominX55_2



    Note, consider post-async-task-with-context, instead of start-async-task.


    The difference is that you can use the context to define error handling, so errors that occur aren't deep 6'd when it's in response to button press, as example.


    More info and elare plugin framework here:


    PS - source code there is out of date - for fresh stuff.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points