Message queue (SOLVED)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Message queue (SOLVED)

Post by MaxV » Thu Feb 04, 2016 8:17 am

Hi,
I really don't know what is the best practice for creating a message queue.
I have a button that user can click any number of times: every time he clicks a process starts, but the new process can't start untill the old one finished.
The process duration time may change, so I can't use send to me in xxx sec.
I need to create a message queue, so every time the user clicks, he just add a process start request to a list.
I'm very scared of using something like repeat forever cicles to check the list.
(I'll need at least 16 of these buttons)
Last edited by MaxV on Thu Feb 04, 2016 4:20 pm, edited 1 time in total.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Message queue

Post by SparkOut » Thu Feb 04, 2016 8:43 am

On clicking a button, add the message to a list, eg custom property or field ( your queue) and send a message in 0 milliseconds to start the queue handler and set a flag to show it is running, or don't send the message if already running.
In the queue handler, take the first message in the list, remove it and unset the running flag if the list is now empty. Handle the queued item. On ending that handler check if the handler running flag is set and if so, call it again.
Best practice? Not sure but it seems doable

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Message queue

Post by MaxV » Thu Feb 04, 2016 1:16 pm

I tried it, but I get weird results.
Does anyone have some working example?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Message queue (SOLVED)

Post by MaxV » Thu Feb 04, 2016 4:37 pm

I solved this way:
########CODE#######
on mymess var1,var2
if the occupato of me then
send ("mymess " & var1 & comma & var2) to me in 0.1 sec
exit mymess
end if
set the occupato of me to true
#...the remaining code
#...
set the occupato of me to false
end mymess
#####END OF CODE#####

My mistake was to use the custom property also for other puporses, messing all... :oops:
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply