Chapter 19½: inside jev-worker/src — one file, two adapters
Everything is in lib.rs, top to bottom in the order you would read it.
lib.rs, in reading order
- The doc comment: what the crate is and why it has no ledger.
MAX_BODY: 8 MiB, the most of a response body it accepts, the same capjev-httpuses. A bigger body isTooLarge, which the client never retries (the answer was already produced and billed).FetchTransport: holds one URL.FetchTransport::api()isjev_protocol::ENDPOINT;FetchTransport::new(url)is anything else.request(url, sent): turnsjev-client'sHttpRequestinto a workers-rsRequest: aPOSTwith every header copied and the body as aUint8Array. A header that is not valid text, or a request workers-rs will not build, is aConfigerror.header_map(headers): turns the response'sHeadersback into anhttp::HeaderMap, skipping any pairhttpwill not accept.impl Transport for FetchTransport:sendrunsFetch::Request(..) .send(). A failed fetch isConnect; a failure reading the body isInterrupted; an oversized body isTooLarge.distrust_connectionis empty, becausefetchowns the connections.WorkerRuntimeandimpl Runtime:nowisjev_client::Instant::now()(web-time'sperformance.now()clock),wall_clockisDate.now(),sleepis a workers-rsDelay,timeoutraces the future against aDelaywithfutures_util::future::select, andjitterisMath.random().
fetch outcome | TransportErrorKind | What the client does |
|---|---|---|
| the request cannot be built | Config | fails at once |
fetch itself fails | Connect | retries with backoff |
| reading the body fails | Interrupted | retries with backoff |
| body over 8 MiB | TooLarge | fails at once |
Try it
cargo build -p jev-worker --target wasm32-unknown-unknown
For the people who maintain it
In this folder
| File | What |
|---|---|
| lib.rs | FetchTransport, WorkerRuntime, MAX_BODY. |
| CLAUDE.md | Invariants for agents. |
← Previous: Chapter 19: jev-worker · Up: jev-worker · Next: Chapter 20: jev-http →