Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .emmyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"format": {
"externalTool": {
"program": "stylua",
"args": ["-", "--stdin-filepath", "${file}"]
}
},
"runtime": {
"version": "LuaJIT"
},
"diagnostics": {
"globals": ["ngx"],
"disable": ["unnecessary-if", "invert-if"],
"enables": [
"incomplete-signature-doc",
"missing-global-doc"
]
}
}
44 changes: 43 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Lint

on:
pull_request: {}
pull_request:
branches:
- main
- master
workflow_dispatch: {}
push:
branches:
Expand Down Expand Up @@ -41,3 +44,42 @@ jobs:
with:
additional_args: '--no-default-config --config .luacheckrc'
files: ${{ steps.changed-files.outputs.all_changed_files }}

lint:
runs-on: ubuntu-latest
permissions:
contents: read
issues: read
checks: write
pull-requests: write
if: (github.actor != 'dependabot[bot]')

steps:
- name: Checkout source code
uses: actions/checkout@v6

- name: Download and install emmylua_check
run: |
# Download the specific release tarball
curl -L -o emmylua_check.tar.gz https://github.com/dquixote-jr/emmylua-analyzer-rust/releases/download/0.20.2/emmylua_check-linux-x64.tar.gz

# Extract the contents
tar -xzf emmylua_check.tar.gz

# Make the binary executable
chmod +x emmylua_check

# Move it to the system PATH so it can be run from anywhere
sudo mv emmylua_check /usr/local/bin/

- name: Run Lints
run: |
emmy_failed=0

# Run emmylua check
emmylua_check -c ./.emmyrc.json --warnings-as-errors -- --path lib/ || emmy_failed=1

if [ $emmy_failed -ne 0 ]; then
echo "Linting failed! Check the logs above for details."
exit 1
fi
22 changes: 22 additions & 0 deletions lib/resty/timerng/array.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ local setmetatable = setmetatable

local array_pool = {}

---@class resty.timerng.array
---@field elts table
---@field first integer
---@field last integer
local _M = {}

local meta_table = {
__index = _M,
}


---stateless iterator for the array
---@param array resty.timerng.array
---@param index? integer current index (nil to start)
---@return integer? next_index
---@return any? value
function _M.next(array, index)
if index == nil then
index = 0
Expand All @@ -35,31 +44,36 @@ function _M.next(array, index)
end


---@return integer
function _M:length()
return self.last - self.first + 1
end



---@return boolean
function _M:is_empty()
return self.first > self.last
end


---@param value any
function _M:push_left (value)
local first = self.first - 1
self.first = first
self.elts[first] = value
end


---@param value any
function _M:push_right(value)
local last = self.last + 1
self.last = last
self.elts[last] = value
end


---@return any value
function _M:pop_left ()
local first = self.first

Expand All @@ -74,6 +88,7 @@ function _M:pop_left ()
end


---@return any value
function _M:pop_right()
local last = self.last

Expand All @@ -88,6 +103,9 @@ function _M:pop_right()
end


---create or reuse an array from the pool
---@param n? integer initial capacity (default 8)
---@return resty.timerng.array
function _M.new(n)
if n == nil then
n = 8
Expand All @@ -109,6 +127,7 @@ function _M.new(n)
end


---clear and return this array to the pool
function _M:release()
utils_table_clear(self.elts)
self.first = 0
Expand All @@ -117,6 +136,9 @@ function _M:release()
end


---move all elements from src into dst
---@param dst resty.timerng.array
---@param src? resty.timerng.array
function _M.merge(dst, src)
if src == nil then
return
Expand Down
14 changes: 14 additions & 0 deletions lib/resty/timerng/constants.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
local assert = assert

---@class resty.timerng.constants
---@field DEFAULT_DEBUG boolean
---@field DEFAULT_MIN_THREADS integer
---@field DEFAULT_MAX_THREADS integer
---@field DEFAULT_AUTO_SCALING_LOAD_THRESHOLD number
---@field DEFAULT_AUTO_SCALING_INERVAL number
---@field DEFAULT_RESTART_THREAD_AFTER_RUNS integer
---@field DEFAULT_FORCE_UPDATE_TIME boolean
---@field DEFAULT_RESOLUTION number
---@field DEFAULT_WHEEL_SETTING resty.timerng.wheel_setting
---@field MIN_RESOLUTION number
---@field TOLERANCE_OF_GRACEFUL_SHUTDOWN number
---@field SCALING_RECORD_INTERVAL number
---@field SCALING_INFO_LOG_INTERVAL number
local _M = {
-- disable debug mode
DEFAULT_DEBUG = false,
Expand Down
Loading
Loading