Popularity
1.3
Declining
Activity
1.3
Growing
15
3
1

Programming language: Kotlin
License: MIT License
Tags: Coroutines    
Latest version: v1.2.35

coroutinesmanager alternatives and similar libraries

Based on the "Coroutines" category.
Alternatively, view coroutinesmanager alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of coroutinesmanager or a related project?

Add another 'Coroutines' Library

README

Kotlin Coroutines Manager

Download Kotlin 1.4.10 Codacy Badge Awesome Kotlin Badge

Some helpful kotlin coroutines manager classes and extensions. You can turn every function into coroutine function with powerful try-catch-finally blocks

class MainActivity(
    private val coroutinesManager: ICoroutinesManager = CoroutinesManager()
) : AppCompatActivity(), ICoroutinesManager by coroutinesManager {

    // Async worker may be into your DI as uses case
    private val asyncWorker = AsyncWorker()

    fun tryCatch() = launchOnUITryCatch(tryBlock = {
        // do some work on ui
        val result = asyncWorker.awaitSomeHardWorkToComplete()
    }, catchBlock = {
        // catch every exception
    })

    // Sinse version 1.2.0
    private fun launchUiAsyncAction() = launchOnUITryCatchFinallyAsyncAwait(
        tryBlock = {

            delay(3000L)
            if (Random.nextInt(1, 20) % 2 == 0)
                throw RuntimeException("THERE IS AN ERROR")

            println("----> launchUiAsyncAction 'TRY' BLOCK COMPLETE")
        }, catchBlock = {
            println("----> ASYNC 'CATCH' BLOCK ${Thread.currentThread().name}")
            titleTextView.text = it.message
        }, finallyBlock = {

        })

    fun tryFinally() = launchOnUITryFinally(tryBlock = {
        // try some action that maybe produce an exceptions
    }, finallyBlock = {
        // do work when coroutine is done
    })

    fun tryCatchFinally() = launchOnUITryCatchFinally(tryBlock = {
        val resultForAwait = asyncWorker.createDeferrerForAwait()
        val finalResult: String = resultForAwait.await()    
    }, catchBlock = {
        // error here
    }, finallyBlock = {
        // final action here
    })

    fun doOnUiOnly() = launchOnUI { 
        // do some work on UI thread
    }   
}

class AsyncWorker(
    // You can store this class as global singleton into your DI framework
    private val asyncTaskManager: IAsyncTasksManager = AsyncTasksManager()
) : IAsyncTasksManager by asyncTaskManager {

    suspend fun awaitSomeHardWorkToComplete() = doTryCatchAsyncAwait(
        tryBlock = {
            println("----> ASYNC 'TRY' BLOCK")

            delay(3000L)
            if (Random.nextInt(1, 20) % 2 == 0)
                throw RuntimeException("THERE IS AN ERROR")

            "OPERATION COMPLETE"
        },
        catchBlock = {
            println("----> ASYNC 'CATCH' BLOCK")
            throw it
        }
    )

    suspend fun <T> createDeferrerForAwait(): Deferred<T> = doAsync {
        "SOME WORK HERE"
    }
}

You can use ICoroutinesManager as base implementation for your presenter in MVP or MVI architecture. Use IAsyncTasksManager as base implementation for hard work or async operations as UseCases and another tasks.

Gradle:

implementation 'com.rasalexman.coroutinesmanager:coroutinesmanager:x.y.z'

License

MIT License

Copyright (c) 2019 Alexandr Minkin ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


*Note that all licence references and agreements mentioned in the coroutinesmanager README section above are relevant to that project's source code only.