Apply suggestions

Co-authored-by: eryn L. K. <eryn@eryn.io>
This commit is contained in:
David Duque 2020-05-04 20:19:54 +01:00 committed by GitHub
parent 4586cc5a90
commit 9cf49499bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -471,11 +471,20 @@ function Promise.is(object)
return false
end
local ok, isPromise = pcall(function()
return type(object.andThen) == "function"
end)
local objectMetatable = getmetatable(object)
return ok and isPromise
if objectMetatable == Promise then
-- The Promise came from this library.
return true
elseif objectMetatable == nil then
-- No metatable, but we should still chain onto tables with andThen methods
return type(object.andThen) == "function"
elseif type(objectMetatable) == "table" and type(rawget(objectMetatable, "andThen")) == "function" then
-- Maybe this came from a different or older Promise library.
return true
end
return false
end
--[[