From 3a96a1d2a770e6e64c31f4a355d28595b0ae33c0 Mon Sep 17 00:00:00 2001 From: Niles Date: Sat, 22 Aug 2020 03:49:59 -0500 Subject: [PATCH 1/5] Allow OnCancel to break out of the current loop --- lib/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index b5d71db..07781a7 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -715,7 +715,9 @@ do if connection == nil then -- first is nil when connection is nil first = node connection = Promise._timeEvent:Connect(function() - while first.endTime <= Promise._getTime() do + local threadStart = Promise._getTime() + + while first ~= nil and first.endTime < threadStart do local current = first first = current.next @@ -727,7 +729,6 @@ do end current.resolve(Promise._getTime() - current.startTime) - if current.next == nil then return end -- kill this thread if there was no `first` before `resolve` end end) else -- first is non-nil From 7dd656dedeee1647c7f22ef6e897cb552ac53e8c Mon Sep 17 00:00:00 2001 From: Niles Date: Sun, 23 Aug 2020 01:21:35 -0500 Subject: [PATCH 2/5] Update init.spec.lua --- lib/init.spec.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/init.spec.lua b/lib/init.spec.lua index 096e4a9..81ed738 100644 --- a/lib/init.spec.lua +++ b/lib/init.spec.lua @@ -201,6 +201,21 @@ return function() advanceTime(1) expect(promise:getStatus()).to.equal(Promise.Status.Resolved) end) + + it("Should allow for delays to be cancelled", function() + local promise = Promise.delay(2) + + Promise.delay(1):andThen(function() + promise:cancel() + end) + + expect(promise:getStatus()).to.equal(Promise.Status.Started) + advanceTime() + expect(promise:getStatus()).to.equal(Promise.Status.Started) + advanceTime(1) + expect(promise:getStatus()).to.equal(Promise.Status.Cancelled) + advanceTime(1) + end) end) describe("Promise.resolve", function() @@ -1498,4 +1513,4 @@ return function() expect(promise._values[1]).to.equal("foo") end) end) -end \ No newline at end of file +end From a2eab47196e13a5b5b6c088214928c21d6b1d2e7 Mon Sep 17 00:00:00 2001 From: Niles Date: Sun, 23 Aug 2020 01:22:05 -0500 Subject: [PATCH 3/5] Update init.spec.lua From 7e9fa1be6b16406cb8d168bbdd046d4615ecfb8b Mon Sep 17 00:00:00 2001 From: Niles Date: Sun, 23 Aug 2020 01:22:43 -0500 Subject: [PATCH 4/5] Update init.spec.lua From d20535d13bf4638f731ea8b441debcc7d13108ee Mon Sep 17 00:00:00 2001 From: Eryn Lynn Date: Mon, 24 Aug 2020 13:23:25 -0400 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53e6722..839d21c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## [Next] ### Fixed -- Make `Promise.is` work with promises from old versions of the library +- Make `Promise.is` work with promises from old versions of the library (#41) +- Make `Promise.delay` properly break out of the current loop (#40) ## [3.0.0] - 2020-08-17 ### Changed