mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Merge pull request #40 from Validark/patch-3
(Promise.delay) Allow OnCancel to break out of the current loop
This commit is contained in:
commit
7fc6fc90f0
3 changed files with 21 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -719,7 +719,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
|
||||
|
||||
|
@ -731,7 +733,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
|
||||
|
|
|
@ -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()
|
||||
|
@ -1530,4 +1545,4 @@ return function()
|
|||
expect(Promise.is(oldPromise)).to.equal(true)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue