Kovenant. Promises for Kotlin.

Overview

CircleCI branch Maven Central DUB develop: Develop dependency status master: Master dependency status

Kovenant

Promises for Kotlin.

The easy asynchronous library for Kotlin. With extensions for Android, RxJava, JavaFX and much more.

task { "world" } and task { "Hello" } success {
    println("${it.second} ${it.first}!")
}

Please refer to the Kovenant site for API usage and more.

Getting started

Build against Kotlin: 1.0.3. Source and target compatibility is 1.6

Gradle

dependencies {
    compile 'nl.komponents.kovenant:kovenant:3.3.0'
}

Maven

<dependency>
	<groupId>nl.komponents.kovenant</groupId>
	<artifactId>kovenant</artifactId>
	<version>3.3.0</version>
</dependency>

Android Demo app

Checkout the Android Demo App on Github.

Artifacts

Kovenant has been structured in sub projects so you can cherry pick what you need.

artifact description
kovenant Container artifact that consists of kovenant-core, kovenant-combine, kovenant-jvm and kovenant-functional
kovenant-core The core of kovenant. Provides the API and default implementations
kovenant-combine Adds combine functionality that keep everything strongly typed
kovenant-jvm Support for converting between Executors and Dispatchers
kovenant-ui Support for UI frameworks that need UI work to operate on a specific process
kovenant-rx Add promise support to Rx
kovenant-android Extensions for Android specific needs
kovenant-jfx Extensions for JavaFX specific needs
kovenant-disruptor LMAX Disruptor work queues
kovenant-progress Progress configuration helper
kovenant-functional Functional Programming idiomatic additions

Issues

Issues are tracked in Youtrack

Release notes

See Changelog for release notes

Slack

Join the #kovenant channel on Kotlin Slack.

More Kotlin libraries

Check out Awesome Kotlin

