| 430 | } |
| 431 | |
| 432 | static int |
| 433 | ts_lua_sleep(lua_State *L) |
| 434 | { |
| 435 | int sec; |
| 436 | TSAction action; |
| 437 | TSCont contp; |
| 438 | ts_lua_async_item *ai; |
| 439 | ts_lua_cont_info *ci; |
| 440 | |
| 441 | ci = ts_lua_get_cont_info(L); |
| 442 | if (ci == nullptr) { |
| 443 | TSError("[ts_lua][%s] no cont info found", __FUNCTION__); |
| 444 | TSReleaseAssert(!"Unexpected fetch of cont info"); |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | sec = luaL_checknumber(L, 1); |
| 449 | if (sec < 1) { |
| 450 | sec = 1; |
| 451 | } |
| 452 | |
| 453 | contp = TSContCreate(ts_lua_sleep_handler, ci->mutex); |
| 454 | action = TSContScheduleOnPool(contp, sec * 1000, TS_THREAD_POOL_NET); |
| 455 | |
| 456 | ai = ts_lua_async_create_item(contp, ts_lua_sleep_cleanup, (void *)action, ci); |
| 457 | TSContDataSet(contp, ai); |
| 458 | |
| 459 | return lua_yield(L, 0); |
| 460 | } |
| 461 | |
| 462 | static int |
| 463 | ts_lua_sleep_handler(TSCont contp, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED) |
nothing calls this directly
no test coverage detected