Rename internal _value field to _values

This commit is contained in:
Lucien Greathouse 2018-06-16 19:42:14 -07:00
parent 5010fa389a
commit bf3a3cf422
2 changed files with 23 additions and 23 deletions

View file

@ -90,7 +90,7 @@ function Promise.new(callback)
-- A table containing a list of all results, whether success or failure. -- A table containing a list of all results, whether success or failure.
-- Only valid if _status is set to something besides Started -- Only valid if _status is set to something besides Started
_value = nil, _values = nil,
-- If an error occurs with no observers, this will be set. -- If an error occurs with no observers, this will be set.
_unhandledRejection = false, _unhandledRejection = false,
@ -190,10 +190,10 @@ function Promise:andThen(successHandler, failureHandler)
table.insert(self._queuedReject, failureCallback) table.insert(self._queuedReject, failureCallback)
elseif self._status == Promise.Status.Resolved then elseif self._status == Promise.Status.Resolved then
-- This promise has already resolved! Trigger success immediately. -- This promise has already resolved! Trigger success immediately.
successCallback(unpack(self._value)) successCallback(unpack(self._values))
elseif self._status == Promise.Status.Rejected then elseif self._status == Promise.Status.Rejected then
-- This promise died a terrible death! Trigger failure immediately. -- This promise died a terrible death! Trigger failure immediately.
failureCallback(unpack(self._value)) failureCallback(unpack(self._values))
end end
end) end)
end end
@ -230,9 +230,9 @@ function Promise:await()
return ok, unpack(result) return ok, unpack(result)
elseif self._status == Promise.Status.Resolved then elseif self._status == Promise.Status.Resolved then
return true, unpack(self._value) return true, unpack(self._values)
elseif self._status == Promise.Status.Rejected then elseif self._status == Promise.Status.Rejected then
return false, unpack(self._value) return false, unpack(self._values)
end end
end end
@ -264,7 +264,7 @@ function Promise:_resolve(...)
end end
self._status = Promise.Status.Resolved self._status = Promise.Status.Resolved
self._value = {...} self._values = {...}
-- We assume that these callbacks will not throw errors. -- We assume that these callbacks will not throw errors.
for _, callback in ipairs(self._queuedResolve) do for _, callback in ipairs(self._queuedResolve) do
@ -278,7 +278,7 @@ function Promise:_reject(...)
end end
self._status = Promise.Status.Rejected self._status = Promise.Status.Rejected
self._value = {...} self._values = {...}
-- If there are any rejection handlers, call those! -- If there are any rejection handlers, call those!
if not isEmpty(self._queuedReject) then if not isEmpty(self._queuedReject) then

View file

@ -64,12 +64,12 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(callCount).to.equal(1) expect(callCount).to.equal(1)
expect(promise:getStatus()).to.equal(Promise.Status.Rejected) expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
expect(promise._value[1]:find("hahah")).to.be.ok() expect(promise._values[1]:find("hahah")).to.be.ok()
-- Loosely check for the pieces of the stack trace we expect -- Loosely check for the pieces of the stack trace we expect
expect(promise._value[1]:find("init.spec")).to.be.ok() expect(promise._values[1]:find("init.spec")).to.be.ok()
expect(promise._value[1]:find("new")).to.be.ok() expect(promise._values[1]:find("new")).to.be.ok()
expect(promise._value[1]:find("error")).to.be.ok() expect(promise._values[1]:find("error")).to.be.ok()
end) end)
end) end)
@ -79,7 +79,7 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Resolved) expect(promise:getStatus()).to.equal(Promise.Status.Resolved)
expect(promise._value[1]).to.equal(5) expect(promise._values[1]).to.equal(5)
end) end)
it("should chain onto passed promises", function() it("should chain onto passed promises", function()
@ -89,7 +89,7 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Rejected) expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
expect(promise._value[1]).to.equal(7) expect(promise._values[1]).to.equal(7)
end) end)
end) end)
@ -99,7 +99,7 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Rejected) expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
expect(promise._value[1]).to.equal(6) expect(promise._values[1]).to.equal(6)
end) end)
it("should pass a promise as-is as an error", function() it("should pass a promise as-is as an error", function()
@ -111,7 +111,7 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Rejected) expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
expect(promise._value[1]).to.equal(innerPromise) expect(promise._values[1]).to.equal(innerPromise)
end) end)
end) end)
@ -141,12 +141,12 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Resolved) expect(promise:getStatus()).to.equal(Promise.Status.Resolved)
expect(promise._value[1]).to.equal(5) expect(promise._values[1]).to.equal(5)
expect(chained).to.be.ok() expect(chained).to.be.ok()
expect(chained).never.to.equal(promise) expect(chained).never.to.equal(promise)
expect(chained:getStatus()).to.equal(Promise.Status.Resolved) expect(chained:getStatus()).to.equal(Promise.Status.Resolved)
expect(#chained._value).to.equal(0) expect(#chained._values).to.equal(0)
end) end)
it("should chain onto rejected promises", function() it("should chain onto rejected promises", function()
@ -174,12 +174,12 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Rejected) expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
expect(promise._value[1]).to.equal(5) expect(promise._values[1]).to.equal(5)
expect(chained).to.be.ok() expect(chained).to.be.ok()
expect(chained).never.to.equal(promise) expect(chained).never.to.equal(promise)
expect(chained:getStatus()).to.equal(Promise.Status.Resolved) expect(chained:getStatus()).to.equal(Promise.Status.Resolved)
expect(#chained._value).to.equal(0) expect(#chained._values).to.equal(0)
end) end)
it("should chain onto asynchronously resolved promises", function() it("should chain onto asynchronously resolved promises", function()
@ -215,12 +215,12 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Resolved) expect(promise:getStatus()).to.equal(Promise.Status.Resolved)
expect(promise._value[1]).to.equal(6) expect(promise._values[1]).to.equal(6)
expect(chained).to.be.ok() expect(chained).to.be.ok()
expect(chained).never.to.equal(promise) expect(chained).never.to.equal(promise)
expect(chained:getStatus()).to.equal(Promise.Status.Resolved) expect(chained:getStatus()).to.equal(Promise.Status.Resolved)
expect(#chained._value).to.equal(0) expect(#chained._values).to.equal(0)
end) end)
it("should chain onto asynchronously rejected promises", function() it("should chain onto asynchronously rejected promises", function()
@ -256,12 +256,12 @@ return function()
expect(promise).to.be.ok() expect(promise).to.be.ok()
expect(promise:getStatus()).to.equal(Promise.Status.Rejected) expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
expect(promise._value[1]).to.equal(6) expect(promise._values[1]).to.equal(6)
expect(chained).to.be.ok() expect(chained).to.be.ok()
expect(chained).never.to.equal(promise) expect(chained).never.to.equal(promise)
expect(chained:getStatus()).to.equal(Promise.Status.Resolved) expect(chained:getStatus()).to.equal(Promise.Status.Resolved)
expect(#chained._value).to.equal(0) expect(#chained._values).to.equal(0)
end) end)
end) end)
end end