From 2315a699fb21fe9e49be7844980dde832c420508 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sat, 6 Jan 2018 05:09:53 -0600 Subject: TunnelManager: Enumerate running tunnels only once Signed-off-by: Samuel Holland --- .../main/java/com/wireguard/android/model/TunnelManager.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java index eaf8c0d6..3682cfcd 100644 --- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -87,13 +87,11 @@ public final class TunnelManager { public void onCreate() { Log.v(TAG, "onCreate triggered"); - configStore.enumerate() - .thenApply(names -> StreamSupport.stream(names) - .map(this::add) - .map(Tunnel::getStateAsync) - .toArray(CompletableFuture[]::new)) - .thenCompose(CompletableFuture::allOf) - .whenComplete(ExceptionLoggers.E); + configStore.enumerate().thenAcceptBoth(backend.enumerate(), (names, running) -> { + for (final String name : names) { + add(name, null, running.contains(name) ? State.UP : State.DOWN); + } + }).whenComplete(ExceptionLoggers.D); } public CompletionStage restoreState() { -- cgit v1.2.3