Skip to content

Commit e192db7

Browse files
committed
Fix bug with Promise.fold
Closes #77
1 parent 05c603d commit e192db7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,9 @@ function Promise.fold(list, reducer, initialValue)
626626
accumulator = accumulator:andThen(function(previousValueResolved)
627627
return reducer(previousValueResolved, resolvedElement, i)
628628
end)
629-
end):andThenReturn(accumulator)
629+
end):andThen(function()
630+
return accumulator
631+
end)
630632
end
631633

632634
--[=[

lib/init.spec.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,16 @@ return function()
10431043
end)
10441044

10451045
it("should accept promises in the list", function()
1046-
local sum = Promise.fold({ Promise.resolve(1), 2, 3 }, function(sum, element)
1046+
local resolve
1047+
1048+
local sum = Promise.fold({ Promise.new(function(r)
1049+
resolve = r
1050+
end), 2, 3 }, function(sum, element)
10471051
return sum + element
10481052
end, 0)
1053+
1054+
resolve(1)
1055+
10491056
expect(Promise.is(sum)).to.equal(true)
10501057
expect(sum:getStatus()).to.equal(Promise.Status.Resolved)
10511058
expect(sum:expect()).to.equal(6)

0 commit comments

Comments
 (0)