Comments
  • extension need one for ">

    extension "then" on promise need one for

    Is there a reason we can't have one for Throwable instead of just Exception? For example, Vert.x always types their exceptions callback handlers with Throwable, so would have to wrap every exception otherwise.

    question 
    opened by apatrida 3
  • Move the code into a module, so we can do pull requests for additional modules

    Move the code into a module, so we can do pull requests for additional modules

    If you move the main code down into a submodule, we can do pull request for things like a dispatcher based on disruptor. And still keep all the code together.

    enhancement 
    opened by apatrida 2
  • Tuple1..22 and the like create unnecessary additional classes

    Tuple1..22 and the like create unnecessary additional classes

    One strength Kotlin really has going for it now is a low number of class/method points which is important in environments like Android where you have a set limit. The cases where you have combine could easily be vararg instead of fixed parameters, with lists of things instead of set individual first, second, third, fourth, etc.

    Plus your code becomes littered with variations of all these classes that must be kept in sync.

    Simplify, it is really a list of things to combine, so treat it as such instead of hard set parameters and fields. Otherwise your library will go unused in environments such as Android (which may not be important to you, but it is a key driver helping Kotlin thrive right now, so let's all help that continue)

    enhancement wontfix 
    opened by apatrida 2
  • Question about chaining with `all()`

    Question about chaining with `all()`

    Hi all, I have using kovenant framework with some questions I would like to fetch a table of contents and fetch the content of the table simultaneously, then output a mixed list with table content title and content itself.

    But I faced the problems for coding with kovenant.

    For example, I have MySubject and MySubjectDetails class.

    class MySubject {
        var id: String = ""
        var name: String = ""
    }
    
    class MySubjectDetails {
        var id: String = ""
        var name: String = ""
        var data: List<String> = ArrayList()
    }
    

    and APICalls class (part of code is pseudo code),

    object APICalls {
        fun getSubjects(): Promise<List<MySubject>, Exception> {
            val deferred = deferred<List<MySubject>, Exception>()
            // ... API calls ...
            return deferred.promise
        }
    
        fun getSubjectById(id: String): Promise<MySubjectDetail, Exception> {
            val deferred = deferred<MySubjectDetail, Exception>()
            // ... API calls ...
            return deferred.promise
        }
    }
    

    I may fetch the data like is:

    APICalls.getSubjects().then { subjects ->
        val promises = subjects.map {
            APICalls.getSubjectById(it.id)
        }
        all(promises)
    }.then { promise: Promise<List<MySubjectDetail>, Exception> ->
        //       ^~~~~~ What's this?
    }
    

    I will get a result with Promise<List<MySubjectDetail>, Exception> type then I can't continue the code. I expected it will be a combined list (List<MySubjectDetail>) but it comes up a Promise<List<MySubjectDetail>, Exception> object thats confused me.

    How can I do or fix the code? Thanks.

    opened by j796160836 0
  • Using deferred promise in middle of chain..

    Using deferred promise in middle of chain..

    How can you use a deferred promise int he middle of a chain? The only way I can see doing it right now is.

    task { setup1() } then { setup2() } then { deffered() } then { promise -> val result = promise ?: throw(error) if result.isError() { throw(error) } else { it.get() } } fail { }

    Unwrap doesn't seem to exist like is suggested.

    opened by scottandrew 0
  • unwrapping the return Promise of then

    unwrapping the return Promise of then

    Hey there,

    kovenant is a great library. I love to use it. However, there is a small feature I like I wish you can provide is "unwrap the return Promise of then"

    For example, I have two methods

    fun method1() : Promise<String, Exception>{}
    fun method2() : Promise<String, Exception>{}
    
    // current
    val p: Promise<Promise<String, Exception>, Exception> = method1().then{ method2() }
    // can it just be 
    val p: Promise<String, Exception> = method1().then{ method2() }
    

    Now, I added these extensions in my project to achieve it, but I don't know whether it is a good way to do it and it is a little unclear to use thenFlat instead of then.

    infix fun <V, R> Promise<V, Exception>.thenFlat(bind: (V) -> Promise<R, Exception>): Promise<R, Exception> {
        val deferred = deferred<R, Exception>(context)
        success {
            try {
                bind(it).success(deferred::resolve).fail(deferred::reject)
            } catch (e: Exception) {
                deferred.reject(ApiError(e))
            }
        }.fail(deferred::reject)
        
        return deferred.promise
    }
    
    // so it can be
    val p: Promise<String, Exception> = method1().thenFlat{ method2() }
    
    opened by weironghuang31 1
  • Blocking call in task

    Blocking call in task

    Call from this function

    private fun loginWithFacebookAccessToken(accessToken: AccessToken) {
            promiseOnUi {
                mvpView?.showLoggingProgress()
            } then {
                loginManager.loginWithFacebook(accessToken).get() //Call from this side
    		} alwaysUi {
                mvpView?.hideLoggingProgress()
            } successUi {
                mvpView?.navigateToMainScreen()
            } failUi { error ->
    			mvpView?.showMessage(error.localizedMessage)
            }
        }
    

    To this function

        fun loginWithFacebook(fbAccessToken: AccessToken): Promise<Unit, Exception> {
    		ti { "KOVENANT In Function" }
            return task {
    			ti { "KOVENANT In task" }
            } then {
    			ti { "KOVENANT In then" }
            }
        }
    

    Hi I have a problem in the last function, my call is block in the task { .. } My application is deploy on a SAMSUNG S4 MINI API 19 Version 4.4.2 And the logcat only show : "KOVENANT In Function"

    opened by alexandre-roulin 2
  • Question about chaining long processes.

    Question about chaining long processes.

    I was trying to chain long processes but it wasn't working. All the long processes were returning deferredPromises.

    I thought this was working not too long ago but the update to AndroidStudio 3.1 seems to have broken something. I was seeing pending promises fall through. It was something like.

    renewToken() then { getData() } successUI { broadcast update }

    The broad cast update was happening while getData was pending. I have worked around by doing:

    all(renewToken(), getData()) successUI { }

    It appears though that the then is not working at all. Its just falling through. I had another case where this was falling through when trying to log out then show login screen when logout was complete.

    opened by scottandrew 1
Releases(v3.3.0)
Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

Gérard Paligot 98 Dec 15, 2022
Android + Kotlin + Github Actions + ktlint + Detekt + Gradle Kotlin DSL + buildSrc = ❤️

kotlin-android-template ?? A simple Github template that lets you create an Android/Kotlin project and be up and running in a few seconds. This templa

Nicola Corti 1.5k Jan 3, 2023
LifecycleMvp 1.2 0.0 Kotlin is MVP architecture implementation with Android Architecture Components and Kotlin language features

MinSDK 14+ Download Gradle Add to project level build.gradle allprojects { repositories { ... maven { url 'https://jitpack.io' }

Robert 20 Nov 9, 2021
Opinionated Redux-like implementation backed by Kotlin Coroutines and Kotlin Multiplatform Mobile

CoRed CoRed is Redux-like implementation that maintains the benefits of Redux's core idea without the boilerplate. No more action types, action creato

Kittinun Vantasin 28 Dec 10, 2022
👋 A common toolkit (utils) ⚒️ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! 🍭

Toolkit [ ?? Work in progress ⛏ ?? ??️ ?? ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

凛 35 Jul 23, 2022
An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile.

An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile. 项目架构主要分为原生系统层、Android/iOS业务SDK层、KMM SDK层、KMM业务逻辑SDK层、iOS sdkfra

libill 4 Nov 20, 2022
Provides Kotlin libs and some features for building Kotlin plugins

Kotlin Plugin Provides Kotlin libs and some features for building awesome Kotlin plugins. Can be used instead of CreeperFace's KotlinLib (don't use to

null 3 Dec 24, 2021
Notes-App-Kotlin - Notes App Built Using Kotlin

Notes-App-Kotlin Splash Screen Home Page Adding New Notes Filter Feature Search

Priyanka 4 Oct 2, 2022
Kotlin-client-dsl - A kotlin-based dsl project for a (Client) -> (Plugin) styled program

kotlin-client-dsl a kotlin-based dsl project for a (Client) -> (Plugin) styled p

jackson 3 Dec 10, 2022
A Kotlin Native program to show the time since a date, using Kotlin LibUI

TimeSince A Kotlin Native program to show the time since a date, using Kotlin LibUI Report Bug . Request Feature About The Project TimeSince is a Kotl

Russell Banks 2 May 6, 2022
RoomJetpackCompose is an app written in Kotlin and shows a simple solution to perform CRUD operations in the Room database using Kotlin Flow in clean architecture.

RoomJetpackCompose is an app written in Kotlin and shows a simple solution to perform CRUD operations in the Room database using Kotlin Flow in clean architecture.

Alex 27 Jan 1, 2023
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Practical Kotlin Multiplatform on the Web 본 저장소는 코틀린 멀티플랫폼 기반 웹 프로그래밍 워크숍(강좌)을 위해 작성된 템플릿 프로젝트가 있는 곳입니다. 워크숍 과정에서 코틀린 멀티플랫폼을 기반으로 프론트엔드(front-end)는 Ko

SpringRunner 14 Nov 5, 2022
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Building a Full Stack Web App with Kotlin Multiplatform 본 저장소는 INFCON 2022에서 코틀린 멀티플랫폼 기반 웹 프로그래밍 핸즈온랩을 위해 작성된 템플릿 프로젝트가 있는 곳입니다. 핸즈온 과정에서 코틀린 멀티플랫폼을

Arawn Park 19 Sep 8, 2022
Kotlin library for Android

KAndroid Kotlin library for Android providing useful extensions to eliminate boilerplate code in Android SDK and focus on productivity. Download Downl

Paweł Gajda 890 Nov 13, 2022
Type-safe time calculations in Kotlin, powered by generics.

Time This library is made for you if you have ever written something like this: val duration = 10 * 1000 to represent a duration of 10 seconds(in mill

Kizito Nwose 958 Dec 10, 2022
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT ??️ NotyKT is the complete Kotlin-stack note taking ??️ application ?? built to demonstrate a use of Kotlin programming language in server-side

Shreyas Patil 1.4k Jan 4, 2023
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

MaterialDrawerKt Create navigation drawers in your Activities and Fragments without having to write any XML, in pure Kotlin code, with access to all t

Márton Braun 517 Nov 19, 2022
Kotlin-based modern RecyclerView rendering weapon

Read this in other languages: 中文, English, Changelog Yasha Item introduction: Kotlin-based modern RecyclerView rendering weapon Item Features: No Adap

Season 514 Dec 21, 2022
{ } Declarative Kotlin DSL for choreographing Android transitions

Transition X Kotlin DSL for choreographing Android Transitions TransitionManager makes it easy to animate simple changes to layout without needing to

Arunkumar 520 Dec 16, 2022