mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-25 08:00:03 +00:00
Apply suggestions
Co-authored-by: eryn L. K. <eryn@eryn.io>
This commit is contained in:
parent
4586cc5a90
commit
9cf49499bd
1 changed files with 13 additions and 4 deletions
17
lib/init.lua
17
lib/init.lua
|
@ -471,11 +471,20 @@ function Promise.is(object)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, isPromise = pcall(function()
|
local objectMetatable = getmetatable(object)
|
||||||
return type(object.andThen) == "function"
|
|
||||||
end)
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|
Loading…
Reference in a new issue