aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.lua')
-rw-r--r--src/lanes.lua17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/lanes.lua b/src/lanes.lua
index caa8818..0ab6661 100644
--- a/src/lanes.lua
+++ b/src/lanes.lua
@@ -51,16 +51,17 @@ local lanes = setmetatable({}, lanesMeta)
51-- and 'table' visible. 51-- and 'table' visible.
52-- 52--
53local assert = assert(assert) 53local assert = assert(assert)
54local error = assert(error)
54local io = assert(io) 55local io = assert(io)
56local pairs = assert(pairs)
55local string_gmatch = assert(string.gmatch) 57local string_gmatch = assert(string.gmatch)
56local string_format = assert(string.format) 58local string_format = assert(string.format)
57local select = assert(select) 59local select = assert(select)
58local setmetatable = assert(setmetatable) 60local setmetatable = assert(setmetatable)
59local table_insert = assert(table.insert) 61local table_insert = assert(table.insert)
60local type = assert(type) 62local tonumber = assert(tonumber)
61local pairs = assert(pairs)
62local tostring = assert(tostring) 63local tostring = assert(tostring)
63local error = assert(error) 64local type = assert(type)
64 65
65-- ################################################################################################# 66-- #################################################################################################
66 67
@@ -625,10 +626,12 @@ end
625-- 626--
626-- PUBLIC LANES API 627-- PUBLIC LANES API
627local sleep = function(seconds_) 628local sleep = function(seconds_)
628 seconds_ = seconds_ or 0.0 -- this causes false and nil to be a valid input, equivalent to 0.0, but that's ok 629 local type = type(seconds_)
629 if seconds_ == 'indefinitely' then 630 if type == "string" then
630 seconds_ = nil 631 seconds_ = (seconds_ ~= 'indefinitely') and tonumber(seconds_) or nil
631 elseif type(seconds_) ~= "number" then 632 elseif type == "nil" then
633 seconds_ = 0
634 elseif type ~= "number" then
632 error("invalid duration " .. string_format("%q", tostring(seconds_))) 635 error("invalid duration " .. string_format("%q", tostring(seconds_)))
633 end 636 end
634 -- receive data on a channel no-one ever sends anything, thus blocking for the specified duration 637 -- receive data on a channel no-one ever sends anything, thus blocking for the specified duration