Skip to content
Snippets Groups Projects
Commit 9a1a9f09 authored by mechanik20051988's avatar mechanik20051988 Committed by Nikita Pettik
Browse files

lua: implement timeout for 'fiber:join'

Implement ability to pass timeout to 'fiber:join' function.
If timeout expired, join fails with 'timed out' error.

Closes #6203

@TarantoolBot document
Title: ability to set timeout for 'fiber:join' function was implemented
Implement ability to pass timeout to 'fiber:join' function.
If timeout expired, join fails with 'timed out' error.
parent b48b3332
No related branches found
No related tags found
No related merge requests found
## feature/core
* Implement timeout for 'fiber:join' in lua (gh-6203).
\ No newline at end of file
......@@ -809,13 +809,20 @@ lbox_fiber_join(struct lua_State *L)
if (!(fiber->flags & FIBER_IS_JOINABLE))
luaL_error(L, "the fiber is not joinable");
fiber_join(fiber);
double timeout = TIMEOUT_INFINITY;
if (!lua_isnoneornil(L, 2)) {
if (!lua_isnumber(L, 2) ||
(timeout = lua_tonumber(L, 2)) < .0) {
luaL_error(L, "fiber:join(timeout): bad arguments");
}
}
int rc = fiber_join_timeout(fiber, timeout);
if (child_L != NULL) {
coro_ref = lua_tointeger(child_L, -1);
lua_pop(child_L, 1);
}
if (fiber->f_ret != 0) {
if (rc != 0) {
/*
* After fiber_join the error of fiber being joined was moved to
* current fiber diag so we have to get it from there.
......
fiber = require('fiber')
---
...
timeout = 10
---
...
function sleep(timeout) \
channel:get() \
fiber.sleep(timeout) \
end
---
...
channel = fiber.channel()
---
...
f = fiber.create(sleep, timeout)
---
...
f:set_joinable(true)
---
...
channel:put(true)
---
- true
...
f:join(0.1) -- Join failed because of timeout
---
- false
- timed out
...
timeout = 0.2
---
...
f = fiber.create(sleep, timeout)
---
...
f:set_joinable(true)
---
...
channel:put(true)
---
- true
...
f:join("xxx") --error: 'fiber:join(timeout): bad arguments'
---
- error: 'fiber:join(timeout): bad arguments'
...
f:join(-1) --error: 'fiber:join(timeout): bad arguments'
---
- error: 'fiber:join(timeout): bad arguments'
...
fiber = require('fiber')
timeout = 10
function sleep(timeout) \
channel:get() \
fiber.sleep(timeout) \
end
channel = fiber.channel()
f = fiber.create(sleep, timeout)
f:set_joinable(true)
channel:put(true)
f:join(0.1) -- Join failed because of timeout
timeout = 0.2
f = fiber.create(sleep, timeout)
f:set_joinable(true)
channel:put(true)
f:join("xxx") --error: 'fiber:join(timeout): bad arguments'
f:join(-1) --error: 'fiber:join(timeout): bad arguments'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment