const classafConcurrent::AtomicList
sys::Obj afConcurrent::AtomicList
@
Js
A List that provides fast reads and lightweight writes between threads using the copy on write paradigm.
The list is stored in an AtomicRef through which all reads are made. Writing makes a rw
copy of the list and is thus a more expensive operation.
CAUTION: Write operations (
add
,remove
&clear
) are not synchronised. This makes them lightweight but also susceptible to data-loss during race conditions. Though this may be acceptable for caching situations where values are re-calculated on demand.
All values held in the list must be immutable.
- add
Add the specified item to the end of the list. Return this.
- clear
This clear()
Remove all key/value pairs from the map. Return this.
- contains
Returns
true
if this list contains the specified item.- each
Call the specified function for every item in the list.
- first
Obj? first()
Return the item at index 0, or if empty return null.
- get
Returns the item at the specified index. A negative index may be used to access an index from the end of the list.
- insert
This insert(Int index, Obj? item)
Insert the item at the specified index. A negative index may be used to access an index from the end of the list. Size is incremented by 1. Return this. Throw IndexErr if index is out of range. Throw ReadonlyErr if readonly.
- isEmpty
Bool isEmpty()
Return
true
if size() == 0- last
Obj? last()
Return the item at index-1, or if empty return null.
- peek
Obj? peek()
- pop
Obj? pop()
- push
- remove
Removes the specified item from the list, returning the removed item. If the item was not mapped then return
null
.- removeAt
Remove the object at the specified index. A negative index may be used to access an index from the end of the list. Return the item removed.
- rw
Obj?[] rw()
Get a read-write, mutable List instance with the same contents.
- size
Int size()
Get the number of values in the map.
- toStr
virtual override Str toStr()
Returns a string representation the list.
- val
Obj?[] val
Gets or sets a read-only copy of the backing map.
- valType
const Type valType := sys::Obj?#
Used to parameterize the backing list.
AtomicList() { it.valType = Str# }