Add timeout to call_sync
Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
parent
253e04ff5d
commit
2b935b87e4
3 changed files with 11 additions and 6 deletions
|
|
@ -146,7 +146,7 @@ bc:finalize()
|
|||
bc:call("some_verb", "param_a_value", "param_b_value")
|
||||
```
|
||||
|
||||
### `BaseControl:call_sync(verb, timeout, ...)`
|
||||
### `BaseControl:call_sync([timeout], verb, ...)`
|
||||
Call a verb **synchroneously**. All parameters following `verb` will be given
|
||||
to the remote function. `call_sync` will return the remote function's return
|
||||
value. If timeout is not `nil` or `0`, `call_sync` will error upon
|
||||
|
|
@ -161,7 +161,7 @@ end)
|
|||
bc:finalize()
|
||||
|
||||
-- This call can either happen locally or on another node
|
||||
local res = bc:call_sync("stupid_add", nil, 12, 34)
|
||||
local res = bc:call_sync("stupid_add", 12, 34)
|
||||
print("12 + 34 = "..res)
|
||||
```
|
||||
|
||||
|
|
|
|||
11
bc.lua
11
bc.lua
|
|
@ -352,14 +352,19 @@ function BaseControl:call(verb, ...)
|
|||
end
|
||||
end
|
||||
|
||||
function BaseControl:call_sync(verb, ...)
|
||||
function BaseControl:call_sync(timeout, verb, ...)
|
||||
local param = {...}
|
||||
if type(timeout) ~= "number" then
|
||||
table.insert(param, 1, verb)
|
||||
timeout, verb = nil, timeout
|
||||
end
|
||||
if self.local_verbs[verb] ~= nil then
|
||||
return self.local_verbs[verb](...)
|
||||
return self.local_verbs[verb](table.unpack(param))
|
||||
elseif self.remote_verbs[verb] ~= nil then
|
||||
self.network:send(self.remote_verbs[verb], {
|
||||
ty=Message.VerbRequest,
|
||||
verb=verb,
|
||||
param={...},
|
||||
param=param,
|
||||
sync=true,
|
||||
})
|
||||
local answer = self.network:pull(function(remote, msg)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function test_timeout_call()
|
|||
)
|
||||
|
||||
assert_error_match("timeout", function()
|
||||
bc:call_sync("toc1v", 0.1)
|
||||
bc:call_sync(0.1, "toc1v")
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue