Skip to content

Commit 657cc55

Browse files
committed
Improve README usability and API guidance
1 parent 8d23686 commit 657cc55

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,36 @@
33
[![](https://img.shields.io/nuget/dt/soenneker.atomics.nullablebools.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.atomics.nullablebools/)
44
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.atomics.nullablebools/codeql.yml?label=CodeQL&style=for-the-badge)](https://github.com/soenneker/soenneker.atomics.nullablebools/actions/workflows/codeql.yml)
55

6-
# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.Atomics.NullableBools
7-
### A lock free atomic nullable boolean.
6+
# Soenneker.Atomics.NullableBools
87

9-
## Installation
8+
A lightweight atomic tri-state flag implemented on top of an inline `ValueAtomicInt`. Backing values: `-1` = null / unknown `0` = false `1` = true.
109

11-
```
10+
## Install
11+
12+
```bash
1213
dotnet add package Soenneker.Atomics.NullableBools
1314
```
15+
16+
## What you get
17+
18+
- `AtomicNullableBool` — A lightweight atomic tri-state flag implemented on top of an inline `ValueAtomicInt`. Backing values: `-1` = null / unknown `0` = false `1` = true.
19+
20+
## API at a glance
21+
22+
| API | What it does | Result / important behavior |
23+
| --- | --- | --- |
24+
| `AtomicNullableBool.HasValue` | Gets a value indicating whether the current state is non-null. | Gets a value indicating whether the current state is non-null. |
25+
| `AtomicNullableBool.Value` | Gets or sets the current value as a nullable boolean. | Gets or sets the current value as a nullable boolean. |
26+
| `AtomicNullableBool.Read()` | Reads the raw backing state. | `-1` (null), `0` (false), or `1` (true). |
27+
| `AtomicNullableBool.GetValueOrFalse()` | Gets the value, treating `null`/`unknown` as `false`. | true if gets the value, treating null/unknown as; otherwise, false. |
28+
| `AtomicNullableBool.GetValueOrTrue()` | Gets the value, treating `null`/`unknown` as `true`. | true if gets the value, treating null/unknown as; otherwise, false. |
29+
| `AtomicNullableBool.Set(value)` | Sets the state to `true` or `false`. | Returns no value; the requested change is complete when the method returns. |
30+
| `AtomicNullableBool.TrySet(value)` | Attempts to set the state to `true` or `false` only if the current state is `null`/`unknown`. | true if the requested update was applied; otherwise, false. |
31+
| `AtomicNullableBool.TryCompareExchange(newState, expected)` | Attempts to transition the state from `expected` to `newState`. | true if the requested update was applied; otherwise, false. |
32+
| `AtomicNullableBool.Reset()` | Resets the state to `null`/`unknown`. | Returns no value; the requested change is complete when the method returns. |
33+
| `AtomicNullableBool.ToString()` | Returns a string representation of the current state. | Returns `string`. |
34+
35+
## Important behavior
36+
37+
- `AtomicNullableBool`: Reads establish acquire semantics and writes establish release semantics. This is a mutable reference type. Use as a private field and avoid exposing the instance publicly unless you want shared, aliasable state.
38+
- `AtomicNullableBool.Write(state)`: Callers must only provide valid values: `-1`, `0`, or `1`.

0 commit comments

Comments
 (0)