LocalThreadStorageBucket<T> constructor
LocalThreadStorageBucket<T> (
- T? initialValue,
- Isolate isolate
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
Creates a new LocalThreadStorageBucket bound to the given isolate.
If initialValue is provided, it is stored immediately.
Implementation
LocalThreadStorageBucket(T? initialValue, Isolate isolate) : _isolate = isolate {
if (initialValue != null) {
_storage = initialValue;
}
}