Skip to content

Commit

Permalink
Implement and document resultType method, bump version to 0.2.0
Browse files Browse the repository at this point in the history
To facilitate history navigation, the source file has been renamed so
that the current version doesn't appear in the file name and I don't
have to move it at each bump. Provide a symlink to the current version
to facilitate package require.
  • Loading branch information
gahr committed May 10, 2017
1 parent 4961b78 commit eb60f48
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ returns a boolean indicating whether a response for the result is available:
% r resultReady rds:1
1

The type of a result can also be queried with the `resultType` method. If a
result is not ready, the method returns the empty string. Otherwise, it returns
one of `SimpleString`, `Error`, `Integer`, `BulkString`, `Array`.

% r PING
rds:1
% r resultType rds:1
SimpleString

The asynchronous operation mode can be turned off (and back on) using the pair
of methods `-async` and `+async`. When the asynchronous mode is disabled,
Redis commands are executed and their results returned as soon as they are
Expand Down
1 change: 1 addition & 0 deletions retcl-0.2.0.tm
22 changes: 17 additions & 5 deletions retcl-0.1.0.tm → retcl.tm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package require Tcl 8.6
package require TclOO

package provide retcl 0.1.0
package provide retcl 0.2.0

catch {retcl destroy}

Expand All @@ -44,11 +44,12 @@ oo::class create retcl {
# to the server is assigned a unique identifier, which can be then used by
# the user to retrieve the result (see [result] method). The resultsCache
# variable is a dictionary where unique identifiers are the keys, with
# further keys for status, and response. Status is either 0 (not replied)
# or 1 (replied). New commands are appended at the tail of the list;
# responses are inserted at the first command with a status 0.
# further keys for status, type, and response. Status is either 0 (not
# replied) or 1 (replied). Type is one of the values of the typeNames list.
# New commands are appended at the tail of the list; responses are inserted
# at the first command with a status 0.
#
# (cmd1 {status (0|1) response (RESPONSE)})
# (cmd1 {status (0|1) type (SimpleString|...) response (RESPONSE)})
#
variable resultsCache

Expand Down Expand Up @@ -267,6 +268,16 @@ oo::class create retcl {
dict get $resultsCache $cmdId status
}

##
# Retrieve the type of a result, or the empty string if the result is not
# ready.
method resultType {cmdId} {
if {[catch {dict get $resultsCache $cmdId type} res]} {
set res {}
}
set res
}

##
# Return a dictionary of the reuslts in form
# of cmdId => result.
Expand Down Expand Up @@ -578,6 +589,7 @@ oo::class create retcl {
my Error "No request found for response $body"
}
set cmdId [lindex $cmdIds 0]
dict set resultsCache $cmdId type $type
dict set resultsCache $cmdId response $body
dict set resultsCache $cmdId status 1
}
Expand Down
2 changes: 1 addition & 1 deletion test/001-pkg-version.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tcltest::test pkg-version-1.1 {pkg version is correct} -body {
package require retcl
} -result {0.1.0}
} -result {0.2.0}
33 changes: 33 additions & 0 deletions test/009-resultType.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
tcltest::test resultType-1.1 {set is simple string} -constraints {
serverIsRunning
} -setup {
set r [retcl new]
} -body {
set res [$r set a 12]
set done 0
after 100 {
set done 1
}
vwait done
$r resultType $res
} -cleanup {
$r del 12
$r destroy
} -result {SimpleString}

tcltest::test resultType-1.2 {set with two params is an error} -constraints {
serverIsRunning
} -setup {
set r [retcl new]
} -body {
set res [$r set a 12 13]
set done 0
after 100 {
set done 1
}
vwait done
$r resultType $res
} -cleanup {
$r del 12
$r destroy
} -result {Error}

0 comments on commit eb60f48

Please sign in to comment.