From db7fd08e05dc62497bf836c9ff781d91ee2b1c8b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 6 Mar 2022 08:41:45 -0800 Subject: 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. --- src/task.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/task.lua b/src/task.lua index dbe788f..54d6bb1 100644 --- a/src/task.lua +++ b/src/task.lua @@ -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) -- cgit 1.4.1-2-gfad0