Package net.dv8tion.jda.api.utils
Class LockIterator<T>
java.lang.Object
net.dv8tion.jda.api.utils.LockIterator<T>
- Type Parameters:
T
- The element type for this iterator
- All Implemented Interfaces:
AutoCloseable
,Iterator<T>
,ClosableIterator<T>
Simple implementation of a
Close is an idempotent function and can be performed multiple times without effects beyond first invocation.
This is deployed by
ClosableIterator
that uses a lock.
Close is an idempotent function and can be performed multiple times without effects beyond first invocation.
This is deployed by
CacheView.lockedIterator()
to allow read-only access
to the underlying structure without the need to clone it, unlike the normal iterator.
This closes automatically when hasNext()
returns false
but
its recommended to only be used within a try-with-resources
block for safety.
Example
This can handle any exceptions thrown while iterating and ensures the lock is released correctly.
try (ClosableIterator<T> it = cacheView.lockedIterator()) {
while (it.hasNext()) {
consume(it.next());
}
}
- Since:
- 4.0.0
-
Constructor Details
-
LockIterator
-
-
Method Details