Description
There seem to be a few problems that are caused by side-effects of calls that return WouldBlock:
- ADC OneShot: Clarify asynchronous behavior embedded-hal#123 is about how to start a new ADC reading when an ADC reading was implicitly started by a read call that returned WouldBlock
- In nb architectural issues #15, @mqudsi wants to return WouldBlock but keep sending data in subsequent calls with the same arguments.
- Uncertainty about serial write methods: Could they have already transmitted a character even before a non-WouldBlock result has been returned?
The Core Idea section of the docs says that WouldBlock means that an operation would need to block in order to complete; my impression from the well-working use cases is that moreover, WouldBlock also indicates that an operation would need to block in order to start: Given the callee should not hold state about the arguments between calls, starting operations silently should not be desirable pattern.
I'd propose to-be-evaluated guidelines like this:
The WouldBlock error variant signals that the operation can't be executed right now and would need to block to complete, and that no action has been taken. WouldBlock is a special error in the sense that's not fatal; the operation was not started, and can still be executed by retrying again later.
A non-WouldBlock result indicates that the operation has been executed and completed – or at least been taken up for execution, and the result is already predictable and can be returned.
Operations in which both the start and the execution may block can be split up into two parts (likeembedded_hal::SPI::FullDuplex::{send,read}
).
That's obviously not a change that can be just-so made (and invalidate existing use cases like embedded_hal::adc::OneShot
), but more of something to keep around as a usage pattern, to try implementations against, and to see whether it can evolve into something that can at some point supersede the current description.