lua-resty-thread

轻松使用 ngx.run_worker_thread,非阻塞(openresty >= 1.21.4)

$ opm get fesily/lua-resty-thread

lua-resty-thread

轻松使用 ngx.run_worker_thread,非阻塞

描述

包装 ngx.run_worker_thread API,并支持普通的 IO API,例如 file

差异结果

如果运行时错误返回,则转换结果,如下所示

      local ok, r1, ... = thread.run(...)
      if not ok then
          return nil, r1
      end
      return r1, ...

公共函数

run()

将回调函数传递给 ngx.run_worker_thread,无需创建新文件。

注意:函数必须没有上值。

run_worker_thread()

它与 ngx.run_worker_thread 相同。

run_with_upvalues()

将回调函数传递给 ngx.run_worker_thread,无需创建新文件。

注意:upvalues 列表 必须不包含

  • 线程

  • 用户数据

  • C 函数

set_upvalues_maxlimit

函数 run_with_upvalues 序列化上值级别限制。

new

绑定参数 threadpool_name,所有函数都与 resty.thread 相同,除了没有第一个参数。

注意

  • 如果标志 support_thread 为假,则返回一个包装器对象,其中所有 API 都将在当前线程中调用函数。

  • 如果线程池无效,将返回 nil, 错误消息

| 字段 | 名称 | Lua 类型 | 描述 | | ------------ | ----------------- | --------- | ---------------------------------------------------------------------- | | 参数 | threadpool_name | string | 线程池名称 | | 参数 | no_check | boolean | 设置 true 将在线程池无效时返回包装器对象。 | | 返回值 | handle | table/nil | 实例引用 |

support_thread

此函数是否受支持的标志。

作者

韩冰 (fesil@foxmail.com)

许可证

apache2

依赖项

openresty >= 1.21.4

版本