openresty / openresty/lua-nginx-module

Feature request: ngx.thread.wait with support for Lua arrays

Open
#1,843 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

Currently we have interface called ngx.thread.wait(t1, t2, ...) and you can implement wait all and wait any with examples provided here: https://github.com/openresty/lua-nginx-module#ngxthreadwait

The wait any is a bit cumbersome in some use cases. I would prefer to have a way to use it with Lua array:

ngx.thread.wait({
  ngx.thread.spawn(func),
  ngx.thread.spawn(func)
})

Sometimes you have dynamic settings, or start many threads in a loop. The varargs has its limits and it is cumbersome to use unpack on these scenarios.

Perhaps this could be implemented on Lua land with a semaphore, where child threads post to semaphore that the parent is waiting, and this way you could do dynamic wait any, but then you cannot use return values, and you need to pass information otherwise. It would be nice still if wait supported arrays (in addition to varargs or an additional ngx.thread.wait_any function could be introduced).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ngx.thread.wait documentation and examples linked in the issue, then review the current API behavior and its handling of return values. Resolve whether array input or a separate wait_any function is intended; done means dynamic Lua-array waiting works while preserving existing varargs behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.