From 60d5146434e30e0fcbd9126580359fdeb910d109 Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Mon, 25 Jan 2016 20:26:12 +0100 Subject: [PATCH 1/9] updated to (non-public) kotlin rc version --- build.gradle | 10 ++++++++-- projects/core/src/test/kotlin/tests/api/get.kt | 4 ++-- projects/progress/progress.gradle | 8 +++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index b633628..9e07c74 100644 --- a/build.gradle +++ b/build.gradle @@ -20,12 +20,15 @@ */ buildscript { - ext.kotlinVersion = '1.0.0-beta-4589' + ext.kotlinVersion = '1.0.0-rc-1007' ext.extraConfVersion = '2.2.+' repositories { mavenCentral() jcenter() + maven { + url "http://dl.bintray.com/kotlin/kotlin-eap" + } maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } @@ -38,7 +41,7 @@ buildscript { allprojects { ext { - appVersion = '3.0.0-beta.4' + appVersion = '3.0.0-rc.01007' appGroup = 'nl.komponents.kovenant' @@ -57,6 +60,9 @@ subprojects { maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } + maven { + url "http://dl.bintray.com/kotlin/kotlin-eap" + } maven { url 'https://oss.sonatype.org/content/groups/staging' } diff --git a/projects/core/src/test/kotlin/tests/api/get.kt b/projects/core/src/test/kotlin/tests/api/get.kt index 11a38d6..8dd0fa5 100644 --- a/projects/core/src/test/kotlin/tests/api/get.kt +++ b/projects/core/src/test/kotlin/tests/api/get.kt @@ -60,7 +60,7 @@ class GetTest { @Test fun failResultException() { val promise = Promise.ofFail(Exception("bummer")) - var thrown = false + var thrown: Boolean try { promise.get() fail("Should not be reachable") @@ -74,7 +74,7 @@ class GetTest { @Test fun failResultValue() { val promise = Promise.ofFail("bummer") - var thrown = false + var thrown: Boolean try { promise.get() fail("Should not be reachable") diff --git a/projects/progress/progress.gradle b/projects/progress/progress.gradle index 536f26a..b02c472 100644 --- a/projects/progress/progress.gradle +++ b/projects/progress/progress.gradle @@ -22,7 +22,13 @@ project.description = "Progress tracking Kovenant extensions" +repositories { + maven { + url "http://dl.bintray.com/mplatvoet/komponents" + } +} + dependencies { compile project(':kovenant-core') - compile 'nl.komponents.progress:progress-core:1.0.0-beta.4' + compile 'nl.komponents.progress:progress-core:1.0.0-rc.01007' } \ No newline at end of file From 701a6c77e406ef680580747cd49c555d850dc520 Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Mon, 25 Jan 2016 20:31:43 +0100 Subject: [PATCH 2/9] added Lazy interface to lazyPromise, added bintray config --- build.gradle | 32 ++++++++++++++++++- .../core/src/main/kotlin/delegates-jvm.kt | 8 +---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 9e07c74..78cfd20 100644 --- a/build.gradle +++ b/build.gradle @@ -36,6 +36,7 @@ buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "com.netflix.nebula:gradle-extra-configurations-plugin:$extraConfVersion" + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5' } } @@ -49,6 +50,9 @@ allprojects { sonatypeUsr = project.hasProperty('sonatypeUsername') ? sonatypeUsername : '' sonatypePwd = project.hasProperty('sonatypePassword') ? sonatypePassword : '' + + bintrayUsr = project.hasProperty('bintrayUsername') ? bintrayUsername : '' + bintrayKey = project.hasProperty('bintrayApiKey') ? bintrayApiKey : '' } } @@ -75,6 +79,7 @@ subprojects { apply plugin: 'kotlin' apply plugin: 'maven' apply plugin: 'signing' + apply plugin: 'com.jfrog.bintray' compileJava { sourceCompatibility = "1.6" @@ -189,12 +194,33 @@ subprojects { } } + + bintray { + user = bintrayUsr + key = bintrayKey + pkg { + repo = 'komponents' + name = project.name + licenses = ['MIT'] + vcsUrl = 'scm:git:git@github.com:mplatvoet/kovenant.git' + + version { + name = appVersion + desc = 'n/a' + released = new Date() + } + publicDownloadNumbers = false + configurations = ['archives'] + } + publish = true + dryRun = false + } } gradle.taskGraph.whenReady { taskGraph -> def branchName = System.getenv('CIRCLE_BRANCH')?.trim() - if ('master'.equals(branchName) || taskGraph.hasTask(release)) { + if ('master'.equals(branchName) || taskGraph.hasTask(release) || taskGraph.hasTask(bintray)) { allprojects*.version = appVersion } else { allprojects*.version = "$appVersion-SNAPSHOT" @@ -212,6 +238,10 @@ task release() { dependsOn subprojects.uploadArchives } +task bintray { + dependsOn subprojects.bintrayUpload +} + task wrapper(type: Wrapper) { gradleVersion = '2.10' diff --git a/projects/core/src/main/kotlin/delegates-jvm.kt b/projects/core/src/main/kotlin/delegates-jvm.kt index 3264f5e..610ce74 100644 --- a/projects/core/src/main/kotlin/delegates-jvm.kt +++ b/projects/core/src/main/kotlin/delegates-jvm.kt @@ -26,7 +26,6 @@ import nl.komponents.kovenant.Kovenant import nl.komponents.kovenant.Promise import nl.komponents.kovenant.task import java.util.concurrent.atomic.AtomicInteger -import kotlin.reflect.KProperty public class LazyPromise( @@ -35,7 +34,7 @@ public class LazyPromise( //that would lead to this property using another Context //than the rest of the program. private val context: Context?, - initializer: () -> T) /*: Lazy>() */{ + initializer: () -> T) : Lazy> { private @Volatile var initializer: (() -> T)? @@ -46,13 +45,8 @@ public class LazyPromise( this.initializer = initializer } - @Suppress("UNUSED_PARAMETER") - operator fun getValue(thisRef: Any?, property: KProperty<*>): Promise = initOrGetPromise() -/* - //See if Lazy will be openend up again override val value: Promise get() = initOrGetPromise() override fun isInitialized(): Boolean = promise != null -*/ private fun initOrGetPromise(): Promise { // Busy/Spin lock, expecting async to return quickly From 7f21e37277091d22e4b827efd21da5146dbdc987 Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Thu, 4 Feb 2016 20:12:44 +0100 Subject: [PATCH 3/9] eap --- build.gradle | 4 ++-- projects/progress/progress.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 78cfd20..a726d15 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ */ buildscript { - ext.kotlinVersion = '1.0.0-rc-1007' + ext.kotlinVersion = '1.0.0-rc-1025' ext.extraConfVersion = '2.2.+' repositories { @@ -42,7 +42,7 @@ buildscript { allprojects { ext { - appVersion = '3.0.0-rc.01007' + appVersion = '3.0.0-rc.01025' appGroup = 'nl.komponents.kovenant' diff --git a/projects/progress/progress.gradle b/projects/progress/progress.gradle index b02c472..a3539be 100644 --- a/projects/progress/progress.gradle +++ b/projects/progress/progress.gradle @@ -30,5 +30,5 @@ repositories { dependencies { compile project(':kovenant-core') - compile 'nl.komponents.progress:progress-core:1.0.0-rc.01007' + compile 'nl.komponents.progress:progress-core:1.0.0-rc.01025' } \ No newline at end of file From 6fa83b1be4762398c154f4d52ba487be4dfaa146 Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Tue, 9 Feb 2016 20:36:35 +0100 Subject: [PATCH 4/9] update to kotlin rc 1050 --- README.md | 6 +++--- build.gradle | 4 ++-- docs/docs/index.md | 6 +++--- projects/progress/progress.gradle | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3313394..b75823e 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ task { "world" } and task { "Hello" } success { Please refer to the [Kovenant](http://kovenant.komponents.nl) site for API usage and more. ## Getting started -Build against Kotlin 1.0 rc: `1.0.0-rc-1036`. +Build against Kotlin 1.0 rc: `1.0.0-rc-1050`. Source and target compatibility is `1.6` ###Gradle ```groovy dependencies { - compile 'nl.komponents.kovenant:kovenant:3.0.0-rc.1036.1' + compile 'nl.komponents.kovenant:kovenant:3.0.0-rc.1050' } ``` @@ -32,7 +32,7 @@ dependencies { nl.komponents.kovenant kovenant - 3.0.0-rc.1036.1 + 3.0.0-rc.1050 ``` diff --git a/build.gradle b/build.gradle index f23c8b6..a25b686 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ */ buildscript { - ext.kotlinVersion = '1.0.0-rc-1036' + ext.kotlinVersion = '1.0.0-rc-1050' ext.extraConfVersion = '2.2.+' repositories { @@ -42,7 +42,7 @@ buildscript { allprojects { ext { - appVersion = '3.0.0-rc.1036.1' + appVersion = '3.0.0-rc.1050' appGroup = 'nl.komponents.kovenant' diff --git a/docs/docs/index.md b/docs/docs/index.md index 726e676..632ef5e 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -25,13 +25,13 @@ Developed with the following [goals](misc/goals.md) in mind. * **Dependency free**: when not counting kotlin std ## Getting started -Build against Kotlin 1.0 rc: `1.0.0-rc-1036`. +Build against Kotlin 1.0 rc: `1.0.0-rc-1050`. Source and target compatibility is `1.6` ###Gradle ```groovy dependencies { - compile 'nl.komponents.kovenant:kovenant:3.0.0-rc.1036.1' + compile 'nl.komponents.kovenant:kovenant:3.0.0-rc.1050' } ``` @@ -40,7 +40,7 @@ dependencies { nl.komponents.kovenant kovenant - 3.0.0-rc.1036.1 + 3.0.0-rc.1050 ``` diff --git a/projects/progress/progress.gradle b/projects/progress/progress.gradle index 4f18b9d..29b10f0 100644 --- a/projects/progress/progress.gradle +++ b/projects/progress/progress.gradle @@ -30,5 +30,5 @@ repositories { dependencies { compile project(':kovenant-core') - compile 'nl.komponents.progress:progress-core:1.0.0-rc.1036' + compile 'nl.komponents.progress:progress-core:1.0.0-rc.1050' } \ No newline at end of file From add95407e27789403448da1f9d8fc744183b9fac Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Sun, 28 Feb 2016 13:51:24 +0100 Subject: [PATCH 5/9] Typo in version fixed --- docs/docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index d31b754..56e65d9 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -3,7 +3,7 @@ Changelog of Kovenant. Complying to [Semantic Versioning](http://semver.org). Please refer to [roadmap](roadmap.md) for upcoming releases. -##v3.0.0 +##v3.1.0 **rx** From c259d4817e7602149732c0235b8d74ca6714a721 Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Sun, 28 Feb 2016 16:28:13 +0100 Subject: [PATCH 6/9] Added bintray support to the build file --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index a311d3e..74e766f 100644 --- a/build.gradle +++ b/build.gradle @@ -232,5 +232,9 @@ task release() { dependsOn subprojects.uploadArchives } +task bintray { + dependsOn subprojects.bintrayUpload +} + defaultTasks 'clean', 'jars' \ No newline at end of file From dac3c31e0ec49dd0f3164883b8b03102d92ddb38 Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Tue, 1 Mar 2016 16:48:32 +0100 Subject: [PATCH 7/9] Renamed root project (not affecting package naming) --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index ce88ad5..da683ef 100644 --- a/settings.gradle +++ b/settings.gradle @@ -19,7 +19,7 @@ * THE SOFTWARE. */ -rootProject.name = 'Kovenant-Root' +rootProject.name = 'Kovenant' include 'core' include 'combine' From 5f2f3432873a0fce8f95a736d407f33ea13599cd Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Thu, 10 Mar 2016 20:59:11 +0100 Subject: [PATCH 8/9] KOV-74, KOV-75, KOV-76: renamed and moved functions --- docs/docs/api/core_usage.md | 54 ++++++++++++++----- docs/docs/api/functional_usage.md | 26 --------- projects/core/src/main/kotlin/context-api.kt | 29 ++++++++++ projects/core/src/main/kotlin/promises-api.kt | 37 ++++++++++++- .../core/src/test/kotlin/examples/lazy.kt | 4 +- .../src/test/kotlin/tests/api/unwrap.kt | 8 +-- .../functional/src/main/kotlin/context.kt | 33 ++---------- projects/functional/src/main/kotlin/unwrap.kt | 33 ++---------- .../src/test/kotlin/examples/covariance.kt | 2 +- .../src/test/kotlin/examples/unwrap.kt | 2 +- 10 files changed, 119 insertions(+), 109 deletions(-) rename projects/{functional => core}/src/test/kotlin/tests/api/unwrap.kt (92%) diff --git a/docs/docs/api/core_usage.md b/docs/docs/api/core_usage.md index 91d8b02..a1fc7a3 100644 --- a/docs/docs/api/core_usage.md +++ b/docs/docs/api/core_usage.md @@ -184,14 +184,14 @@ failed. The work of `then` is executed by the `workerContext`. --- -##Then Use -`thenUse` operates similar to [`then`](#then) except that it takes the output from a previous `Promise` as its input +##ThenApply +`thenApply` operates similar to [`then`](#then) except that it takes the output from a previous `Promise` as its input as an extension function. The previous example would thus be: ```kt task { fib(20) -} thenUse { +} thenApply { "fib(20) = $this, and fib(21) = (${fib(21)})" } success { println(it) @@ -237,7 +237,7 @@ val expensiveResource by lazyPromise { fun main(args: Array) { println("start program") - expensiveResource thenUse { + expensiveResource thenApply { "Got [$value]" } success { println(it) @@ -332,20 +332,48 @@ any (*promises) success { msg -> ##Cancel Any `Promise` that implements `CancelablePromise` allows itself to be cancelled. By default the promises returned -from [`task`](#task), [`then`](#then) and [`thenUse`](#thenUse) are `CancelablePromise`s. +from [`task`](#task), [`then`](#then) and [`thenApply`](#thenApply) are `CancelablePromise`s. Cancelling a promises is quite similar to [`Deferred.reject`](#deferred) as it finishes the promises as failed. Thus the callbacks `fail` and `always` are still executed. Cancel does also try to prevent the promised work from ever being - scheduled. If the promised work is already running it gets [interrupted](https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#interrupt()) (when using default dispatchers). +scheduled. If the promised work is already running it gets [interrupted](https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#interrupt()) (when using default dispatchers). - --- +--- - ##Void - There are those times where just knowing that something has either failed or succeeded is enough information. So for - the ultimate "on a need to know basis" Kovenant provides three methods that hide the results: +##Void +There are those times where just knowing that something has either failed or succeeded is enough information. So for +the ultimate "on a need to know basis" Kovenant provides three methods that hide the results: + +* `toVoid()`, creates a `Promise` of an existing `Promise` +* `toSuccessVoid()`, creates a `Promise` of an existing `Promise` +* `toFailVoid()`, creates a `Promise` of an existing `Promise` + - * `toVoid()`, creates a `Promise` of an existing `Promise` - * `toSuccessVoid()`, creates a `Promise` of an existing `Promise` - * `toFailVoid()`, creates a `Promise` of an existing `Promise` +--- + +##unwrap +Unwraps any nested Promise. By default the returned `Promise` will operate on the same `Context` as its parent +`Promise`, no matter what the `Context` of the nested `Promise` is. If you want the resulting promise to operate on +a different `Context` you can provide one. + +Function tries to be as efficient as possible in cases where this or the nested `Promise` is already resolved. This +means that this function might or might not create a new `Promise`, it all depends on the current state. + +```kt +val nested = Promise.of(Promise.of(42)) +val promise = nested.unwrap() +promise success { + println(it) +} +``` + +##withContext +Returns a `Promise` operating on the provided `Context`. This function might return the same instance of the `Promise` +or a new one depending whether the `Context` of the `Promise` and the provided `Promise` match. + +```kt +val p = Promise.of(42).withContext(Kovenant.context) +``` + \ No newline at end of file diff --git a/docs/docs/api/functional_usage.md b/docs/docs/api/functional_usage.md index a2448bd..e6b604f 100644 --- a/docs/docs/api/functional_usage.md +++ b/docs/docs/api/functional_usage.md @@ -52,30 +52,4 @@ val p = Promise.of(21) apply Promise.of({ x: Int -> x * 2 }) p success { println(it) } ``` ---- - -##unwrap -Unwraps any nested Promise. By default the returned `Promise` will operate on the same `Context` as its parent -`Promise`, no matter what the `Context` of the nested `Promise` is. If you want the resulting promise to operate on -a different `Context` you can provide one. - -Function tries to be as efficient as possible in cases where this or the nested `Promise` is already resolved. This -means that this function might or might not create a new `Promise`, it all depends on the current state. - -```kt -val nested = Promise.of(Promise.of(42)) -val promise = nested.unwrap() -promise success { - println(it) -} -``` - -##withContext -Returns a `Promise` operating on the provided `Context`. This function might return the same instance of the `Promise` -or a new one depending whether the `Context` of the `Promise` and the provided `Promise` match. - -```kt -val p = Promise.of(42).withContext(Kovenant.context) -``` - diff --git a/projects/core/src/main/kotlin/context-api.kt b/projects/core/src/main/kotlin/context-api.kt index d9488d9..155892f 100644 --- a/projects/core/src/main/kotlin/context-api.kt +++ b/projects/core/src/main/kotlin/context-api.kt @@ -141,3 +141,32 @@ fun Kovenant.testMode(failures: (Throwable) -> Unit = { throw it }) { } } } + + +/** + * Returns a `Promise` operating on the provided `Context` + * + * This function might return the same instance of the `Promise` or a new one depending whether the + * `Context` of the `Promise` and the provided `Promise` match. + * + * + * @param context The `Context` on which the returned promise should operate + * @return the same `Promise` if the `Context` matches, a new promise otherwise with the provided context + */ +fun Promise.withContext(context: Context): Promise { + // Already same context, just return self + if (this.context == context) return this + + // avoid using deferred and callbacks if this promise + // is already resolved + if (isDone()) when { + isSuccess() -> return Promise.ofSuccess(get(), context) + isFailure() -> return Promise.ofFail(getError(), context) + } + + //okay, the hard way + val deferred = deferred(context) + success { deferred resolve it } + fail { deferred reject it } + return deferred.promise +} diff --git a/projects/core/src/main/kotlin/promises-api.kt b/projects/core/src/main/kotlin/promises-api.kt index 407f529..286666b 100644 --- a/projects/core/src/main/kotlin/promises-api.kt +++ b/projects/core/src/main/kotlin/promises-api.kt @@ -335,10 +335,14 @@ fun Promise.then(context: Context, bind: (V) -> R): Promise * * @param bind the transform function. */ -infix inline fun Promise.thenUse( +infix inline fun Promise.thenApply( crossinline bind: V.() -> R): Promise = then { it.bind() } +@Deprecated("renamed to 'thenApply'", ReplaceWith("thenApply(bind)")) +infix inline fun Promise.thenUse( + crossinline bind: V.() -> R): Promise = then { it.bind() } + /** * Transforms any `Promise` into a Promise. * @@ -396,4 +400,35 @@ fun Promise.toSuccessVoid(context: Context = this.context): Promise success { deferred.resolve() } fail { deferred.reject(it) } return deferred.promise +} + + +/** + * Unwraps any nested Promise. + * + * Unwraps any nested Promise. By default the returned `Promise` will operate on the same `Context` as its parent + * `Promise`, no matter what the `Context` of the nested `Promise` is. If you want the resulting promise to operate on + * a different `Context` you can provide one. + * + * Function tries to be as efficient as possible in cases where this or the nested `Promise` is already resolved. This + * means that this function might or might not create a new `Promise`, it all depends on the current state. + * + * @param context the `Context` on which the returned `Promise` operates + * @return the unwrapped Promise + */ +fun Promise, E>.unwrap(context: Context = this.context): Promise { + if (isDone()) when { + isSuccess() -> return get().withContext(context) + isFailure() -> return Promise.ofFail(getError(), context) + } + + val deferred = deferred(context) + success { + nested -> + nested success { deferred resolve it } + nested fail { deferred reject it } + } fail { + deferred reject it + } + return deferred.promise } \ No newline at end of file diff --git a/projects/core/src/test/kotlin/examples/lazy.kt b/projects/core/src/test/kotlin/examples/lazy.kt index b282e44..6202b41 100644 --- a/projects/core/src/test/kotlin/examples/lazy.kt +++ b/projects/core/src/test/kotlin/examples/lazy.kt @@ -23,7 +23,7 @@ package examples.lazy import nl.komponents.kovenant.properties.lazyPromise -import nl.komponents.kovenant.thenUse +import nl.komponents.kovenant.thenApply val expensiveResource by lazyPromise { println("init promise") @@ -33,7 +33,7 @@ val expensiveResource by lazyPromise { fun main(args: Array) { println("start program") - expensiveResource thenUse { + expensiveResource thenApply { "Got [$value]" } success { println(it) diff --git a/projects/functional/src/test/kotlin/tests/api/unwrap.kt b/projects/core/src/test/kotlin/tests/api/unwrap.kt similarity index 92% rename from projects/functional/src/test/kotlin/tests/api/unwrap.kt rename to projects/core/src/test/kotlin/tests/api/unwrap.kt index acb2dca..dcf250a 100644 --- a/projects/functional/src/test/kotlin/tests/api/unwrap.kt +++ b/projects/core/src/test/kotlin/tests/api/unwrap.kt @@ -20,13 +20,9 @@ * THE SOFTWARE. */ -package tests.api.functional.unwrap +package tests.api.unwrap -import nl.komponents.kovenant.DirectDispatcher -import nl.komponents.kovenant.Kovenant -import nl.komponents.kovenant.Promise -import nl.komponents.kovenant.functional.unwrap -import nl.komponents.kovenant.testMode +import nl.komponents.kovenant.* import org.junit.Before import org.junit.Test import kotlin.test.assertEquals diff --git a/projects/functional/src/main/kotlin/context.kt b/projects/functional/src/main/kotlin/context.kt index 04cca7a..d76bf74 100644 --- a/projects/functional/src/main/kotlin/context.kt +++ b/projects/functional/src/main/kotlin/context.kt @@ -19,37 +19,12 @@ * THE SOFTWARE. */ @file:JvmName("KovenantFnContext") + package nl.komponents.kovenant.functional import nl.komponents.kovenant.Context import nl.komponents.kovenant.Promise -import nl.komponents.kovenant.deferred - - -/** - * Returns a `Promise` operating on the provided `Context` - * - * This function might return the same instance of the `Promise` or a new one depending whether the - * `Context` of the `Promise` and the provided `Promise` match. - * - * - * @param context The `Context` on which the returned promise should operate - * @return the same `Promise` if the `Context` matches, a new promise otherwise with the provided context - */ -fun Promise.withContext(context: Context): Promise { - // Already same context, just return self - if (this.context == context) return this - - // avoid using deferred and callbacks if this promise - // is already resolved - if (isDone()) when { - isSuccess() -> return Promise.ofSuccess(get(), context) - isFailure() -> return Promise.ofFail(getError(), context) - } +import nl.komponents.kovenant.withContext as targetWithContext - //okay, the hard way - val deferred = deferred(context) - success { deferred resolve it } - fail { deferred reject it } - return deferred.promise -} \ No newline at end of file +@Deprecated("moved to core library", ReplaceWith("withContext(context)", "nl.komponents.kovenant.withContext")) +fun Promise.withContext(context: Context): Promise = this.targetWithContext(context) \ No newline at end of file diff --git a/projects/functional/src/main/kotlin/unwrap.kt b/projects/functional/src/main/kotlin/unwrap.kt index 06f664a..1f9c171 100644 --- a/projects/functional/src/main/kotlin/unwrap.kt +++ b/projects/functional/src/main/kotlin/unwrap.kt @@ -23,35 +23,8 @@ package nl.komponents.kovenant.functional import nl.komponents.kovenant.Context import nl.komponents.kovenant.Promise -import nl.komponents.kovenant.deferred +import nl.komponents.kovenant.unwrap as targetUnwrap -/** - * Unwraps any nested Promise. - * - * Unwraps any nested Promise. By default the returned `Promise` will operate on the same `Context` as its parent - * `Promise`, no matter what the `Context` of the nested `Promise` is. If you want the resulting promise to operate on - * a different `Context` you can provide one. - * - * Function tries to be as efficient as possible in cases where this or the nested `Promise` is already resolved. This - * means that this function might or might not create a new `Promise`, it all depends on the current state. - * - * @param context the `Context` on which the returned `Promise` operates - * @return the unwrapped Promise - */ -fun Promise, E>.unwrap(context: Context = this.context): Promise { - if (isDone()) when { - isSuccess() -> return get().withContext(context) - isFailure() -> return Promise.ofFail(getError(), context) - } - - val deferred = deferred(context) - success { - nested -> - nested success { deferred resolve it } - nested fail { deferred reject it } - } fail { - deferred reject it - } - return deferred.promise -} +@Deprecated("moved to core library", ReplaceWith("unwrap(context)", "nl.komponents.kovenant.unwrap")) +fun Promise, E>.unwrap(context: Context = this.context): Promise = this.targetUnwrap(context) diff --git a/projects/functional/src/test/kotlin/examples/covariance.kt b/projects/functional/src/test/kotlin/examples/covariance.kt index 6df0ed6..3ff88f3 100644 --- a/projects/functional/src/test/kotlin/examples/covariance.kt +++ b/projects/functional/src/test/kotlin/examples/covariance.kt @@ -22,8 +22,8 @@ package examples.covariance import nl.komponents.kovenant.Promise -import nl.komponents.kovenant.functional.unwrap import nl.komponents.kovenant.task +import nl.komponents.kovenant.unwrap fun main(args: Array) { createBase() success { diff --git a/projects/functional/src/test/kotlin/examples/unwrap.kt b/projects/functional/src/test/kotlin/examples/unwrap.kt index 31ca34e..9ff3736 100644 --- a/projects/functional/src/test/kotlin/examples/unwrap.kt +++ b/projects/functional/src/test/kotlin/examples/unwrap.kt @@ -22,7 +22,7 @@ package examples.unwrap import nl.komponents.kovenant.Promise -import nl.komponents.kovenant.functional.unwrap +import nl.komponents.kovenant.unwrap fun main(args: Array) { val nested = Promise.of(Promise.of(42)) From 03620c37337d19f9c24290c21d379928740277f0 Mon Sep 17 00:00:00 2001 From: mplatvoet Date: Thu, 17 Mar 2016 08:51:30 +0100 Subject: [PATCH 9/9] Release v3.2.0 --- README.md | 31 ++++++++++++++----------------- build.gradle | 4 ++-- docs/docs/changelog.md | 13 +++++++++++++ docs/docs/index.md | 13 +++++-------- docs/docs/roadmap.md | 14 +++++++++++++- projects/progress/progress.gradle | 2 +- 6 files changed, 48 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index daa6a98..e0596ec 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ task { "world" } and task { "Hello" } success { Please refer to the [Kovenant](http://kovenant.komponents.nl) site for API usage and more. ## Getting started -Build against Kotlin: `1.0.0`. +Build against Kotlin: `1.0.1`. Source and target compatibility is `1.6` ###Gradle ```groovy dependencies { - compile 'nl.komponents.kovenant:kovenant:3.1.0' + compile 'nl.komponents.kovenant:kovenant:3.2.0' } ``` @@ -32,7 +32,7 @@ dependencies { nl.komponents.kovenant kovenant - 3.1.0 + 3.2.0 ``` @@ -40,7 +40,7 @@ dependencies { Checkout the [Android Demo App on Github](https://github.com/mplatvoet/kovenant-android-demo). ###Artifacts -Kovenant has been structured in sub projects so you can cherry pick what you need. +Kovenant has been structured in sub projects so you can cherry pick what you need. |artifact |description | |--------------------|---------------------------------------------------------------------------------------------------| @@ -50,23 +50,20 @@ Kovenant has been structured in sub projects so you can cherry pick what you nee |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 | +|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 Issues are tracked in [Youtrack](http://issues.komponents.nl/youtrack/issues?q=project%3A+Kovenant) ##Release notes -See [Changelog](http://kovenant.komponents.nl/changelog/) for release notes +See [Changelog](changelog.md) for release notes ##Slack -Join the `#kovenant` channel on [Kotlin Slack](http://kotlinslackin.herokuapp.com). +Join the `#kovenant` channel on [Kotlin Slack](http://kotlinslackin.herokuapp.com). -## Recommended libraries: -Other libraries for Kotlin applications - -* [Injekt](https://github.com/kohesive/injekt) - Crazily easy Dependency Injection for Kotlin -* [Fuel](https://github.com/kittinunf/Fuel) - The easiest HTTP networking library in Kotlin for Android. \ No newline at end of file +## More Kotlin libraries +Check out [Awesome Kotlin](https://github.com/JavaBy/awesome-kotlin) diff --git a/build.gradle b/build.gradle index 74e766f..f8f0a03 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ */ buildscript { - ext.kotlinVersion = '1.0.0' + ext.kotlinVersion = '1.0.1' ext.extraConfVersion = '2.2.+' repositories { @@ -39,7 +39,7 @@ buildscript { allprojects { ext { - appVersion = '3.1.0' + appVersion = '3.2.0' appGroup = 'nl.komponents.kovenant' diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index 56e65d9..a2315b6 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -3,6 +3,19 @@ Changelog of Kovenant. Complying to [Semantic Versioning](http://semver.org). Please refer to [roadmap](roadmap.md) for upcoming releases. +##v3.2.0 + +**core** + +* [KOV-74](http://issues.komponents.nl/youtrack/issue/KOV-74) Move `unwrap` to core library +* [KOV-75](http://issues.komponents.nl/youtrack/issue/KOV-75) Move `withContext` to core library +* [KOV-76](http://issues.komponents.nl/youtrack/issue/KOV-76) rename `thenUse` to `thenApply` + +**general** + +* [KOV-77](http://issues.komponents.nl/youtrack/issue/KOV-77) Kotlin 1.0.1 + + ##v3.1.0 **rx** diff --git a/docs/docs/index.md b/docs/docs/index.md index 3937ab4..7d8492a 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -25,13 +25,13 @@ Developed with the following [goals](misc/goals.md) in mind. * **Dependency free**: when not counting kotlin std ## Getting started -Build against Kotlin: `1.0.0`. +Build against Kotlin: `1.0.1`. Source and target compatibility is `1.6` ###Gradle ```groovy dependencies { - compile 'nl.komponents.kovenant:kovenant:3.1.0' + compile 'nl.komponents.kovenant:kovenant:3.2.0' } ``` @@ -40,7 +40,7 @@ dependencies { nl.komponents.kovenant kovenant - 3.1.0 + 3.2.0 ``` @@ -73,8 +73,5 @@ See [Changelog](changelog.md) for release notes ##Slack Join the `#kovenant` channel on [Kotlin Slack](http://kotlinslackin.herokuapp.com). -## Recommended libraries -Other libraries for Kotlin applications: - -* [Injekt](https://github.com/kohesive/injekt) - Crazily easy Dependency Injection for Kotlin -* [Fuel](https://github.com/kittinunf/Fuel) - The easiest HTTP networking library in Kotlin for Android. \ No newline at end of file +## More Kotlin libraries +Check out [Awesome Kotlin](https://github.com/JavaBy/awesome-kotlin) diff --git a/docs/docs/roadmap.md b/docs/docs/roadmap.md index a0b5061..9bc6450 100644 --- a/docs/docs/roadmap.md +++ b/docs/docs/roadmap.md @@ -5,11 +5,23 @@ Input is always welcome. --- -##v3.2.0 +##v3.3.0 **expected** * UI Click handler +* Timeouts on blocking methods + +**certain** + +* n/a + +--- + +##v4.0.0 + +**expected** + * Groundwork for JavaScript, core only. **certain** diff --git a/projects/progress/progress.gradle b/projects/progress/progress.gradle index 2f1d90e..c38841f 100644 --- a/projects/progress/progress.gradle +++ b/projects/progress/progress.gradle @@ -24,5 +24,5 @@ project.description = "Progress tracking Kovenant extensions" dependencies { compile project(':kovenant-core') - compile 'nl.komponents.progress:progress-core:1.0.0' + compile 'nl.komponents.progress:progress-core:1.0.1' } \ No newline at end of file