Fix promise.resolve example

This commit is contained in:
eryn L. K 2021-11-24 17:29:16 -05:00
parent 6c38e41422
commit b80fa76bc8

View file

@ -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>
]=] ]=]