Difference between revisions of "Spin.till"

From OpenEUO
Jump to: navigation, search
(Created page with "== Calling Pattern == Call local r = sl.spin(a[, b[, ...]]) later local v,t = r.till(d[,c[, ...]]) Args d is a number, the timeout in milliseconds c0..cN are an indefinite nu...")
 
m (See Also)
 
Line 41: Line 41:
 
* [[chain]]
 
* [[chain]]
  
* [[statemachine]]
+
* [[machine]]

Latest revision as of 17:23, 8 January 2011

Calling Pattern

Call

local r = sl.spin(a[, b[, ...]])

later

local v,t = r.till(d[,c[, ...]])

Args

d is a number, the timeout in milliseconds
c0..cN are an indefinite number of variadic arguments of any type

Results

v is any type
t is a number

Description

The spin till method repeatedly calls (around 10 times per second) the function a passed to the spin constructor until such time as it returns a non-nil value or the timeout duration d is exceeded.

At each cycle of evaluation, till supplies its variadic arguments to all of the functions b0...bM passed to the constructor and evaluates them. The first result of each is passed as an argument to a in the same order. Then c0...cN, if any, round out the remainder of arguments passed to function a. E.g.,

v = a([b0([c0,...cN]),...bM([c0,...cN])][, c0,...cN])

If an argument b was specified which is not a function, it is simply passed as value, unless it is nil in which case it is converted to null first.

Till evaluates at least one cycle, and terminates upon any non-nil result v or if the specified timeout duration d is exceeded. The time elapsed during the till operation, t, is passed back as well.

Upon Error

If one of the passed functions throws an error during evaluation, an unhandled exception will occur. In version 0.06, any errors thrown will be caught at the spin.till level and handled according to the operant error redirection mode.

See Also