SuppliedNamedLocalThread<T> class final

A NamedLocalThread that provides an initial value using a Supplier function.

Extends NamedLocalThread to include a supplier function that provides the initial value for the thread-local variable when it is first accessed in a thread.

Key Features:

  • Descriptive name for identification
  • Supplier function for initial values
  • Thread-safe initialization
  • Combines naming with convenient initialization

Usage Example:

// Create a thread-local with initial value supplier
final counter = SuppliedNamedThreadLocal<int>(
  'requestCounter',
  () => 0, // Initial value for each thread
);

// In each thread, the initial value is automatically set to 0
print(counter.get()); // 0 (initial value from supplier)

// Increment the counter
counter.set(counter.get()! + 1);
print(counter.get()); // 1

// New thread gets fresh initial value
await Isolate.run(() {
  print(counter.get()); // 0 (new thread, new initial value)
});
Inheritance
Annotations
  • @Generic(SuppliedNamedLocalThread)

Constructors

SuppliedNamedLocalThread(String name, Supplier<T> supplier)
Creates a SuppliedNamedLocalThread with the given name and supplier function.

Properties

hashCode int
The hash code for this object.
no setterinherited
name String
The descriptive name of this thread-local variable.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supplier Supplier<T>
The supplier function that provides the initial value for each thread.
final

Methods

get() → T?
Returns the value associated with this LocalThread in the current Isolate.
inherited
initialValue() → T?
Returns the initial value for this LocalThread.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove() → void
Removes the value associated with this LocalThread in the current Isolate.
inherited
set(T value) → void
Sets a value for this LocalThread in the current Isolate.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited