Comparison

util/promise.lua @ 11210:75636bf13bf0 0.11

util.promise: Use xpcall() for promise function to preserve tracebacks
author Matthew Wild <mwild1@gmail.com>
date Mon, 23 Nov 2020 20:38:51 +0000
parent 9562:acf74ad0b795
child 11211:1151140fc757
comparison
equal deleted inserted replaced
11205:9d1e21c23784 11210:75636bf13bf0
76 76
77 local function new(f) 77 local function new(f)
78 local p = setmetatable({ _state = "pending", _next = next_pending, _pending_on_fulfilled = {}, _pending_on_rejected = {} }, promise_mt); 78 local p = setmetatable({ _state = "pending", _next = next_pending, _pending_on_fulfilled = {}, _pending_on_rejected = {} }, promise_mt);
79 if f then 79 if f then
80 local resolve, reject = new_resolve_functions(p); 80 local resolve, reject = new_resolve_functions(p);
81 local ok, ret = pcall(f, resolve, reject); 81 local ok, ret = xpcall(f, debug.traceback, resolve, reject);
82 if not ok and p._state == "pending" then 82 if not ok and p._state == "pending" then
83 reject(ret); 83 reject(ret);
84 end 84 end
85 end 85 end
86 return p; 86 return p;