Better errors and return codes

Signed-off-by: Rahix <rahix@rahix.de>
dev
rahix 7 years ago
parent c6f019f271
commit 1a9422af7d

@ -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)

@ -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…
Cancel
Save