dcapwell commented on code in PR #56:
URL: https://github.com/apache/cassandra-accord/pull/56#discussion_r1297760397
##########
accord-core/src/main/java/accord/utils/async/AsyncResults.java:
##########
@@ -333,14 +333,19 @@ public RunnableResult(Callable<V> callable)
@Override
public void run()
{
+ V result = null;
+ boolean success = false;
try
{
- trySetResult(callable.call(), null);
+ result = callable.call();
+ success = true;
}
catch (Throwable t)
{
trySetResult(null, t);
}
+ if (success)
+ trySetResult(result, null);
Review Comment:
it would be good to document why the code is written this way, and we can
avoid the boolean `success` if we rely on `return` when a failure is thrown
```
// There are two different type of exceptions: user function throws,
listener throws. To make sure this is clear,
// make sure to catch the exception from the user function and
set as failed, and let the listener exceptions bubble up.
V call;
try
{
call = callable.call();
}
catch (Throwable t)
{
setResult(null, t);
return;
}
setResult(call, null);
```
##########
accord-core/src/test/java/accord/impl/basic/TaskExecutorService.java:
##########
@@ -44,14 +44,19 @@ public Task(Callable<T> fn)
@Override
public void run()
{
+ T result = null;
Review Comment:
to avoid copy/paste maybe we should `extends AsyncResults.RunnableResult`?
```
public static class Task<T> extends AsyncResults.RunnableResult<T>
implements Pending, RunnableFuture<T>
{
public Task(Callable<T> fn)
{
super(fn);
}
```
we can avoid the run method in this case completely
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]