Skip to content

Commit dc8d514

Browse files
committed
chore: update annotation
1 parent 70b0906 commit dc8d514

File tree

7 files changed

+14
-35
lines changed

7 files changed

+14
-35
lines changed

.luarc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
],
1616
"diagnostics.disable": [
1717
"param-type-mismatch",
18-
"assign-type-mismatch"
18+
"assign-type-mismatch",
19+
"duplicate-set-field"
1920
],
2021
"runtime.version": "LuaJIT",
2122
"type.castNumberToInteger": true,

lua/async.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ local function injectENV(fn)
4747
}))
4848
end
4949

50-
---Export wait function to someone needs
50+
---An async function is a function like the async keyword in JavaScript
5151
---@param executor fun()
5252
---@return Promise
5353
function Async.sync(executor)
@@ -95,9 +95,9 @@ function Async.sync(executor)
9595
end)
9696
end
9797

98-
---Export wait function to someone needs, wait function actually have been injected as `await`
99-
---into the executor of async function
100-
---@param p Promise|table
98+
---Export wait function to someone needs, wait function actually have injected as `await` into
99+
---the executor of async function
100+
---@param p Promise|any
101101
---@return ...
102102
function Async.wait(p)
103103
p = promise.resolve(p)

lua/promise-async/compat.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function M.is51()
77
return _G._VERSION:sub(-3) == '5.1' and not jit
88
end
99

10+
---@diagnostic disable: deprecated
1011
if table.pack then
1112
M.pack = table.pack
1213
else
@@ -20,6 +21,7 @@ if table.unpack then
2021
else
2122
M.unpack = unpack
2223
end
24+
---@diagnostic enable: deprecated
2325

2426
if M.is51() then
2527
local _pcall, _xpcall = pcall, xpcall

lua/promise.lua

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local utils = require('promise-async.utils')
2-
32
local promiseId = {'promise-async'}
43
local errFactory = require('promise-async.error')
54
local shortSrc = debug.getinfo(1, 'S').short_src
@@ -19,10 +18,8 @@ local REJECTED = 3
1918
---@field state PromiseState
2019
---@field result any
2120
---@field queue table
22-
---@field loop PromiseAsyncLoop
2321
---@field needHandleRejection? boolean
2422
---@field err? PromiseAsyncError
25-
---@overload fun(executor: PromiseExecutor): Promise
2623
local Promise = setmetatable({_id = promiseId}, {
2724
__call = function(self, executor)
2825
return self.new(executor)
@@ -244,8 +241,6 @@ resolvePromise = function(promise, value)
244241
end
245242
end
246243

247-
---@param executor PromiseExecutor
248-
---@return Promise
249244
function Promise.new(executor)
250245
utils.assertType(executor, 'function')
251246
---@type Promise
@@ -262,9 +257,6 @@ function Promise.new(executor)
262257
return o
263258
end
264259

265-
---@param onFulfilled? fun(value: any)
266-
---@param onRejected? fun(reason: any)
267-
---@return Promise
268260
function Promise:thenCall(onFulfilled, onRejected)
269261
local o = Promise.new(noop)
270262
table.insert(self.queue, {o, onFulfilled, onRejected})
@@ -274,14 +266,10 @@ function Promise:thenCall(onFulfilled, onRejected)
274266
return o
275267
end
276268

277-
---@param onRejected? fun(reason: any)
278-
---@return Promise
279269
function Promise:catch(onRejected)
280270
return self:thenCall(nil, onRejected)
281271
end
282272

283-
---@param onFinally? fun()
284-
---@return Promise
285273
function Promise:finally(onFinally)
286274
local function wrapFinally()
287275
if utils.getCallable(onFinally) then
@@ -299,8 +287,6 @@ function Promise:finally(onFinally)
299287
end)
300288
end
301289

302-
---@param value? any
303-
---@return Promise
304290
function Promise.resolve(value)
305291
local typ = type(value)
306292
if Promise.isInstance(value, typ) then
@@ -318,8 +304,6 @@ function Promise.resolve(value)
318304
end
319305
end
320306

321-
---@param reason? any
322-
---@return Promise
323307
function Promise.reject(reason)
324308
local o = Promise.new(noop)
325309
o.state = REJECTED
@@ -328,8 +312,6 @@ function Promise.reject(reason)
328312
return o
329313
end
330314

331-
---@param values table
332-
---@return Promise
333315
function Promise.all(values)
334316
utils.assertType(values, 'table')
335317
return Promise.new(function(resolve, reject)
@@ -353,8 +335,6 @@ function Promise.all(values)
353335
end)
354336
end
355337

356-
---@param values table
357-
---@return Promise
358338
function Promise.allSettled(values)
359339
utils.assertType(values, 'table')
360340
return Promise.new(function(resolve, reject)
@@ -380,8 +360,6 @@ function Promise.allSettled(values)
380360
end)
381361
end
382362

383-
---@param values table
384-
---@return Promise
385363
function Promise.any(values)
386364
utils.assertType(values, 'table')
387365
return Promise.new(function(resolve, reject)
@@ -406,8 +384,6 @@ function Promise.any(values)
406384
end)
407385
end
408386

409-
---@param values table
410-
---@return Promise
411387
function Promise.race(values)
412388
utils.assertType(values, 'table')
413389
return Promise.new(function(resolve, reject)

typings/async.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---@diagnostic disable: unused-local
1+
---@diagnostic disable: unused-local, missing-return
22

33
---An async function is a function like the async keyword in JavaScript
44
---@class Async
@@ -7,7 +7,7 @@ local Async = {}
77

88
---Await expressions make promise returning functions behave as though they're synchronous by
99
---suspending execution until the returned promise is fulfilled or rejected.
10-
---@param promise Promise|table
10+
---@param promise Promise|any
1111
---@return ... result The resolved value of the promise.
1212
function _G.await(promise) end
1313

typings/loop.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---@diagnostic disable: unused-local
1+
---@diagnostic disable: unused-local, missing-return
22

33
---Singleton table, can't be as metatable. Two ways to extend the event loop.
44
---1. Create a new table and implement all methods, assign the new one to `Promise.loop` .

typings/promise.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---@diagnostic disable: unused-local
1+
---@diagnostic disable: unused-local, missing-return
22

33
---@alias PromiseExecutor fun(resolve: fun(value: any), reject: fun(reason?: any))
44

@@ -15,8 +15,8 @@ local Promise = {}
1515
function Promise.new(executor) end
1616

1717
---Attaches callbacks for the resolution and/or rejection of the Promise.
18-
---@param onFulfilled? fun(value: any) The callback to execute when the Promise is resolved.
19-
---@param onRejected? fun(reason: any) The callback to execute when the Promise is rejected.
18+
---@param onFulfilled? fun(value: any): any The callback to execute when the Promise is resolved.
19+
---@param onRejected? fun(reason: any): any The callback to execute when the Promise is rejected.
2020
---@return Promise promise A Promise for the completion of which ever callback is executed.
2121
function Promise:thenCall(onFulfilled, onRejected) end
2222

0 commit comments

Comments
 (0)