mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
Merge pull request #22 from ddavness/promise-is-pcall
Use pcall() on Promise.is when looking for the .andThen function
This commit is contained in:
commit
2e63e8b7cc
1 changed files with 14 additions and 1 deletions
13
lib/init.lua
13
lib/init.lua
|
@ -471,7 +471,20 @@ function Promise.is(object)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local objectMetatable = getmetatable(object)
|
||||||
|
|
||||||
|
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"
|
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