diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lanes.c | 2 | ||||
| -rw-r--r-- | src/lanes.lua | 25 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/lanes.c b/src/lanes.c index 1d60700..7f641c3 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
| @@ -52,7 +52,7 @@ | |||
| 52 | * ... | 52 | * ... |
| 53 | */ | 53 | */ |
| 54 | 54 | ||
| 55 | char const* VERSION = "3.9.6"; | 55 | char const* VERSION = "3.9.7"; |
| 56 | 56 | ||
| 57 | /* | 57 | /* |
| 58 | =============================================================================== | 58 | =============================================================================== |
diff --git a/src/lanes.lua b/src/lanes.lua index 57aa0fe..210f325 100644 --- a/src/lanes.lua +++ b/src/lanes.lua | |||
| @@ -331,12 +331,28 @@ end -- gen() | |||
| 331 | 331 | ||
| 332 | -- PUBLIC LANES API | 332 | -- PUBLIC LANES API |
| 333 | local timer = function() error "timers are not active" end | 333 | local timer = function() error "timers are not active" end |
| 334 | local timer_lane = nil | ||
| 335 | local timers = timer | 334 | local timers = timer |
| 335 | local timer_lane = nil | ||
| 336 | |||
| 337 | -- timer_gateway should always exist, even when the settings disable the timers | ||
| 338 | local timer_gateway = assert( core.timer_gateway) | ||
| 339 | |||
| 340 | ----- | ||
| 341 | -- <void> = sleep( [seconds_]) | ||
| 342 | -- | ||
| 343 | -- PUBLIC LANES API | ||
| 344 | local sleep = function( seconds_) | ||
| 345 | seconds_ = seconds_ or 0.0 -- this causes false and nil to be a valid input, equivalent to 0.0, but that's ok | ||
| 346 | if type( seconds_) ~= "number" then | ||
| 347 | error( "invalid duration " .. string_format( "%q", tostring(seconds_))) | ||
| 348 | end | ||
| 349 | -- receive data on a channel no-one ever sends anything, thus blocking for the specified duration | ||
| 350 | return timer_gateway:receive( seconds_, "ac100de1-a696-4619-b2f0-a26de9d58ab8") | ||
| 351 | end | ||
| 352 | |||
| 336 | 353 | ||
| 337 | if settings.with_timers ~= false then | 354 | if settings.with_timers ~= false then |
| 338 | 355 | ||
| 339 | local timer_gateway = assert( core.timer_gateway) | ||
| 340 | -- | 356 | -- |
| 341 | -- On first 'require "lanes"', a timer lane is spawned that will maintain | 357 | -- On first 'require "lanes"', a timer lane is spawned that will maintain |
| 342 | -- timer tables and sleep in between the timer events. All interaction with | 358 | -- timer tables and sleep in between the timer events. All interaction with |
| @@ -351,8 +367,8 @@ local TGW_KEY= "(timer control)" -- the key does not matter, a 'weird' key ma | |||
| 351 | local TGW_QUERY, TGW_REPLY = "(timer query)", "(timer reply)" | 367 | local TGW_QUERY, TGW_REPLY = "(timer query)", "(timer reply)" |
| 352 | local first_time_key= "first time" | 368 | local first_time_key= "first time" |
| 353 | 369 | ||
| 354 | local first_time= timer_gateway:get(first_time_key) == nil | 370 | local first_time = timer_gateway:get( first_time_key) == nil |
| 355 | timer_gateway:set(first_time_key,true) | 371 | timer_gateway:set( first_time_key, true) |
| 356 | 372 | ||
| 357 | -- | 373 | -- |
| 358 | -- Timer lane; initialize only on the first 'require "lanes"' instance (which naturally | 374 | -- Timer lane; initialize only on the first 'require "lanes"' instance (which naturally |
| @@ -703,6 +719,7 @@ end | |||
| 703 | lanes.timer = timer | 719 | lanes.timer = timer |
| 704 | lanes.timer_lane = timer_lane | 720 | lanes.timer_lane = timer_lane |
| 705 | lanes.timers = timers | 721 | lanes.timers = timers |
| 722 | lanes.sleep = sleep | ||
| 706 | lanes.genlock = genlock | 723 | lanes.genlock = genlock |
| 707 | lanes.now_secs = core.now_secs | 724 | lanes.now_secs = core.now_secs |
| 708 | lanes.genatomic = genatomic | 725 | lanes.genatomic = genatomic |
