Skip to content

Commit af2dd88

Browse files
owenpearsonclaude
andcommitted
docs: record that time is read through the clock
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 35e7e56 commit af2dd88

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎CLAUDE.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
- after making any code changes, run `uv ruff check` to make sure linting passes
22
- use `uv` to run any other necessary tasks such as `pytest`
3+
4+
# Time
5+
6+
Production code in `ably/` reads the current time and schedules delayed callbacks through
7+
the clock, never through `time`, `datetime.now` or `asyncio.sleep`:
8+
9+
- `select_clock(options)` in the constructor, from `ably.util.clock`
10+
- `now_ms()` for the time of day
11+
- `monotonic_ms()` for a duration
12+
- `timer(timeout_ms, callback)` for a delayed callback
13+
14+
A test replaces it with `TestOptions(clock=...)`. Converting a caller-supplied value, and
15+
arithmetic on the unix epoch, are not clock readings and stay as they are.
16+
17+
`asyncio.wait_for` in `ConnectionManager.ping` is the one delay that runs on the event
18+
loop's clock rather than this one; a test which waits it out sets a short real
19+
`realtime_request_timeout`.
20+
21+
`Auth._timestamp` signs a token request the server validates, so a client which reads a
22+
fake clock talks to a mock rather than to the sandbox.

0 commit comments

Comments
 (0)