OpenDevicePartnership / OpenDevicePartnership/embedded-sensors

ThresholdWait has no documented cancel-safety contract

Open
#60 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation rust
Dominant language
Rust
Stars
4
Forks
9
Avg merge
5d 13h
Merged PRs (30d)
3

Description

Problem

wait_for_*_threshold is the one method in this HAL that callers will realistically put inside a select! or a timeout combinator, which means its future will be dropped before completion in normal use. The trait documentation says nothing about what happens in that case.

Unanswered questions an implementer and a caller both need answered:

  • If the alert latches (e.g. the ALERT pin asserts) and the future is then dropped, is the event lost or is it observed by the next call?
  • Is it legal to drop the future mid-I2C-transaction, and if so what state is the sensor left in?
  • Can two calls be made in sequence without re-arming thresholds?

This is the most important thing to specify about the trait and it is currently entirely unspecified.

Suggested fix

Add a # Cancel safety section to the generated ThresholdWait docs, following the convention used by embedded-hal-async and tokio. Decide and document whether implementations are required to be cancel-safe (preferred) or merely permitted not to be.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the generated ThresholdWait trait documentation and review the cancel-safety conventions in embedded-hal-async and tokio. Determine the intended answers for dropped futures, interrupted I2C transactions, and consecutive calls, then add a Cancel safety section whose contract addresses each question.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation, embedded-iot
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.