| |||||||||||
command queue Posted by ardikus (ardikus), 7 July 2004 Hi everyone, I've been having some difficulty modifying the order in which commands are processed. What I am trying to create is a FIFO queue, that takes commands from the user via a button click, and spaces the commands 1 second apart each.I tried doing this using the vwait command, so that each time the button is clicked, it waits an additional second to execute the command. When a button is clicked, it runs a proc called SendCommand. In SendCommand, I have: incr CQ 1 set placeinline $CQ set n 0 after 1000 {set n 1} vwait n while {$placeinline > 1} { set m 0 after 1000 {set m 1} vwait m incr placeinline -1 } exec command x incr $CQ -1 Unfortunately if I click Button A, and then Button B before before command A is complete, the vwait in command B takes precedence and completes first. I need the commands to be executed in the order in which the buttons are clicked. Does anyone have any possible suggestions for how to set this up in TCL so that I can evenly space the execution of commands no matter how quickly I click the buttons? Any help is appreciated, and if further clarification is needed please let me know. Thanks in advance. Code: Posted by admin (Graham Ellis), 8 July 2004 I guess you're using Tk?Suggested scheme ... a) when a request comes in, add it on to a global list. b) In your main code (before you enter your main event handling loop), register an event to happen after one second. c) When your 1 second event happens, have it 1) Start the first process in your global list, if any 2) Move your global list up if necessary 3) Reset the event trigger Not something I've done, but have a look at "event generate" which I suspect has the facilities you need. Posted by ardikus (ardikus), 8 July 2004 Thanks a TON for your response, I finally got this thing figured out. Your suggestion was just what I needed. I used the FIFO queue suggested at this wiki site: http://wiki.tcl.tk/9552 and then drew my commands off of this queue in a main loop every one second. Once again thanks, this has been bugging me for days Posted by admin (Graham Ellis), 8 July 2004 Delighted to be of service ... and thanks for the onwards link too.This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |