Skip to main content
areohbee
Legend
August 31, 2010
Question

Feature Request: LrTasks.executeSyncTask... & startAsyncTaskOnce

  • August 31, 2010
  • 2 replies
  • 1300 views

I'm finding a lot of things want to be done from an "async" task, for Lightroom's sake, yet they need to be "synchronous" for the sake of the plugin. I use flag variables presently as a work around to wait for a task, but it would be better if this were supported natively.

Another thing that would help is a one-instance-only capability for async tasks - so if you tried to start a second one before the first was finished it wouldn't start. This would help for example when writing a button handler that does stuff that must be via asynchronous task, but really shouldn't do more than once until last invocation is finished.

Rob

This topic has been closed for replies.

2 replies

Inspiring
March 29, 2017

resurrecting this;

LrFtp seems to be another case in point. Create, putFile etc need to be called from an asyncTask. This is fine until the count of files you're uploading goes beyond the number of concurrent transfers allowed by the server. Running as an asynctask is fine, multiple concurrent transfers speeds uploads quite considerably but you need a way to limit the number of tasks running at any given time.

johnrellis
Legend
March 29, 2017

need a way to limit the number of tasks running at any given time.

My plugins use two different methods:

1. A counter tracks the number of active worker tasks, incremented when a task beings and decremented when it exits. When the plugin wants to create a new worker task, it spins politely until there's less than the maximum number of workers active:

while nWorkers >= MaxWorkers do LrTasks.sleep (0.1) end

Spinning like this offends the experienced programmer but is a practical solution -- I use it in many places in my plugins.  The CPU overhead is tiny, as long as you choose the sleep time to be as large as possible without affecting the latency of whatever task you're performing.

2. Work needing processing (e.g. files to be transferred) are added to a queue.  At the start of work, the plugin creates the maximum number of worker tasks, which repeatedly take work off the queue and process it, exiting when the queue is empty.

Inspiring
March 29, 2017

1. is more or less where I am. I just felt it was worth raising. Thanks for the thoughts.

September 1, 2010

Maybe it's good idea to solve the general issue by adding mutexes or critical sections. This way you'll be able to do whatever you want and tune it right.

Marin

areohbee
areohbeeAuthor
Legend
September 1, 2010

That would do it.

_R

September 2, 2010

Critical section work around (though very ugly) - do writing to the lock variable in a WWAD gate.

Marin