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, ...)`
|
||||
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.
|
||||
`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.
|
||||
```lua
|
||||
|
|
@ -146,8 +149,10 @@ bc:call("some_verb", "param_a_value", "param_b_value")
|
|||
### `BaseControl:call_sync(verb, timeout, ...)`
|
||||
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 return early upon
|
||||
value. If timeout is not `nil` or `0`, `call_sync` will error upon
|
||||
the timeout expiring.
|
||||
|
||||
_Note_: For local verbs, the timeout can not be adhered to.
|
||||
```lua
|
||||
local bc = require("bc")
|
||||
bc:register("stupid_add", function(a, b)
|
||||
|
|
|
|||
8
bc.lua
8
bc.lua
|
|
@ -245,7 +245,7 @@ function BaseControl:get(noun, timeout)
|
|||
error("timeout")
|
||||
end
|
||||
else
|
||||
return error("unknown")
|
||||
return error("unknown noun \""..noun.."\"")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -289,12 +289,16 @@ end
|
|||
function BaseControl:call(verb, ...)
|
||||
if self.local_verbs[verb] ~= nil then
|
||||
self.local_verbs[verb](...)
|
||||
return true
|
||||
elseif self.remote_verbs[verb] ~= nil then
|
||||
self.network:send(self.remote_verbs[verb], {
|
||||
ty=Message.VerbRequest,
|
||||
verb=verb,
|
||||
param={...},
|
||||
})
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -320,7 +324,7 @@ function BaseControl:call_sync(verb, ...)
|
|||
error("timeout")
|
||||
end
|
||||
else
|
||||
error("unknown")
|
||||
error("unknown verb \""..verb.."\"")
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue