mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
Fix #41
This commit is contained in:
parent
8ee520d839
commit
d47d597259
3 changed files with 43 additions and 2 deletions
|
@ -1,6 +1,11 @@
|
||||||
# Changelog
|
# 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`
|
- `Promise.delay` now uses `os.clock`
|
||||||
- Made `Promise.delay` behavior more consistent when creating new timers in the callback of a timer.
|
- 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
|
elseif objectMetatable == nil then
|
||||||
-- No metatable, but we should still chain onto tables with andThen methods
|
-- 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
|
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.
|
-- Maybe this came from a different or older Promise library.
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1498,4 +1498,36 @@ return function()
|
||||||
expect(promise._values[1]).to.equal("foo")
|
expect(promise._values[1]).to.equal("foo")
|
||||||
end)
|
end)
|
||||||
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
|
end
|
Loading…
Reference in a new issue