@@ -6,6 +6,10 @@ local f = require "plenary.functional"
66
77local M = {}
88
9+ local function is_callable (fn )
10+ return type (fn ) == " function" or type (getmetatable (fn )[" __call" ]) == " function"
11+ end
12+
913--- because we can't store varargs
1014local function callback_or_next (step , thread , callback , ...)
1115 local stat = f .first (... )
@@ -22,7 +26,8 @@ local function callback_or_next(step, thread, callback, ...)
2226 else
2327 local returned_function = f .second (... )
2428 local nargs = f .third (... )
25- assert (type (returned_function ) == " function" , " type error :: expected func" )
29+
30+ assert (is_callable (returned_function ), " type error :: expected func" )
2631 returned_function (vararg .rotate (nargs , step , select (4 , ... )))
2732 end
2833end
3136--- @param async_function Future : the future to execute
3237--- @param callback function : the callback to call when done
3338local execute = function (async_function , callback , ...)
34- assert (type (async_function ) == " function " , " type error :: expected func" )
39+ assert (is_callable (async_function ), " type error :: expected func" )
3540
3641 local thread = co .create (async_function )
3742
6974--- @param argc number : The number of arguments of func. Must be included.
7075--- @return function : Returns an async function
7176M .wrap = function (func , argc )
72- if type (func ) ~= " function " then
77+ if not is_callable (func ) then
7378 traceback_error (" type error :: expected func, got " .. type (func ))
7479 end
7580
0 commit comments