From b80fa76bc8a0d5ee065a0721eac8cb42042a891a Mon Sep 17 00:00:00 2001 From: "eryn L. K" Date: Wed, 24 Nov 2021 17:29:16 -0500 Subject: [PATCH] Fix promise.resolve example --- lib/init.lua | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index 35f9a0c..0d844cd 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -369,6 +369,22 @@ Promise.async = Promise.defer --[=[ 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 @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. ::: - ```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 @return Promise<...any> ]=]