aboutsummaryrefslogtreecommitdiffstats
path: root/coroutine-utils/src/main/kotlin/dev/msfjarvis
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-07-15 00:53:48 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-07-15 01:13:47 +0530
commit549ee790d3e52bc62565ddf92e6a556e98b5195e (patch)
treed5758e5eb80093704e683c8da926838e18182588 /coroutine-utils/src/main/kotlin/dev/msfjarvis
parent010c6e227c9cc27f4d01bc912311f977b2aeb3a7 (diff)
downloadHardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.tar.gz
HardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.zip
all: re-do package structure yet again
Diffstat (limited to 'coroutine-utils/src/main/kotlin/dev/msfjarvis')
-rw-r--r--coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt22
-rw-r--r--coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt49
2 files changed, 0 insertions, 71 deletions
diff --git a/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt b/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt
deleted file mode 100644
index a7c4530d..00000000
--- a/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package dev.msfjarvis.aps.util.coroutines
-
-import javax.inject.Inject
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.Dispatchers
-
-/** Interface to allow abstracting individual [CoroutineDispatcher]s out of class dependencies. */
-public interface DispatcherProvider {
-
- public fun main(): CoroutineDispatcher = Dispatchers.Main
- public fun default(): CoroutineDispatcher = Dispatchers.Default
- public fun io(): CoroutineDispatcher = Dispatchers.IO
- public fun unconfined(): CoroutineDispatcher = Dispatchers.Unconfined
-}
-
-/** Concrete type for [DispatcherProvider] with all the defaults from the class. */
-public class DefaultDispatcherProvider @Inject constructor() : DispatcherProvider
diff --git a/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt b/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt
deleted file mode 100644
index 4ba68159..00000000
--- a/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-@file:OptIn(ExperimentalContracts::class)
-@file:Suppress("RedundantSuspendModifier")
-
-package dev.msfjarvis.aps.util.coroutines
-
-import com.github.michaelbull.result.Err
-import com.github.michaelbull.result.Ok
-import com.github.michaelbull.result.Result
-import kotlin.contracts.ExperimentalContracts
-import kotlin.contracts.InvocationKind
-import kotlin.contracts.contract
-import kotlinx.coroutines.CancellationException
-
-/**
- * Calls the specified function [block] and returns its encapsulated result if invocation was
- * successful, catching any [Throwable] except [CancellationException] that was thrown from the
- * [block] function execution and encapsulating it as a failure.
- */
-@OptIn(ExperimentalContracts::class)
-public suspend inline fun <V> runSuspendCatching(block: () -> V): Result<V, Throwable> {
- contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
-
- return try {
- Ok(block())
- } catch (e: Throwable) {
- if (e is CancellationException) throw e
- Err(e)
- }
-}
-
-/**
- * Calls the specified function [block] with [this] value as its receiver and returns its
- * encapsulated result if invocation was successful, catching any [Throwable] except
- * [CancellationException] that was thrown from the [block] function execution and encapsulating it
- * as a failure.
- */
-@OptIn(ExperimentalContracts::class)
-public suspend inline infix fun <T, V> T.runSuspendCatching(
- block: T.() -> V
-): Result<V, Throwable> {
- contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
-
- return try {
- Ok(block())
- } catch (e: Throwable) {
- if (e is CancellationException) throw e
- Err(e)
- }
-}