Commit 86fdbd6f by jaewan Committed by Ian Baker

Only unsubscribe from specified parentId

PiperOrigin-RevId: 422331961
parent cd56084b
...@@ -183,9 +183,7 @@ import java.util.concurrent.Future; ...@@ -183,9 +183,7 @@ import java.util.concurrent.Future;
() -> { () -> {
@Nullable LibraryResult<Void> result = tryGetFutureResult(future); @Nullable LibraryResult<Void> result = tryGetFutureResult(future);
if (result == null || result.resultCode != RESULT_SUCCESS) { if (result == null || result.resultCode != RESULT_SUCCESS) {
synchronized (lock) { removeSubscription(controller, parentId);
subscriptions.remove(checkStateNotNull(browser.getControllerCb()));
}
} }
}, },
MoreExecutors.directExecutor()); MoreExecutors.directExecutor());
...@@ -203,11 +201,7 @@ import java.util.concurrent.Future; ...@@ -203,11 +201,7 @@ import java.util.concurrent.Future;
"onUnsubscribe must return non-null future"); "onUnsubscribe must return non-null future");
future.addListener( future.addListener(
() -> { () -> removeSubscription(checkStateNotNull(browser.getControllerCb()), parentId),
synchronized (lock) {
subscriptions.remove(checkStateNotNull(browser.getControllerCb()));
}
},
MoreExecutors.directExecutor()); MoreExecutors.directExecutor());
return future; return future;
...@@ -307,4 +301,16 @@ import java.util.concurrent.Future; ...@@ -307,4 +301,16 @@ import java.util.concurrent.Future;
} }
} }
} }
private void removeSubscription(ControllerCb controllerCb, String parentId) {
synchronized (lock) {
@Nullable Set<String> subscription = subscriptions.get(controllerCb);
if (subscription != null) {
subscription.remove(parentId);
if (subscription.isEmpty()) {
subscriptions.remove(controllerCb);
}
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment