NamedLocalThread<T> class final

A specialized LocalThread that includes a descriptive name for better debugging and identification.

Extends the standard LocalThread class by adding a human-readable name that helps identify the purpose of the thread-local variable during debugging, logging, and maintenance.

Key Features:

  • Provides meaningful names for thread-local variables
  • Enhanced toString() output for better debugging
  • Maintains all functionality of standard ThreadLocal

Usage Example:

// Create a named thread-local variable for user session data
final userSession = NamedThreadLocal<Map<String, dynamic>>('userSession');

// In each thread, you can set and get values
userSession.set({'userId': 123, 'username': 'john_doe'});

// Later retrieve the value
final session = userSession.get();
print(session); // {'userId': 123, 'username': 'john_doe'}

// toString() shows the descriptive name
print(userSession.toString()); // 'userSession'

When to Use:

  • When you need multiple thread-local variables and want to distinguish them clearly
  • For better debugging and logging output
  • In frameworks where thread-local variables need descriptive identifiers
Inheritance
Implementers
Annotations

Constructors

NamedLocalThread(String name)
Creates a NamedLocalThread with the given descriptive name.

Properties

hashCode int
The hash code for this object.
no setterinherited
name String
The descriptive name of this thread-local variable.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

get() → T?
Returns the value associated with this LocalThread in the current Isolate.
inherited
initialValue() → T?
Returns the initial value for this LocalThread.
inherited
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.
override

Operators

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