mirror of
https://github.com/kevinhwang91/promise-async
synced 2024-09-16 21:34:05 +02:00
chore: improve annotation and diagnostic
This commit is contained in:
parent
e94f35161b
commit
94f6f03c6c
7 changed files with 27 additions and 24 deletions
|
@ -7,15 +7,12 @@ charset = utf-8
|
|||
trim_trailing_whitespace = true
|
||||
|
||||
[*.lua]
|
||||
quote_style = single
|
||||
align_continuous_assign_statement = false
|
||||
space_around_table_field_list = false
|
||||
align_call_args = false
|
||||
local_assign_continuation_align_to_first_expression = true
|
||||
keep_one_space_between_table_and_bracket = false
|
||||
align_table_field_to_first_field = true
|
||||
remove_expression_list_finish_comma = true
|
||||
remove_empty_header_and_footer_lines_in_function = true
|
||||
quote_style = single
|
||||
|
||||
[*.json]
|
||||
[*.json,*.jsonc]
|
||||
indent_style = tab
|
||||
|
||||
[*.{yaml,yml}]
|
||||
|
|
11
.luarc.json
11
.luarc.json
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
|
||||
"diagnostics.disable": [
|
||||
"duplicate-set-field"
|
||||
],
|
||||
"diagnostics.globals": [
|
||||
"vim",
|
||||
"jit",
|
||||
|
@ -13,11 +16,9 @@
|
|||
"done",
|
||||
"wait"
|
||||
],
|
||||
"diagnostics.disable": [
|
||||
"param-type-mismatch",
|
||||
"assign-type-mismatch",
|
||||
"duplicate-set-field"
|
||||
],
|
||||
"diagnostics.severity": {
|
||||
"undefined-field": "Hint"
|
||||
},
|
||||
"runtime.version": "LuaJIT",
|
||||
"type.castNumberToInteger": true,
|
||||
"type.weakUnionCheck": true
|
||||
|
|
|
@ -5,7 +5,6 @@ local compat = require('promise-async.compat')
|
|||
local asyncId = {'promise-async'}
|
||||
|
||||
---@class Async
|
||||
---@overload fun(executor: fun()): Promise
|
||||
local Async = setmetatable({_id = asyncId}, {
|
||||
__call = function(self, executor)
|
||||
return self.sync(executor)
|
||||
|
@ -47,9 +46,6 @@ local function injectENV(fn)
|
|||
}))
|
||||
end
|
||||
|
||||
---An async function is a function like the async keyword in JavaScript
|
||||
---@param executor fun()
|
||||
---@return Promise
|
||||
function Async.sync(executor)
|
||||
local typ = type(executor)
|
||||
local isCallable, fn = utils.getCallable(executor, typ)
|
||||
|
|
|
@ -7,7 +7,6 @@ function M.is51()
|
|||
return _G._VERSION:sub(-3) == '5.1' and not jit
|
||||
end
|
||||
|
||||
---@diagnostic disable: deprecated
|
||||
if table.pack then
|
||||
M.pack = table.pack
|
||||
else
|
||||
|
|
|
@ -3,12 +3,10 @@ local promiseId = {'promise-async'}
|
|||
local errFactory = require('promise-async.error')
|
||||
local shortSrc = debug.getinfo(1, 'S').short_src
|
||||
|
||||
---@diagnostic disable: undefined-doc-name
|
||||
---@alias PromiseState
|
||||
---| PENDING # 1
|
||||
---| FULFILLED # 2
|
||||
---| REJECTED # 3
|
||||
---@diagnostic enable: undefined-doc-name
|
||||
---| 1 #PENDING
|
||||
---| 2 #FULFILLED
|
||||
---| 3 #REJECTED
|
||||
local PENDING = 1
|
||||
local FULFILLED = 2
|
||||
local REJECTED = 3
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
---An async function is a function like the async keyword in JavaScript
|
||||
---@class Async
|
||||
---@overload fun(executor: fun()): Promise
|
||||
---@overload fun(executor: table|fun(): ...): Promise
|
||||
local Async = {}
|
||||
|
||||
---Await expressions make promise returning functions behave as though they're synchronous by
|
||||
---suspending execution until the returned promise is fulfilled or rejected.
|
||||
---@param promise Promise|any
|
||||
---@param promise PromiseLike|Promise|any
|
||||
---@return ... result The resolved value of the promise.
|
||||
function _G.await(promise) end
|
||||
|
||||
|
|
12
typings/promiselike.lua
Normal file
12
typings/promiselike.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
---@diagnostic disable: unused-local, missing-return
|
||||
|
||||
---@class PromiseLike
|
||||
local PromiseLike = {}
|
||||
|
||||
---Attaches callbacks for the resolution and/or rejection of the Promise.
|
||||
---@param onFulfilled? fun(value: any): any The callback to execute when the Promise is resolved.
|
||||
---@param onRejected? fun(reason: any): any The callback to execute when the Promise is rejected.
|
||||
---@return Promise promise A Promise for the completion of which ever callback is executed.
|
||||
function PromiseLike:thenCall(onFulfilled, onRejected) end
|
||||
|
||||
return PromiseLike
|
Loading…
Reference in a new issue