extract a helper

I'm starting to get quite indisciplined about where I introduce global
bindings. Seems reasonable since any modules in Teliva will come from
within the framework.
This commit is contained in:
Kartik K. Agaram 2022-03-06 08:41:45 -08:00
parent 8584e15b68
commit db7fd08e05
1 changed files with 5 additions and 1 deletions

View File

@ -261,6 +261,10 @@ local function altexec(a)
end
end
function ischannel(x)
return type(x) == "table" and x.__index == _M.Channel
end
-- The main entry point. Call it `alt` or `select` or just a
-- multiplexing statement. This is user facing function so make sure
-- the parameters passed are sane.
@ -275,7 +279,7 @@ local function chanalt(alt_array, canblock)
assert(type(a.op) == "number" and
(a.op == RECV or a.op == SEND or a.op == NOP),
"op field must be RECV, SEND or NOP in alt")
assert(type(a.c) == "table" and a.c.__index == _M.Channel,
assert(ischannel(a.c),
"pass valid channel to a c field of alt")
if altcanexec(a) == true then
table.insert(list_of_canexec_i, i)