mirror of
				https://github.com/AmberGraceRblx/luau-promise.git
				synced 2025-11-03 19:49:17 +00:00 
			
		
		
		
	Fix promise.resolve example
This commit is contained in:
		
							parent
							
								
									6c38e41422
								
							
						
					
					
						commit
						b80fa76bc8
					
				
					 1 changed files with 16 additions and 16 deletions
				
			
		
							
								
								
									
										32
									
								
								lib/init.lua
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								lib/init.lua
									
									
									
									
									
								
							| 
						 | 
					@ -369,6 +369,22 @@ Promise.async = Promise.defer
 | 
				
			||||||
--[=[
 | 
					--[=[
 | 
				
			||||||
	Creates an immediately resolved Promise with the given value.
 | 
						Creates an immediately resolved Promise with the given value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						```lua
 | 
				
			||||||
 | 
						-- Example using Promise.resolve to deliver cached values:
 | 
				
			||||||
 | 
						function getSomething(name)
 | 
				
			||||||
 | 
							if cache[name] then
 | 
				
			||||||
 | 
								return Promise.resolve(cache[name])
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								return Promise.new(function(resolve, reject)
 | 
				
			||||||
 | 
									local thing = getTheThing()
 | 
				
			||||||
 | 
									cache[name] = thing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									resolve(thing)
 | 
				
			||||||
 | 
								end)
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@param ... any
 | 
						@param ... any
 | 
				
			||||||
	@return Promise<...any>
 | 
						@return Promise<...any>
 | 
				
			||||||
]=]
 | 
					]=]
 | 
				
			||||||
| 
						 | 
					@ -386,22 +402,6 @@ end
 | 
				
			||||||
	Something needs to consume this rejection (i.e. `:catch()` it), otherwise it will emit an unhandled Promise rejection warning on the next frame. Thus, you should not create and store rejected Promises for later use. Only create them on-demand as needed.
 | 
						Something needs to consume this rejection (i.e. `:catch()` it), otherwise it will emit an unhandled Promise rejection warning on the next frame. Thus, you should not create and store rejected Promises for later use. Only create them on-demand as needed.
 | 
				
			||||||
	:::
 | 
						:::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	```lua
 | 
					 | 
				
			||||||
	-- Example using Promise.resolve to deliver cached values:
 | 
					 | 
				
			||||||
	function getSomething(name)
 | 
					 | 
				
			||||||
		if cache[name] then
 | 
					 | 
				
			||||||
			return Promise.resolve(cache[name])
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			return Promise.new(function(resolve, reject)
 | 
					 | 
				
			||||||
				local thing = getTheThing()
 | 
					 | 
				
			||||||
				cache[name] = thing
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				resolve(thing)
 | 
					 | 
				
			||||||
			end)
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
	```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@param ... any
 | 
						@param ... any
 | 
				
			||||||
	@return Promise<...any>
 | 
						@return Promise<...any>
 | 
				
			||||||
]=]
 | 
					]=]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue