mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FIX] Try fix Downloader cancel()
This commit is contained in:
parent
9f44673809
commit
711413c52f
1 changed files with 10 additions and 0 deletions
|
@ -189,6 +189,7 @@ public static class ProgressTrackingBodyHandler<T> implements HttpResponse.BodyH
|
|||
private final HttpResponse.BodyHandler<T> delegate;
|
||||
private final DownloadCallback callback;
|
||||
private ProgressTrackingBodySubscriber subscriber;
|
||||
private boolean isCanceled = false;
|
||||
|
||||
public ProgressTrackingBodyHandler(HttpResponse.BodyHandler<T> delegate, DownloadCallback callback) {
|
||||
this.delegate = delegate;
|
||||
|
@ -198,10 +199,14 @@ public ProgressTrackingBodyHandler(HttpResponse.BodyHandler<T> delegate, Downloa
|
|||
@Override
|
||||
public HttpResponse.BodySubscriber<T> apply(HttpResponse.ResponseInfo responseInfo) {
|
||||
subscriber = new ProgressTrackingBodySubscriber(delegate.apply(responseInfo));
|
||||
if (isCanceled) {
|
||||
subscriber.cancel();
|
||||
}
|
||||
return subscriber;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
isCanceled = true;
|
||||
if (subscriber != null) {
|
||||
subscriber.cancel();
|
||||
}
|
||||
|
@ -210,6 +215,7 @@ public void cancel() {
|
|||
private class ProgressTrackingBodySubscriber implements HttpResponse.BodySubscriber<T> {
|
||||
private final HttpResponse.BodySubscriber<T> delegate;
|
||||
private Flow.Subscription subscription;
|
||||
private boolean isCanceled = false;
|
||||
|
||||
public ProgressTrackingBodySubscriber(HttpResponse.BodySubscriber<T> delegate) {
|
||||
this.delegate = delegate;
|
||||
|
@ -223,6 +229,9 @@ public CompletionStage<T> getBody() {
|
|||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription) {
|
||||
this.subscription = subscription;
|
||||
if (isCanceled) {
|
||||
subscription.cancel();
|
||||
}
|
||||
delegate.onSubscribe(subscription);
|
||||
}
|
||||
|
||||
|
@ -247,6 +256,7 @@ public void onComplete() {
|
|||
}
|
||||
|
||||
public void cancel() {
|
||||
isCanceled = true;
|
||||
if (subscription != null) {
|
||||
subscription.cancel();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue