A Janet client library for interfacing with Tile38.
The library can be installed with jpm
using jpm install https://github.com/rokf/janet-tile38
or by adding the following line into your project's dependency tuple:
{ :url "https://github.com/rokf/janet-tile38" :tag "main" }
After the library is installed you should be able to import its tile38
module with (import tile38)
.
The make-client
function takes three optional parameters:
host
(string), defaults to127.0.0.1
port
(number), defaults to9851
pass
(string), the password for authentication (if required), defaults tonil
It creates a new Tile38 client that wraps its RESP API. The client can be
used with Janet's with
, because it implements a :close
method.
(def client (tile38/make-client "localhost" 9852 "my-secret-123"))
Functions for Tile38's commands are generated using a macro because they all follow the same pattern. See Commands for details. See tests and examples for some practical usage examples. Generally they're following the pattern below:
(tile38/{command} client & args)
Some commands don't take any arguments. In those cases you'd only have to pass in the client.
Closes the underlying connection stream.
(tile38/close client)
Waits for events (notifications) to appear in subscribed channels, decodes them
and pushes them into an event channel, which you have to pass as an argument
(event-ch
). Exits cleanly if the stop-ch
channel is closed using something
like (ev/chan-close stop-ch)
from the standard library. The interval for
stop-ch
state checks and reading from the client's internal Tile38 connection
can be configured using the optional timeout
parameter, which defaults to
0.5
, meaning half a second. By default it will wait for half a second each
loop iteration for the stop-ch
channel to get closed and then it will try
to read from the connection for half a second, before going back to the stop-ch
check.
(tile38/watch client event-ch stop-ch &opt timeout)
Usage examples can be found in the examples
folder. The folder also contains
a Docker Compose specification that spins up a Tile38 server instance, which
has the configuration required by the examples.
Unit tests can be found in the test
folder. They require judge
to be
installed on your machine. You can install judge
with:
jpm install https://github.com/ianthehenry/judge
MIT - see the LICENSE
file for details.