summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android/util
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-09-14 19:46:49 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-09-15 12:30:15 +0200
commitbab70ab51ecc02c2e8afd1843cdd4d90ae9cc257 (patch)
treebd7117473f42dc6211d9aad4c78cbdddeb851b3e /ui/src/main/java/com/wireguard/android/util
parent2fc0bb1a03f624e297d2afdeb95231cf906afc21 (diff)
coroutines: convert the rest
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/util')
-rw-r--r--ui/src/main/java/com/wireguard/android/util/AsyncWorker.kt43
-rw-r--r--ui/src/main/java/com/wireguard/android/util/ExceptionLoggers.kt27
2 files changed, 0 insertions, 70 deletions
diff --git a/ui/src/main/java/com/wireguard/android/util/AsyncWorker.kt b/ui/src/main/java/com/wireguard/android/util/AsyncWorker.kt
deleted file mode 100644
index a6e5d4be..00000000
--- a/ui/src/main/java/com/wireguard/android/util/AsyncWorker.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright © 2017-2020 WireGuard LLC. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0
- */
-package com.wireguard.android.util
-
-import android.os.Handler
-import java9.util.concurrent.CompletableFuture
-import java9.util.concurrent.CompletionStage
-import java.util.concurrent.Executor
-
-/**
- * Helper class for running asynchronous tasks and ensuring they are completed on the main thread.
- */
-
-class AsyncWorker(private val executor: Executor, private val handler: Handler) {
-
- fun runAsync(run: () -> Unit): CompletionStage<Void> {
- val future = CompletableFuture<Void>()
- executor.execute {
- try {
- run()
- handler.post { future.complete(null) }
- } catch (t: Throwable) {
- handler.post { future.completeExceptionally(t) }
- }
- }
- return future
- }
-
- fun <T> supplyAsync(get: () -> T?): CompletionStage<T> {
- val future = CompletableFuture<T>()
- executor.execute {
- try {
- val result = get()
- handler.post { future.complete(result) }
- } catch (t: Throwable) {
- handler.post { future.completeExceptionally(t) }
- }
- }
- return future
- }
-}
diff --git a/ui/src/main/java/com/wireguard/android/util/ExceptionLoggers.kt b/ui/src/main/java/com/wireguard/android/util/ExceptionLoggers.kt
deleted file mode 100644
index 4470134c..00000000
--- a/ui/src/main/java/com/wireguard/android/util/ExceptionLoggers.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0
- */
-package com.wireguard.android.util
-
-import android.util.Log
-import java9.util.function.BiConsumer
-
-/**
- * Helpers for logging exceptions from asynchronous tasks. These can be passed to
- * `CompletionStage.whenComplete()` at the end of an asynchronous future chain.
- */
-enum class ExceptionLoggers(private val priority: Int) : BiConsumer<Any?, Throwable?> {
- D(Log.DEBUG), E(Log.ERROR);
-
- override fun accept(result: Any?, throwable: Throwable?) {
- if (throwable != null)
- Log.println(Log.ERROR, TAG, Log.getStackTraceString(throwable))
- else if (priority <= Log.DEBUG)
- Log.println(priority, TAG, "Future completed successfully")
- }
-
- companion object {
- private const val TAG = "WireGuard/ExceptionLoggers"
- }
-}