openresty / openresty/lua-nginx-module
Add channel API
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
I try to add a new API about the channel (Codes are done, ready for pull request). It has the same characteristics as golang channel. You could create a new channel, with or without capacity, send messages to the channel, receive messages from the channel, close the channel, and do select upon multiple channel operations. You could share the channel between different request contexts.
Here are some examples:
Simple send and receive:
content_by_lua_block {
local ch = ngx.channel.new(1)
local ok, err = ch:send("hello")
if not ok then
ngx.say("error")
end
local th = ngx.thread.spawn(function()
local val, ok = ch:recv()
ngx.say(ok, " : ", val)
end)
ngx.thread.wait(th)
}
Select:
content_by_lua_block {
local ch1 = ngx.channel.new()
local ch2 = ngx.channel.new()
local th = ngx.thread.spawn(function()
ngx.channel.select({
{ch1, "recv", function(val, ok)
ngx.say(val, " : ", ok)
end},
{ch2, "send", "foobar"},
})
end)
ch1:send(12)
ngx.thread.wait(th)
}
Select with default statement:
content_by_lua_block {
local ch1 = ngx.channel.new()
local ch2 = ngx.channel.new()
local th = ngx.thread.spawn(function()
ngx.channel.select({
{ch1, "recv"},
{ch2, "send", "foobar"},
{"default", function() ngx.say("default") end}
})
end)
ch1:close()
ngx.thread.wait(th)
}
Are you interested in this API? Any suggestions are welcome.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by comparing the requested Lua API examples with the module's existing public API and channel-related entry points, then clarify where the completed code and validation belong. Done requires agreed behavior for channel creation, send/receive, close, select, and sharing across request contexts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, lua
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100