|
|
@ -30,13 +30,12 @@ public class SudokuVerifier implements Flow.Subscriber<Boolean> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isSolved() {
|
|
|
|
public boolean isSolved() {
|
|
|
|
|
|
|
|
int subscriberCount = digitPublisher.getSubscribers().size();
|
|
|
|
// Make publisher emit each digit
|
|
|
|
// Make publisher emit each digit
|
|
|
|
digitStream.forEach(digitPublisher::submit);
|
|
|
|
digitStream.forEach(digitPublisher::submit);
|
|
|
|
digitPublisher.close();
|
|
|
|
digitPublisher.close();
|
|
|
|
// Wait for checking subscribers to finish
|
|
|
|
// Wait for checking subscribers to finish
|
|
|
|
int subscriberCount = digitPublisher.getSubscribers().size();
|
|
|
|
while ((finished.get() < subscriberCount) && solved.get()) {
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
if (!(finished.get() < subscriberCount && solved.get())) break;
|
|
|
|
|
|
|
|
justAMoment();
|
|
|
|
justAMoment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return solved.get();
|
|
|
|
return solved.get();
|
|
|
@ -74,17 +73,17 @@ public class SudokuVerifier implements Flow.Subscriber<Boolean> {
|
|
|
|
if (! solved) {
|
|
|
|
if (! solved) {
|
|
|
|
this.solved.compareAndSet(true, false);
|
|
|
|
this.solved.compareAndSet(true, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finished.incrementAndGet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onError(Throwable throwable) {
|
|
|
|
public void onError(Throwable throwable) {
|
|
|
|
System.err.println(throwable.fillInStackTrace());
|
|
|
|
System.err.println(throwable.fillInStackTrace());
|
|
|
|
finished.incrementAndGet();
|
|
|
|
finished.incrementAndGet();
|
|
|
|
System.exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onComplete() {
|
|
|
|
public void onComplete() {
|
|
|
|
finished.incrementAndGet();
|
|
|
|
// not called
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|