Chapter 18½: inside jev-client/src — four files and a folder of tests
Small crate, one loop. Read the ports first, because the loop is written entirely in terms of them; then the loop; then what it returns when things go wrong.
The files, in reading order
- lib.rs: the crate's doc comment and its public surface,
re-exported from the three modules:
Client,Answered,ClientError, and the port types. - ports.rs: the two traits a host implements and the values
that cross them.
Transport:admit(&request)(optional; the default waits for nothing),send(request),distrust_connection().Runtime:now(),wall_clock(),sleep(d),timeout(d, future),jitter()(uniform in [0, 1)).HttpRequest { headers, body },HttpResponse { status, headers, body }.TransportError { kind, message }andTransportErrorKind, each kind documented with what the client does about it.ObserverandEvent, for counters and logs;()is the observer that hears nothing.Instant, which isweb_time::Instant:std::time::Instantitself on native targets, and aperformance.now()clock onwasm32-unknown-unknown, where std'sInstant::nowpanics and a Worker could not implementRuntime::nowat all.
- client.rs:
Client::new(transport, runtime, model, api_key),observed(observer),model(), andask(state, questions), the retry loop (Chapter 18 draws it).MAX_REDIALS= 2 lives here. At the bottom,mod tests;pulls in client/tests.rs. - error.rs:
ClientErrorand its five variants,nothing_billed()andrequest_id(). ItsDisplayappends the attempt count when there was more than one, and[request <id>]when a response carried one. - client/: the tests for the loop, Chapter 18¾.
Aside. Why is there a
client.rsand aclient/folder? That is how Rust spells "this module has a child module in its own file".client.rssaysmod tests;, and the compiler looks forclient/tests.rs. Nothing else lives in the folder.
Try it
cargo test -p jev-client
For the people who maintain it
In this folder
| Path | What |
|---|---|
| lib.rs | Doc comment and re-exports. |
| ports.rs | Transport, Runtime, Observer, Event, the request, response and error types, Instant. |
| client.rs | Client and the retry loop in ask. |
| error.rs | ClientError, nothing_billed, request_id. |
| client/ | Virtual-time tests for Client::ask. |
| CLAUDE.md | Invariants for agents. |
← Previous: Chapter 18: jev-client · Up: jev-client · Next: Chapter 18¾: jev-client/src/client →