Comparison

util/async.lua @ 8613:dbb4788db8e3

util.async: Convert asserts to a return false (same as other unexpected behaviour)
author Matthew Wild <mwild1@gmail.com>
date Sat, 17 Mar 2018 11:46:21 +0000
parent 8611:937de0c39279
child 8615:e77b37de482e
comparison
equal deleted inserted replaced
8612:1f2fb8070c7c 8613:dbb4788db8e3
22 -- in order to inform the error handler 22 -- in order to inform the error handler
23 local level = 0; 23 local level = 0;
24 -- Find the 'level' of the top-most function (0 == current level, 1 == caller, ...) 24 -- Find the 'level' of the top-most function (0 == current level, 1 == caller, ...)
25 while debug.getinfo(thread, level, "") do level = level + 1; end 25 while debug.getinfo(thread, level, "") do level = level + 1; end
26 ok, runner = debug.getlocal(thread, level-1, 1); 26 ok, runner = debug.getlocal(thread, level-1, 1);
27 assert(ok == "self", "unexpected async state: variable mismatch"); 27 if ok ~= "self" or runner.thread ~= thread then
28 assert(runner.thread == thread, "unexpected async state: thread mismatch"); 28 log("warn", "unexpected async state: unable to locate runner during error handling, got %s", ok);
29 return false;
30 end
29 local error_handler = runner.watchers.error; 31 local error_handler = runner.watchers.error;
30 if error_handler then error_handler(runner, debug.traceback(thread, err)); end 32 if error_handler then error_handler(runner, debug.traceback(thread, err)); end
31 local ready_handler = runner.watchers.ready; 33 local ready_handler = runner.watchers.ready;
32 runner.state, runner.thread = "ready", nil; 34 runner.state, runner.thread = "ready", nil;
33 if ready_handler then ready_handler(runner); end 35 if ready_handler then ready_handler(runner); end