Better errors and return codes
Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
parent
c6f019f271
commit
1a9422af7d
2 changed files with 12 additions and 3 deletions
|
|
@ -130,6 +130,9 @@ print("Value: ", bc:get("some_noun"))
|
||||||
### `BaseControl:call(verb, ...)`
|
### `BaseControl:call(verb, ...)`
|
||||||
Call a verb **asynchroneously**. All parameters following `verb` will be given
|
Call a verb **asynchroneously**. All parameters following `verb` will be given
|
||||||
to the remote function. There is no guarantee that the verb was actually run.
|
to the remote function. There is no guarantee that the verb was actually run.
|
||||||
|
`call` will return `true` if an attempt was made to run the verb and `false`
|
||||||
|
otherwise. `call` specifically does **not** error, because no guarantees
|
||||||
|
could be made anyway.
|
||||||
|
|
||||||
_Note_: For local verbs, the call will still be synchroneous.
|
_Note_: For local verbs, the call will still be synchroneous.
|
||||||
```lua
|
```lua
|
||||||
|
|
@ -146,8 +149,10 @@ bc:call("some_verb", "param_a_value", "param_b_value")
|
||||||
### `BaseControl:call_sync(verb, timeout, ...)`
|
### `BaseControl:call_sync(verb, timeout, ...)`
|
||||||
Call a verb **synchroneously**. All parameters following `verb` will be given
|
Call a verb **synchroneously**. All parameters following `verb` will be given
|
||||||
to the remote function. `call_sync` will return the remote function's return
|
to the remote function. `call_sync` will return the remote function's return
|
||||||
value. If timeout is not `nil` or `0`, `call_sync` will return early upon
|
value. If timeout is not `nil` or `0`, `call_sync` will error upon
|
||||||
the timeout expiring.
|
the timeout expiring.
|
||||||
|
|
||||||
|
_Note_: For local verbs, the timeout can not be adhered to.
|
||||||
```lua
|
```lua
|
||||||
local bc = require("bc")
|
local bc = require("bc")
|
||||||
bc:register("stupid_add", function(a, b)
|
bc:register("stupid_add", function(a, b)
|
||||||
|
|
|
||||||
8
bc.lua
8
bc.lua
|
|
@ -245,7 +245,7 @@ function BaseControl:get(noun, timeout)
|
||||||
error("timeout")
|
error("timeout")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return error("unknown")
|
return error("unknown noun \""..noun.."\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -289,12 +289,16 @@ end
|
||||||
function BaseControl:call(verb, ...)
|
function BaseControl:call(verb, ...)
|
||||||
if self.local_verbs[verb] ~= nil then
|
if self.local_verbs[verb] ~= nil then
|
||||||
self.local_verbs[verb](...)
|
self.local_verbs[verb](...)
|
||||||
|
return true
|
||||||
elseif self.remote_verbs[verb] ~= nil then
|
elseif self.remote_verbs[verb] ~= nil then
|
||||||
self.network:send(self.remote_verbs[verb], {
|
self.network:send(self.remote_verbs[verb], {
|
||||||
ty=Message.VerbRequest,
|
ty=Message.VerbRequest,
|
||||||
verb=verb,
|
verb=verb,
|
||||||
param={...},
|
param={...},
|
||||||
})
|
})
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -320,7 +324,7 @@ function BaseControl:call_sync(verb, ...)
|
||||||
error("timeout")
|
error("timeout")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error("unknown")
|
error("unknown verb \""..verb.."\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue