Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rokf/janet-tile38
A Janet client library for interfacing with Tile38
https://github.com/rokf/janet-tile38
janet janet-lang tile38 tile38-client
Last synced: about 1 month ago
JSON representation
A Janet client library for interfacing with Tile38
- Host: GitHub
- URL: https://github.com/rokf/janet-tile38
- Owner: rokf
- License: mit
- Created: 2024-10-16T20:44:18.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-19T15:36:41.000Z (3 months ago)
- Last Synced: 2024-10-20T04:22:15.058Z (2 months ago)
- Topics: janet, janet-lang, tile38, tile38-client
- Language: Janet
- Homepage: https://tile38.com
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# janet-tile38
A Janet client library for interfacing with Tile38.
## Installation
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:```janet
{ :url "https://github.com/rokf/janet-tile38" :tag "main" }
```## API
After the library is installed you should be able to import its `tile38`
module with `(import tile38)`.### `tile38/make-client`
The `make-client` function takes three optional parameters:
- `host` (string), defaults to `127.0.0.1`
- `port` (number), defaults to `9851`
- `pass` (string), the password for authentication (if required), defaults to `nil`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.```janet
(def client (tile38/make-client "localhost" 9852 "my-secret-123"))
```### `tile38/{command}`
Functions for Tile38's commands are generated using a macro because they all
follow the same pattern. See [Commands](https://tile38.com/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.### `tile38/close`
Closes the underlying connection stream.
```janet
(tile38/close client)
```### `tile38/watch`
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.```janet
(tile38/watch client event-ch stop-ch &opt timeout)
```## Examples
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.## Tests
Unit tests can be found in the `test` folder. They require `judge` to be
installed on your machine. You can install `judge` with:```sh
jpm install https://github.com/ianthehenry/judge
```## License
MIT - see the `LICENSE` file for details.