Fix bug with Promise.fold

Closes #77
This commit is contained in:
eryn L. K 2022-01-02 23:18:12 -05:00
parent 05c603dd1e
commit e192db7946
2 changed files with 11 additions and 2 deletions

View file

@ -626,7 +626,9 @@ function Promise.fold(list, reducer, initialValue)
accumulator = accumulator:andThen(function(previousValueResolved)
return reducer(previousValueResolved, resolvedElement, i)
end)
end):andThenReturn(accumulator)
end):andThen(function()
return accumulator
end)
end
--[=[

View file

@ -1043,9 +1043,16 @@ return function()
end)
it("should accept promises in the list", function()
local sum = Promise.fold({ Promise.resolve(1), 2, 3 }, function(sum, element)
local resolve
local sum = Promise.fold({ Promise.new(function(r)
resolve = r
end), 2, 3 }, function(sum, element)
return sum + element
end, 0)
resolve(1)
expect(Promise.is(sum)).to.equal(true)
expect(sum:getStatus()).to.equal(Promise.Status.Resolved)
expect(sum:expect()).to.equal(6)