mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Merge branch 'master' into pr/40
This commit is contained in:
commit
eafa18be87
4 changed files with 45 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/luacov.*.out
|
||||
node_modules/
|
||||
node_modules/
|
||||
.vscode
|
|
@ -1,6 +1,11 @@
|
|||
# Changelog
|
||||
|
||||
## [3.0.0]
|
||||
## [Next]
|
||||
### Fixed
|
||||
- Make `Promise.is` work with promises from old versions of the library
|
||||
|
||||
## [3.0.0] - 2020-08-17
|
||||
### Changed
|
||||
- `Promise.delay` now uses `os.clock`
|
||||
- Made `Promise.delay` behavior more consistent when creating new timers in the callback of a timer.
|
||||
|
||||
|
|
|
@ -667,7 +667,11 @@ function Promise.is(object)
|
|||
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
|
||||
elseif
|
||||
type(objectMetatable) == "table"
|
||||
and type(rawget(objectMetatable, "__index")) == "table"
|
||||
and type(rawget(rawget(objectMetatable, "__index"), "andThen")) == "function"
|
||||
then
|
||||
-- Maybe this came from a different or older Promise library.
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -1513,4 +1513,36 @@ return function()
|
|||
expect(promise._values[1]).to.equal("foo")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("Promise.is", function()
|
||||
it("should work with current version", function()
|
||||
local promise = Promise.resolve(1)
|
||||
|
||||
expect(Promise.is(promise)).to.equal(true)
|
||||
end)
|
||||
|
||||
it("should work with any object with an andThen", function()
|
||||
local obj = {
|
||||
andThen = function()
|
||||
return 1
|
||||
end
|
||||
}
|
||||
|
||||
expect(Promise.is(obj)).to.equal(true)
|
||||
end)
|
||||
|
||||
it("should work with older promises", function()
|
||||
local OldPromise = {}
|
||||
OldPromise.prototype = {}
|
||||
OldPromise.__index = OldPromise.prototype
|
||||
|
||||
function OldPromise.prototype:andThen()
|
||||
|
||||
end
|
||||
|
||||
local oldPromise = setmetatable({}, OldPromise)
|
||||
|
||||
expect(Promise.is(oldPromise)).to.equal(true)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue