User Tools

Site Tools


dictionary:more:dolater

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dictionary:more:dolater [2017/06/02 21:03] – external edit 127.0.0.1dictionary:more:dolater [2023/02/13 14:52] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====Do Later==== ====Do Later====
 Execute a handler in the same script in some number of milliseconds. It’s often necessary to add in a “delay” to some scripts when talking to other devices or programs, unfortunately a delay causes the entire program to block until the delay is complete. This is not acceptable for an application that must remain responsive to other input while that script is running. **do later** lets you schedule handlers in a script to happen one after another as if the script was written entirely inline but with delay statements while avoiding the problems of blocking the entire app for extended periods of time. Execute a handler in the same script in some number of milliseconds. It’s often necessary to add in a “delay” to some scripts when talking to other devices or programs, unfortunately a delay causes the entire program to block until the delay is complete. This is not acceptable for an application that must remain responsive to other input while that script is running. **do later** lets you schedule handlers in a script to happen one after another as if the script was written entirely inline but with delay statements while avoiding the problems of blocking the entire app for extended periods of time.
 +
 +Do Later is similar to just using the [[dictionary:events:executescript|execute script]] verb and including the handler name property. This will create an event you can then manipulate in the scheduled event window, but the resolution of the time is one second. If you want to wait less than a second or if you are creating many and don’t want the scheduled event window to fill up with them then the do later verb is a good option. 
 +
 +There is no interface currently to the outstanding do later events you’ve created in a script. In order to stop a runaway do later cascade is to edit the script and just put a “return” at the front of the handler you’re calling back into so that it stops before the next do later is created.
 +
 +Don’t use do later for things that you need to adjust the timing of, or things where you might create more and more of them like a motion controlled light. Use the [[tutorials:motion_controlled_light|Motion Controlled Light]] technique for things like that.
 +
 +If you need a regular callback to the same handler or need to create such an event in another script use the [[dictionary:xtension:startidler|Start Idler]] command.
 +
 +A Global Script named “[[xtension_manual:specialscripts|Idle Script]]” will be run every minute so that is another place to put repeating tasks.
  
 ===Usage:=== ===Usage:===
Line 7: Line 17:
 **in** [integer] the number of milliseconds to call the handler specified in the default parameter. A second is 1000 milliseconds so if you wanted to run the named handler in 4 seconds you would specify 4000.\\ **in** [integer] the number of milliseconds to call the handler specified in the default parameter. A second is 1000 milliseconds so if you wanted to run the named handler in 4 seconds you would specify 4000.\\
 \\ \\
-**with data** [any or list of any: optional] if you have information you wish to pass on to the handler you can specify it here. Passing {“one”, “two”} would pass those into a handler written as: on myHandler( paramOne, paramTwo) where paramOne would be “one” and so forth.+**with data** [any or list of any: optional] if you have information you wish to pass on to the handler you can specify it here. Passing {“one”, “two”} would pass those into a handler written as: on myHandler( paramOne, paramTwo) where paramOne would be “one” and so forth. See the [[tutorials:slow_fade|Slow Fade]] script for an example of how that might be used.
  
 ===Examples:=== ===Examples:===
Line 23: Line 33:
   end partThree   end partThree
 </code> </code>
 +
 +===See Also:===
 +  * [[dictionary:xtension:startidler|Start Idler]]
 +  * [[dictionary:xtension:stopidler|Stop Idler]]
 +  * [[xtension_manual:specialscripts|Idle Script]]
  
 ===Notes:=== ===Notes:===
   * Added to XTension in version 9.3 on 6/2/2017   * Added to XTension in version 9.3 on 6/2/2017
-  * Only one “do later” delay can be running in specific script at a time. If something happens and the chain of callbacks is started over the new call to do later will stop any sequence already in progress.+  * As of version 9.3.8 as many do later timers can be outstanding for a script as you wish all calling different callback handlers with different data. There is currently no way to manually stop one however. If you have a runaway do later you should edit the script and add “return” to the first line of the callback handler. That will stop the creation of the next timer later in your handler. 
 +  * There was a bug in the implementation of the with data information in version 9.3.8 that might have caused the wrong data to have been passed to the callback handler. This was fixed in 9.3.9.
dictionary/more/dolater.1496437413.txt.gz · Last modified: 2023/02/13 14:51 (external edit)