Skip to content

Commit

Permalink
Add yield logic for async call
Browse files Browse the repository at this point in the history
  • Loading branch information
HindujaB committed Nov 22, 2024
1 parent 43b6872 commit f3aaa1b
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ public static Object parseBytes(BArray json, BMap<BString, Object> options, BTyp

public static Object parseStream(Environment env, BStream json, BMap<BString, Object> options, BTypedesc typed) {
final BObject iteratorObj = json.getIteratorObj();
BallerinaByteBlockInputStream byteBlockSteam = new BallerinaByteBlockInputStream(env,
iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj));
Object result = JsonParser.parse(new InputStreamReader(byteBlockSteam), options, typed);
if (byteBlockSteam.getError() != null) {
return byteBlockSteam.getError();
}
return result;
return env.yieldAndRun(() -> {
BallerinaByteBlockInputStream byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj,
resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj));
Object result = JsonParser.parse(new InputStreamReader(byteBlockSteam), options, typed);
if (byteBlockSteam.getError() != null) {
return byteBlockSteam.getError();
}
return result;
});
}

public static Object toJson(Object value) {
Expand Down

0 comments on commit f3aaa1b

Please sign in to comment.