>>108906020
Don't know some swift details. Took 10 minutes to draft the initial basic structure in Java. For what position is this?
class SyncCordinator {
int N = 3;
BlockingQueue<Note> reports = new LinkedBlockingQueue<>();
Queue<Future<?>> inFlight = new ArrayDeque<>();
Object monitor = new Object();
AtomicLong started = new AtomicLong();
Semaphore concurrent = new Semaphore(5);
SyncCordinator() {
var executor = Executors.newVirtualThreadPerTaskExecutor();
var dispatcher = Executors.newSingleThreadExecutor();
var rateLimiter = Executors.newSingleThreadExecutor();
dispatcher.submit(() -> {
while (true) {
long l = started.decrementAndGet();
if(l <= 0) { LockSupport.park(monitor);}
Note note = reports.poll();
concurrent.acquire();
Future<?> submit = executor.submit(() -> {
Main.uploadNote(note);
concurrent.release();
});
inFlight.offer(submit);
}
});
rateLimiter.submit(() -> {
while (true) {
LockSupport.parkNanos(1_000_000L);
started.set(5);
monitor.notify();
}
});
}
void sync(List<Note> notes) {
reports.forEach(report -> {
try {
reports.put(report);
} catch (InterruptedException e) {
// cancel working and remaining
}
});
}
void cancellAll() {
// interrupt inflight, drain queue and create report
}
}