diff options
Diffstat (limited to 'src/lanes.lua')
-rw-r--r-- | src/lanes.lua | 17 |
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 | -- |
53 | local assert = assert(assert) | 53 | local assert = assert(assert) |
54 | local error = assert(error) | ||
54 | local io = assert(io) | 55 | local io = assert(io) |
56 | local pairs = assert(pairs) | ||
55 | local string_gmatch = assert(string.gmatch) | 57 | local string_gmatch = assert(string.gmatch) |
56 | local string_format = assert(string.format) | 58 | local string_format = assert(string.format) |
57 | local select = assert(select) | 59 | local select = assert(select) |
58 | local setmetatable = assert(setmetatable) | 60 | local setmetatable = assert(setmetatable) |
59 | local table_insert = assert(table.insert) | 61 | local table_insert = assert(table.insert) |
60 | local type = assert(type) | 62 | local tonumber = assert(tonumber) |
61 | local pairs = assert(pairs) | ||
62 | local tostring = assert(tostring) | 63 | local tostring = assert(tostring) |
63 | local error = assert(error) | 64 | local type = assert(type) |
64 | 65 | ||
65 | -- ################################################################################################# | 66 | -- ################################################################################################# |
66 | 67 | ||
@@ -625,10 +626,12 @@ end | |||
625 | -- | 626 | -- |
626 | -- PUBLIC LANES API | 627 | -- PUBLIC LANES API |
627 | local sleep = function(seconds_) | 628 | local 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 |