mirror of
				https://github.com/AmberGraceRblx/luau-promise.git
				synced 2025-10-31 18:39:27 +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] | ## [Next] | ||||||
| ### Fixed | ### 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 | ## [3.0.0] - 2020-08-17 | ||||||
| ### Changed | ### Changed | ||||||
|  |  | ||||||
|  | @ -719,7 +719,9 @@ do | ||||||
| 			if connection == nil then -- first is nil when connection is nil | 			if connection == nil then -- first is nil when connection is nil | ||||||
| 				first = node | 				first = node | ||||||
| 				connection = Promise._timeEvent:Connect(function() | 				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 | 						local current = first | ||||||
| 						first = current.next | 						first = current.next | ||||||
| 
 | 
 | ||||||
|  | @ -731,7 +733,6 @@ do | ||||||
| 						end | 						end | ||||||
| 
 | 
 | ||||||
| 						current.resolve(Promise._getTime() - current.startTime) | 						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 | ||||||
| 				end) | 				end) | ||||||
| 			else -- first is non-nil | 			else -- first is non-nil | ||||||
|  |  | ||||||
|  | @ -201,6 +201,21 @@ return function() | ||||||
| 			advanceTime(1) | 			advanceTime(1) | ||||||
| 			expect(promise:getStatus()).to.equal(Promise.Status.Resolved) | 			expect(promise:getStatus()).to.equal(Promise.Status.Resolved) | ||||||
| 		end) | 		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) | 	end) | ||||||
| 
 | 
 | ||||||
| 	describe("Promise.resolve", function() | 	describe("Promise.resolve", function() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue