mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-18 07:16:45 +00:00
optimizations, more comfortable PromiseFactory api and support virtual threaded executors
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package dev.tommyjs.futur.joiner;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
class ConcurrentResultArray<T> {
|
||||
|
||||
private final AtomicReference<T[]> ref;
|
||||
|
||||
public ConcurrentResultArray(int expectedSize) {
|
||||
//noinspection unchecked
|
||||
this.ref = new AtomicReference<>((T[]) new Object[expectedSize]);
|
||||
}
|
||||
|
||||
public void set(int index, T element) {
|
||||
ref.updateAndGet(array -> {
|
||||
if (array.length <= index)
|
||||
return Arrays.copyOf(array, index + 6);
|
||||
|
||||
array[index] = element;
|
||||
return array;
|
||||
});
|
||||
}
|
||||
|
||||
public @NotNull List<T> toList() {
|
||||
return Arrays.asList(ref.get());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user