LocalThreadStorageBucket<T> class
final
A mutable storage container for a LocalThread value, bound to a specific Isolate.
Internally, it uses a List<T?>
to store a single value, which allows mutation without
replacing the container itself. This technique supports per-isolate scoped thread-local data.
The storage can hold only one value at a time. The get
, set
, and remove
methods
allow access and management of the thread-local state.
Typically used internally by the LocalThread class to isolate thread-local values per Isolate.
Example
final isolate = Isolate.current;
final bucket = ThreadLocalStorageBucket<String>('initial', isolate);
print(bucket.get()); // prints: initial
bucket.set('updated');
print(bucket.get()); // prints: updated
bucket.remove();
print(bucket.get()); // prints: null
- Annotations
-
- @Generic(LocalThreadStorageBucket)
Constructors
- LocalThreadStorageBucket(T? initialValue, Isolate isolate)
- A mutable storage container for a LocalThread value, bound to a specific Isolate.
Properties
Methods
-
get(
) → T? - Returns the value stored in this bucket.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
) → void - Clears the stored value and kills the associated isolate.
-
set(
T value) → void - Sets or replaces the stored value.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited