Explanation: cancellation
Purpose: explain what cancelling an NFC operation can and cannot guarantee. Platforms: Android, iOS. Status: stable.
Cancellation races the outcome
A command sent to a tag cannot be taken back. Cancellation therefore does not undo work; it competes with the operation to commit one final result:
- Before dispatch: no native call is made. The result is
Cancelledwith mutationNotAttempted. - After a mutating call starts: exactly one of success and cancellation wins. If cancellation wins, the
mutation is
OutcomeUnknownunless a stronger fact is known; the tag may or may not have changed. - After success is committed: a later cancellation cannot rewrite the result.
Expected cancellation is a typed Cancelled result (portable.operation.cancelled), not an
OperationCanceledException. A deadline that elapses returns Timeout.
How cancellation reaches the hardware
Platforms offer different mechanisms. Each feature reports its mechanism in NfcFeatureCapability.Cancellation
and in the capability matrix:
| Value | Mechanism |
|---|---|
SoftwareClose |
The library closes the native connection independently of the blocked call (Android). |
SessionInvalidation |
The session is invalidated, which ends its I/O (Android discovery, iOS Core NFC). |
Unsupported |
The feature offers no cancellation of a started native call. |
A caller deadline is a software deadline, not a hardware timeout. A cancelled task can complete before native cleanup has finished; the owner stays reserved until cleanup is confirmed (see quarantine).
No hidden replay
The library never retries, splits or replays a command, including after cancellation or tag loss. A replayed
write after OutcomeUnknown could apply twice; a replayed APDU could repeat a payment or counter increment.
The decision to repeat belongs to the application, after reading the tag again.
What this means for your app
- Read
Effects.Mutationafter a cancelled or timed-out write before telling the user anything was or was not written. - Use
OutcomeUnknownas "check the tag on a new tap", never as "write again". - Stop and dispose are not cancellable once admitted; they always try to release the hardware.
Related
- Result and effect types: contracts.
- Reason codes of cancelled and timed-out operations: reason codes.
- Why cleanup failures block a tag: quarantine.