|
19 | 19 | package org.neo4j.driver.internal.cursor;
|
20 | 20 |
|
21 | 21 | import java.util.List;
|
| 22 | +import java.util.Optional; |
22 | 23 | import java.util.concurrent.CompletableFuture;
|
23 | 24 | import java.util.concurrent.CompletionStage;
|
24 | 25 | import java.util.function.Consumer;
|
|
33 | 34 |
|
34 | 35 | public class AsyncResultCursorImpl implements AsyncResultCursor
|
35 | 36 | {
|
| 37 | + private final Throwable runError; |
36 | 38 | private final RunResponseHandler runHandler;
|
37 | 39 | private final PullAllResponseHandler pullAllHandler;
|
38 | 40 |
|
39 |
| - public AsyncResultCursorImpl(RunResponseHandler runHandler, PullAllResponseHandler pullAllHandler ) |
| 41 | + public AsyncResultCursorImpl( Throwable runError, RunResponseHandler runHandler, PullAllResponseHandler pullAllHandler ) |
40 | 42 | {
|
| 43 | + this.runError = runError; |
41 | 44 | this.runHandler = runHandler;
|
42 | 45 | this.pullAllHandler = pullAllHandler;
|
43 | 46 | }
|
@@ -113,13 +116,38 @@ public <T> CompletionStage<List<T>> listAsync( Function<Record,T> mapFunction )
|
113 | 116 | @Override
|
114 | 117 | public CompletionStage<Throwable> discardAllFailureAsync()
|
115 | 118 | {
|
116 |
| - return consumeAsync().handle( ( summary, error ) -> error ); |
| 119 | + return consumeAsync().handle( |
| 120 | + ( summary, consumeError ) -> |
| 121 | + { |
| 122 | + if ( runError != null ) |
| 123 | + { |
| 124 | + if ( consumeError != null && runError != consumeError ) |
| 125 | + { |
| 126 | + runError.addSuppressed( consumeError ); |
| 127 | + } |
| 128 | + return runError; |
| 129 | + } |
| 130 | + return consumeError; |
| 131 | + } ); |
117 | 132 | }
|
118 | 133 |
|
119 | 134 | @Override
|
120 | 135 | public CompletionStage<Throwable> pullAllFailureAsync()
|
121 | 136 | {
|
122 |
| - return pullAllHandler.pullAllFailureAsync(); |
| 137 | + return pullAllHandler.pullAllFailureAsync().handle( |
| 138 | + ( ignored, pullAllError ) -> |
| 139 | + { |
| 140 | + if ( runError != null ) |
| 141 | + { |
| 142 | + if ( pullAllError != null && runError != pullAllError ) |
| 143 | + { |
| 144 | + runError.addSuppressed( pullAllError ); |
| 145 | + } |
| 146 | + return runError; |
| 147 | + } |
| 148 | + return pullAllError; |
| 149 | + } |
| 150 | + ); |
123 | 151 | }
|
124 | 152 |
|
125 | 153 | private void internalForEachAsync( Consumer<Record> action, CompletableFuture<Void> resultFuture )
|
@@ -154,4 +182,10 @@ else if ( record != null )
|
154 | 182 | }
|
155 | 183 | } );
|
156 | 184 | }
|
| 185 | + |
| 186 | + @Override |
| 187 | + public Optional<Throwable> runError() |
| 188 | + { |
| 189 | + return Optional.ofNullable( runError ); |
| 190 | + } |
157 | 191 | }
|
0 commit comments