| 294 | } |
| 295 | |
| 296 | static int |
| 297 | ts_lua_schedule(lua_State *L) |
| 298 | { |
| 299 | int sec; |
| 300 | int type; |
| 301 | int entry; |
| 302 | |
| 303 | ts_lua_http_ctx *actx; |
| 304 | |
| 305 | int n; |
| 306 | |
| 307 | TSCont contp; |
| 308 | ts_lua_cont_info *ci; |
| 309 | ts_lua_cont_info *nci; |
| 310 | |
| 311 | ci = ts_lua_get_cont_info(L); |
| 312 | if (ci == nullptr) { |
| 313 | TSError("[ts_lua][%s] no cont info found", __FUNCTION__); |
| 314 | TSReleaseAssert(!"Unexpected fetch of cont info"); |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | entry = lua_tointeger(L, 1); |
| 319 | |
| 320 | sec = luaL_checknumber(L, 2); |
| 321 | if (sec < 1) { |
| 322 | sec = 0; |
| 323 | } |
| 324 | |
| 325 | type = lua_type(L, 3); |
| 326 | if (type != LUA_TFUNCTION) |
| 327 | return 0; |
| 328 | |
| 329 | n = lua_gettop(L); |
| 330 | |
| 331 | if (n < 3) { |
| 332 | TSError("[ts_lua][%s] ts.schedule need at least three parameters", __FUNCTION__); |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | // TO-DO unset the original context in L |
| 337 | actx = ts_lua_create_async_ctx(L, ci, n); |
| 338 | |
| 339 | contp = TSContCreate(ts_lua_schedule_handler, ci->mutex); |
| 340 | TSContDataSet(contp, actx); |
| 341 | |
| 342 | nci = &actx->cinfo; |
| 343 | nci->contp = contp; |
| 344 | nci->mutex = ci->mutex; |
| 345 | |
| 346 | TSContScheduleOnPool(contp, sec * 1000, TSThreadPool(entry)); |
| 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | static int |
| 352 | ts_lua_schedule_handler(TSCont contp, TSEvent ev, void *edata) |
nothing calls this directly
no test coverage detected