Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added null-check to the send Command helper function for at.Session #1227

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 28 additions & 40 deletions lib/at/session.toit
Original file line number Diff line number Diff line change
Expand Up @@ -222,68 +222,56 @@ class Session:
urc_handlers_.remove name
--if_absent=: throw "urc not registered: $name"

/**
Executes a `read` command with the $command_name.
*/
read command_name/string --timeout/Duration?=null -> Result:
return send
Command.read command_name --timeout=timeout

/**
Executes a $Command.read with the $command_name.

Returns null on time out when non $check.
Returns null on timeout when non $check.
*/
read command_name/string --timeout/Duration?=null --check -> Result?:
cmd ::= Command.read command_name --timeout=timeout
read command_name/string --timeout/Duration?=null --check/bool=true -> Result?:
cmd ::= ?
if timeout == null:
cmd = Command.read command_name
else:
cmd = Command.read command_name --timeout=timeout
return check ? send cmd : send_non_check cmd

/**
Executes a `test` command with the $command_name.
*/
test command_name/string --timeout/Duration?=null -> Result:
return send
Command.test command_name --timeout=timeout

/**
Executes a $Command.test with the $command_name.

Returns null on time out when non $check.
Returns null on timeout when non $check.
*/
test command_name/string --timeout/Duration?=null --check -> Result?:
cmd ::= Command.test command_name --timeout=timeout
test command_name/string --timeout/Duration?=null --check/bool=true -> Result?:
cmd ::= ?
if timeout == null:
cmd = Command.test command_name
else:
cmd = Command.test command_name --timeout=timeout
return check ? send cmd : send_non_check cmd

/**
Executes a `set` command with the $command_name, along with $parameters and optional $data.
*/
set command_name/string parameters/List --data=null --timeout/Duration?=null -> Result:
return send
Command.set command_name --parameters=parameters --data=data --timeout=timeout

/**
Executes a $Command.set with the $command_name.

Returns null on time out when non $check.
Returns null on timeout when non $check.
*/
set command_name/string parameters/List --data=null --timeout/Duration?=null --check/bool-> Result?:
cmd ::= Command.set command_name --parameters=parameters --data=data --timeout=timeout
set command_name/string parameters/List --data=null --timeout/Duration?=null --check/bool=true -> Result?:
cmd ::= ?
if timeout == null:
cmd = Command.set command_name --parameters=parameters --data=data
else:
cmd = Command.set command_name --parameters=parameters --data=data --timeout=timeout
return check ? send cmd : send_non_check cmd

/**
Executes an `action` command with the $command_name.
*/
action command_name/string --timeout/Duration?=null -> Result:
return send
Command.action command_name --timeout=timeout

/**
Executes a $Command.action with the $command_name.

Returns null on time out when non $check.
Returns null on timeout when non $check.
*/
action command_name/string --timeout/Duration?=null --check/bool -> Result?:
cmd ::= Command.action command_name --timeout=timeout
action command_name/string --timeout/Duration?=null --check/bool=true -> Result?:
cmd ::= ?
if timeout == null:
cmd = Command.action command_name
else:
cmd = Command.action command_name --timeout=timeout
return check ? send cmd : send_non_check cmd

/**
Expand Down