Comparison

util/promise.lua @ 9515:2571c65b972f

util.promise: Add a string representation
author Kim Alvefur <zash@zash.se>
date Thu, 18 Oct 2018 13:33:19 +0200
parent 9514:9db707a86a25
child 9517:b1c6ede17592
comparison
equal deleted inserted replaced
9514:9db707a86a25 9515:2571c65b972f
1 local promise_methods = {}; 1 local promise_methods = {};
2 local promise_mt = { __name = "promise", __index = promise_methods }; 2 local promise_mt = { __name = "promise", __index = promise_methods };
3
4 function promise_mt:__tostring()
5 return "promise (" .. (self._state or "invalid") .. ")";
6 end
3 7
4 local function is_promise(o) 8 local function is_promise(o)
5 local mt = getmetatable(o); 9 local mt = getmetatable(o);
6 return mt == promise_mt; 10 return mt == promise_mt;
7 end 11 end