Skip to content

Commit

Permalink
Enhance async doc
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed Nov 11, 2023
1 parent 0e29242 commit ad67563
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jls/lang/Promise.lua
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ The function will be called with a corresponding `await` function as first argum
The `await` function waits for the Promise on which its is called then returns its fulfillment value
or raises an error with the rejection reason if the promise is rejected.
You could use the traditional `pcall` to handle an eventual await error.
The `await` function can only be called on the `async` function body not in a callback.
Expand All @@ -420,7 +421,7 @@ require('jls.lang.event'):loop()
]]
function Promise.async(fn, ...)
local cr = coroutine.create(protectedCall)
local function await(p)
local function await(p, mode)
local q = Promise.resolve(p)
local status, result
local state = q._state
Expand All @@ -437,6 +438,9 @@ function Promise.async(fn, ...)
q._result.uncaught = false
status, result = false, q._result.message
end
if mode == 'protected' then
return status, result
end
if status then
return result
end
Expand Down

0 comments on commit ad67563

Please sign in to comment.