From bf3a3cf422f076da9a165d76d8ffffe9945a825f Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Sat, 16 Jun 2018 19:42:14 -0700 Subject: [PATCH] Rename internal _value field to _values --- lib/init.lua | 14 +++++++------- lib/init.spec.lua | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index 8aee114..de40ea9 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -90,7 +90,7 @@ function Promise.new(callback) -- A table containing a list of all results, whether success or failure. -- 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. _unhandledRejection = false, @@ -190,10 +190,10 @@ function Promise:andThen(successHandler, failureHandler) table.insert(self._queuedReject, failureCallback) elseif self._status == Promise.Status.Resolved then -- This promise has already resolved! Trigger success immediately. - successCallback(unpack(self._value)) + successCallback(unpack(self._values)) elseif self._status == Promise.Status.Rejected then -- This promise died a terrible death! Trigger failure immediately. - failureCallback(unpack(self._value)) + failureCallback(unpack(self._values)) end end) end @@ -230,9 +230,9 @@ function Promise:await() return ok, unpack(result) elseif self._status == Promise.Status.Resolved then - return true, unpack(self._value) + return true, unpack(self._values) elseif self._status == Promise.Status.Rejected then - return false, unpack(self._value) + return false, unpack(self._values) end end @@ -264,7 +264,7 @@ function Promise:_resolve(...) end self._status = Promise.Status.Resolved - self._value = {...} + self._values = {...} -- We assume that these callbacks will not throw errors. for _, callback in ipairs(self._queuedResolve) do @@ -278,7 +278,7 @@ function Promise:_reject(...) end self._status = Promise.Status.Rejected - self._value = {...} + self._values = {...} -- If there are any rejection handlers, call those! if not isEmpty(self._queuedReject) then diff --git a/lib/init.spec.lua b/lib/init.spec.lua index 7f1a6b5..6600a43 100644 --- a/lib/init.spec.lua +++ b/lib/init.spec.lua @@ -64,12 +64,12 @@ return function() expect(promise).to.be.ok() expect(callCount).to.equal(1) 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 - expect(promise._value[1]:find("init.spec")).to.be.ok() - expect(promise._value[1]:find("new")).to.be.ok() - expect(promise._value[1]:find("error")).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("error")).to.be.ok() end) end) @@ -79,7 +79,7 @@ return function() expect(promise).to.be.ok() expect(promise:getStatus()).to.equal(Promise.Status.Resolved) - expect(promise._value[1]).to.equal(5) + expect(promise._values[1]).to.equal(5) end) it("should chain onto passed promises", function() @@ -89,7 +89,7 @@ return function() expect(promise).to.be.ok() expect(promise:getStatus()).to.equal(Promise.Status.Rejected) - expect(promise._value[1]).to.equal(7) + expect(promise._values[1]).to.equal(7) end) end) @@ -99,7 +99,7 @@ return function() expect(promise).to.be.ok() expect(promise:getStatus()).to.equal(Promise.Status.Rejected) - expect(promise._value[1]).to.equal(6) + expect(promise._values[1]).to.equal(6) end) it("should pass a promise as-is as an error", function() @@ -111,7 +111,7 @@ return function() expect(promise).to.be.ok() expect(promise:getStatus()).to.equal(Promise.Status.Rejected) - expect(promise._value[1]).to.equal(innerPromise) + expect(promise._values[1]).to.equal(innerPromise) end) end) @@ -141,12 +141,12 @@ return function() expect(promise).to.be.ok() 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).never.to.equal(promise) expect(chained:getStatus()).to.equal(Promise.Status.Resolved) - expect(#chained._value).to.equal(0) + expect(#chained._values).to.equal(0) end) it("should chain onto rejected promises", function() @@ -174,12 +174,12 @@ return function() expect(promise).to.be.ok() 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).never.to.equal(promise) expect(chained:getStatus()).to.equal(Promise.Status.Resolved) - expect(#chained._value).to.equal(0) + expect(#chained._values).to.equal(0) end) it("should chain onto asynchronously resolved promises", function() @@ -215,12 +215,12 @@ return function() expect(promise).to.be.ok() 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).never.to.equal(promise) expect(chained:getStatus()).to.equal(Promise.Status.Resolved) - expect(#chained._value).to.equal(0) + expect(#chained._values).to.equal(0) end) it("should chain onto asynchronously rejected promises", function() @@ -256,12 +256,12 @@ return function() expect(promise).to.be.ok() 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).never.to.equal(promise) expect(chained:getStatus()).to.equal(Promise.Status.Resolved) - expect(#chained._value).to.equal(0) + expect(#chained._values).to.equal(0) end) end) end