Skip to content

Permissible side-effects of calls that return WouldBlock #16

Open
@chrysn

Description

@chrysn

There seem to be a few problems that are caused by side-effects of calls that return WouldBlock:

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 (like embedded_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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions