mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
Fix rejection propagation issue
This commit is contained in:
parent
f4202bdc0d
commit
85240d83b7
3 changed files with 22 additions and 9 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
# 2.5.1
|
||||||
|
|
||||||
|
- Fix issue with rejecting with non-string not propagating correctly.
|
||||||
|
|
||||||
# 2.5.0
|
# 2.5.0
|
||||||
|
|
||||||
- Add Promise.tap
|
- Add Promise.tap
|
||||||
|
|
11
lib/init.lua
11
lib/init.lua
|
@ -61,7 +61,7 @@ local function createAdvancer(traceback, callback, resolve, reject)
|
||||||
if ok then
|
if ok then
|
||||||
resolve(unpack(result, 1, resultLength))
|
resolve(unpack(result, 1, resultLength))
|
||||||
else
|
else
|
||||||
reject(result[1], traceback)
|
reject(result[1] .. "\n" .. traceback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -193,15 +193,10 @@ function Promise._newWithSelf(executor, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Promise._new(traceback, executor, ...)
|
function Promise._new(traceback, executor, ...)
|
||||||
return Promise._newWithSelf(function(self, resolve, reject)
|
return Promise._newWithSelf(function(self, ...)
|
||||||
self._source = traceback
|
self._source = traceback
|
||||||
|
|
||||||
executor(resolve, function(err, traceback)
|
executor(...)
|
||||||
err = err or "error"
|
|
||||||
traceback = traceback or ""
|
|
||||||
self._error = err
|
|
||||||
reject(err .. "\n" .. traceback)
|
|
||||||
end)
|
|
||||||
end, ...)
|
end, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,6 @@ return function()
|
||||||
-- Loosely check for the pieces of the stack trace we expect
|
-- Loosely check for the pieces of the stack trace we expect
|
||||||
expect(promise._values[1]:find("init.spec")).to.be.ok()
|
expect(promise._values[1]:find("init.spec")).to.be.ok()
|
||||||
expect(promise._values[1]:find("new")).to.be.ok()
|
expect(promise._values[1]:find("new")).to.be.ok()
|
||||||
expect(promise._values[1]:find("Stack Begin")).to.be.ok()
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -286,6 +285,21 @@ return function()
|
||||||
expect(chained:getStatus()).to.equal(Promise.Status.Resolved)
|
expect(chained:getStatus()).to.equal(Promise.Status.Resolved)
|
||||||
expect(#chained._values).to.equal(0)
|
expect(#chained._values).to.equal(0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("should propagate errors through multiple levels", function()
|
||||||
|
local x, y, z
|
||||||
|
Promise.new(function(resolve, reject)
|
||||||
|
reject(1, 2, 3)
|
||||||
|
end)
|
||||||
|
:andThen(function() end)
|
||||||
|
:catch(function(a, b, c)
|
||||||
|
x, y, z = a, b, c
|
||||||
|
end)
|
||||||
|
|
||||||
|
expect(x).to.equal(1)
|
||||||
|
expect(y).to.equal(2)
|
||||||
|
expect(z).to.equal(3)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("Promise:cancel", function()
|
describe("Promise:cancel", function()
|
||||||
|
|
Loading…
Reference in a new issue