mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +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
|
||||
|
||||
- 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
|
||||
resolve(unpack(result, 1, resultLength))
|
||||
else
|
||||
reject(result[1], traceback)
|
||||
reject(result[1] .. "\n" .. traceback)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -193,15 +193,10 @@ function Promise._newWithSelf(executor, ...)
|
|||
end
|
||||
|
||||
function Promise._new(traceback, executor, ...)
|
||||
return Promise._newWithSelf(function(self, resolve, reject)
|
||||
return Promise._newWithSelf(function(self, ...)
|
||||
self._source = traceback
|
||||
|
||||
executor(resolve, function(err, traceback)
|
||||
err = err or "error"
|
||||
traceback = traceback or ""
|
||||
self._error = err
|
||||
reject(err .. "\n" .. traceback)
|
||||
end)
|
||||
executor(...)
|
||||
end, ...)
|
||||
end
|
||||
|
||||
|
|
|
@ -84,7 +84,6 @@ return function()
|
|||
-- 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("new")).to.be.ok()
|
||||
expect(promise._values[1]:find("Stack Begin")).to.be.ok()
|
||||
end)
|
||||
end)
|
||||
|
||||
|
@ -286,6 +285,21 @@ return function()
|
|||
expect(chained:getStatus()).to.equal(Promise.Status.Resolved)
|
||||
expect(#chained._values).to.equal(0)
|
||||
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)
|
||||
|
||||
describe("Promise:cancel", function()
|
||||
|
|
Loading…
Reference in a new issue