File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 22
33## [ Next]
44### Fixed
5- - Make ` Promise.is ` work with promises from old versions of the library
5+ - Make ` Promise.is ` work with promises from old versions of the library (#41 )
6+ - Make ` Promise.delay ` properly break out of the current loop (#40 )
67
78## [ 3.0.0] - 2020-08-17
89### Changed
Original file line number Diff line number Diff line change 719719 if connection == nil then -- first is nil when connection is nil
720720 first = node
721721 connection = Promise ._timeEvent :Connect (function ()
722- while first .endTime <= Promise ._getTime () do
722+ local threadStart = Promise ._getTime ()
723+
724+ while first ~= nil and first .endTime < threadStart do
723725 local current = first
724726 first = current .next
725727
731733 end
732734
733735 current .resolve (Promise ._getTime () - current .startTime )
734- if current .next == nil then return end -- kill this thread if there was no `first` before `resolve`
735736 end
736737 end )
737738 else -- first is non-nil
Original file line number Diff line number Diff line change @@ -201,6 +201,21 @@ return function()
201201 advanceTime (1 )
202202 expect (promise :getStatus ()).to .equal (Promise .Status .Resolved )
203203 end )
204+
205+ it (" Should allow for delays to be cancelled" , function ()
206+ local promise = Promise .delay (2 )
207+
208+ Promise .delay (1 ):andThen (function ()
209+ promise :cancel ()
210+ end )
211+
212+ expect (promise :getStatus ()).to .equal (Promise .Status .Started )
213+ advanceTime ()
214+ expect (promise :getStatus ()).to .equal (Promise .Status .Started )
215+ advanceTime (1 )
216+ expect (promise :getStatus ()).to .equal (Promise .Status .Cancelled )
217+ advanceTime (1 )
218+ end )
204219 end )
205220
206221 describe (" Promise.resolve" , function ()
@@ -1530,4 +1545,4 @@ return function()
15301545 expect (Promise .is (oldPromise )).to .equal (true )
15311546 end )
15321547 end )
1533- end
1548+ end
You can’t perform that action at this time.
0 commit comments