|
7 | 7 |
|
8 | 8 | import com.intellij.openapi.application.ApplicationManager; |
9 | 9 | import com.intellij.openapi.diagnostic.Logger; |
10 | | -import com.intellij.openapi.progress.ProcessCanceledException; |
11 | 10 | import com.intellij.openapi.progress.ProgressIndicator; |
12 | 11 | import com.intellij.openapi.progress.ProgressManager; |
13 | 12 | import com.intellij.openapi.project.Project; |
|
38 | 37 | import org.apache.commons.lang3.StringUtils; |
39 | 38 | import org.jdesktop.swingx.JXHyperlink; |
40 | 39 | import org.jetbrains.annotations.Nullable; |
41 | | -import reactor.core.Disposable; |
42 | 40 | import reactor.core.publisher.Flux; |
43 | 41 | import reactor.core.publisher.Mono; |
44 | 42 | import reactor.core.scheduler.Schedulers; |
@@ -197,27 +195,9 @@ private AuthMethodDetails doServicePrincipalLogin() { |
197 | 195 | } |
198 | 196 |
|
199 | 197 | private static AuthMethodDetails checkCanceled(ProgressIndicator indicator, Mono<? extends AuthMethodDetails> mono) { |
200 | | - CompletableFuture<? extends AuthMethodDetails> future = mono.toFuture(); |
201 | | - Disposable disposable = Flux.interval(Duration.ofSeconds(1)).map(ts -> { |
202 | | - if (indicator != null) { |
203 | | - indicator.checkCanceled(); |
204 | | - } |
205 | | - return 1; |
206 | | - }).onErrorResume(e -> { |
207 | | - if (e instanceof ProcessCanceledException) { |
208 | | - future.cancel(true); |
209 | | - } |
210 | | - return Mono.empty(); |
211 | | - }).subscribeOn(Schedulers.boundedElastic()).subscribe(); |
212 | | - try { |
213 | | - return future.get(); |
214 | | - } catch (CancellationException e) { |
215 | | - return null; |
216 | | - } catch (Throwable e) { |
217 | | - throw new AzureToolkitRuntimeException("Cannot login due to error: " + e.getMessage(), e); |
218 | | - } finally { |
219 | | - disposable.dispose(); |
220 | | - } |
| 198 | + final Mono<AuthMethodDetails> cancelMono = Flux.interval(Duration.ofSeconds(1)).map(ignore -> indicator.isCanceled()) |
| 199 | + .any(cancel -> cancel).map(ignore -> new AuthMethodDetails()).subscribeOn(Schedulers.boundedElastic()); |
| 200 | + return Mono.firstWithSignal(cancelMono, mono.subscribeOn(Schedulers.boundedElastic())).block(); |
221 | 201 | } |
222 | 202 |
|
223 | 203 | @Override |
@@ -328,7 +308,7 @@ private synchronized AuthMethodDetails doDeviceLogin() { |
328 | 308 | ErrorWindow.show(project, ex.getMessage(), SIGN_IN_ERROR); |
329 | 309 | } |
330 | 310 | } |
331 | | - return null; |
| 311 | + return new AuthMethodDetails(); |
332 | 312 | } |
333 | 313 |
|
334 | 314 | private static AuthMethodDetails fromAccountEntity(AccountEntity entity) { |
|
0 commit comments