Skip to content

Commit

Permalink
Merge pull request #17 from ravinperera00/java21_sync
Browse files Browse the repository at this point in the history
Revert callMethod improvement
  • Loading branch information
warunalakshitha authored Nov 27, 2024
2 parents 78a1dfa + de99df3 commit 5b5c2ed
Showing 1 changed file with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ public int read() {
public void close() throws IOException {
super.close();
if (closeMethod != null) {
env.yieldAndRun(() -> {
env.getRuntime().callMethod(iterator, closeMethod.getName(), null);
return null;
});
env.getRuntime().callMethod(iterator, closeMethod.getName(), null);
}
}

Expand All @@ -88,30 +85,29 @@ private boolean hasBytesInCurrentChunk() {
}

private boolean readNextChunk() throws InterruptedException {
return env.yieldAndRun(() -> {
try {
Object result = env.getRuntime().callMethod(iterator, nextMethodName, null);
if (result == null) {
this.done = true;
return !this.done;
}
if (result instanceof BMap<?, ?>) {
BMap<BString, Object> valueRecord = (BMap<BString, Object>) result;
final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get();
final BArray arrayValue = valueRecord.getArrayValue(value);
currentChunk = arrayValue.getByteArray();
} else {
// Case where Completes with an error
this.done = true;
}
} catch (BError bError) {
// Panic with an error

try {
Object result = env.getRuntime().callMethod(iterator, nextMethodName, null);
if (result == null) {
this.done = true;
currentChunk = new byte[0];
// TODO : Should we panic here?
return !this.done;
}
return !this.done;
});
if (result instanceof BMap<?, ?>) {
BMap<BString, Object> valueRecord = (BMap<BString, Object>) result;
final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get();
final BArray arrayValue = valueRecord.getArrayValue(value);
currentChunk = arrayValue.getByteArray();
} else {
// Case where Completes with an error
this.done = true;
}
} catch (BError bError) {
// Panic with an error
this.done = true;
currentChunk = new byte[0];
// TODO : Should we panic here?
}
return !this.done;
}

public BError getError() {
Expand Down

0 comments on commit 5b5c2ed

Please sign in to comment.