diff --git a/README.md b/README.md index e67466f..67489e5 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,44 @@ #Progress -Progress tracking for Kotlin. +Track progress for [Kotlin](http://kotlinlang.org) ---- +[![CircleCI branch](https://img.shields.io/circleci/project/mplatvoet/progress/master.svg)](https://circleci.com/gh/mplatvoet/progress/tree/master) [![Maven Central](https://img.shields.io/maven-central/v/nl.komponents.progress/progress.svg)](http://search.maven.org/#browse%7C-300825966) [![DUB](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/mplatvoet/progress/blob/master/LICENSE) + +Please refer to [progress.komponents.nl](http://progress.komponents.nl) for more information ```kt -val progress = Progress() -progress.onUpdate { p-> - println("${p.percentage}%") +//private part +val control = Progress.control() + +//public part +val progress = control.progress + +//get notified on updates +progress.update { + println("${value}") +} + +//set value +control.value = 0.25 +control.value = 0.50 +control.value = 0.75 +control.value = 1.0 +``` + +## Getting started +This version is build against `kotlin-stdlib:0.12.200`. + +###Gradle +```groovy +dependencies { + compile 'nl.komponents.progress:progress:0.1.+' } +``` -val sub1 = progress.child(weight = 0.1) -val sub2 = progress.child(weight = 5) -val sub2sub1 = sub2.child() -val sub2sub2 = sub2.child() -val sub3 = progress.child() -val sub4 = progress.child(weight = 2) - -sub1.value = 0.25 -sub1.value = 0.50 -sub1.value = 0.75 -sub1.value = 1.0 - -sub2sub1.completed = true -sub2sub2.value = 0.5 -sub2sub2.value = 1.0 - -sub3.value = 0.25 -sub3.value = 0.50 -sub3.value = 0.75 -sub3.value = 1.0 - -sub4.value = 0.25 -sub4.value = 0.50 -sub4.value = 0.75 -sub4.value = 1.0 +###Maven +```xml + + nl.komponents.progress + progress + [0.1.0, 0.2.0) + ``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0bd6e57..33c0b47 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ */ buildscript { - ext.kotlinVersion = '0.11.91.2' + ext.kotlinVersion = '0.12.200' ext.extraConfVersion = '2.2.+' repositories { @@ -38,8 +38,8 @@ apply from: "${rootProject.projectDir}/gradle/versions.gradle" allprojects { ext { - appVersion = '0.1.2' - appGroup = 'nl.mplatvoet.komponents' + appVersion = '0.1.0' + appGroup = 'nl.komponents.progress' junitVersion = '4.12' @@ -194,7 +194,7 @@ task release { } task wrapper(type: Wrapper) { - gradleVersion = '2.4-rc-1' + gradleVersion = '2.4' doLast() { def gradleOpts = "-XX:MaxMetaspaceSize=1024m -Xmx1024m" diff --git a/docs/docs/documentation.md b/docs/docs/documentation.md new file mode 100644 index 0000000..9807ea2 --- /dev/null +++ b/docs/docs/documentation.md @@ -0,0 +1,103 @@ +#Progress usage documentation + +Progress is a small utility for tracking progress in Kotlin. It is written with concurrency scenarios in mind and +is thus entirely thread safe. Progress tracking consists of two separate parts: + +- `Progress` for receiving updates +- `ProgressControl` for changing the state. + +##ProgressControl +A `ProgressControl` allows you to mutate the state, ergo setting the progress value, for the associated `Progress`. +There are two types of `ProgressControl`s: + +- a single value control `SingleProgressControl` +- a container control `ContainerProgressControl` + +A `SingleProgressControl` allows you to directly set a value +```kt +val control = Progress.control() + +control.value = 1.0 // must be between 0.0 and 1.0 (inclusive) +``` + +A `ContainerProgressControl` allows you to depend on more than one `Progress` instances + +```kt +val control = Progress.containerControl() + +// create a SingleProcessControl as a child +// of this control +val one = control.child() + +// create a ContainerProcessControl as a child +// of this control +val second = control.containerChild() + +// another child from the second +// container with a custom weight +// for determining the impact on +// overall progress +val third = second.child(0.5) + +// so this weighs heavy on the progress +val fourth = second.child(2.0) +``` + +##Progress +Progress is the client part of progress tracking. You can register a callback for receiving updates on progress or +just query the current state. This can be shared across threads. You obtain a `Progress` instance from a `ProgressControl` +instance. + +```kt +val control = //... +val progress = control.progress + +progress.update { + //called upon updates +} + +// current value between 0.0 and 1.0 (inclusive) +progress.value + +// boolean value that is true when progress.value == 1.0 +progress.done + +``` + + + +##Example + +```kt +val masterControl = Progress.containerControl() +masterControl.progress.update { + println("${value}") +} + +val firstChild = masterControl.child(0.1) +val secondChild = masterControl.containerChild(5.0) +val secondChildFirstChild = secondChild.child() +val secondChildSecondChild = secondChild.child() +val thirdChild = masterControl.child() +val fourthChild = masterControl.child(2.0) + +firstChild.value = 0.25 +firstChild.value = 0.50 +firstChild.value = 0.75 +firstChild.value = 1.0 + +secondChildFirstChild.markAsDone() +secondChildSecondChild.value = 0.5 +secondChildSecondChild.value = 1.0 + +thirdChild.value = 0.25 +thirdChild.value = 0.50 +thirdChild.value = 0.75 +thirdChild.value = 1.0 + +fourthChild.value = 0.25 +fourthChild.value = 0.50 +fourthChild.value = 0.75 +fourthChild.value = 1.0 + +``` \ No newline at end of file diff --git a/docs/docs/index.md b/docs/docs/index.md index c6ae7b0..7679743 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -1,25 +1,42 @@ #Progress Track progress for [Kotlin](http://kotlinlang.org) +[![CircleCI branch](https://img.shields.io/circleci/project/mplatvoet/progress/master.svg)](https://circleci.com/gh/mplatvoet/progress/tree/master) [![Maven Central](https://img.shields.io/maven-central/v/nl.komponents.progress/progress.svg)](http://search.maven.org/#browse%7C-300825966) [![DUB](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/mplatvoet/progress/blob/master/LICENSE) + ```kt -//TODO +//private part +val control = Progress.control() + +//public part +val progress = control.progress + +//get notified on updates +progress.update { + println("${value}") +} + +//set value +control.value = 0.25 +control.value = 0.50 +control.value = 0.75 +control.value = 1.0 ``` ## Getting started -This version is build against `Java 7` and `kotlin-stdlib:0.11.91`. +This version is build against `kotlin-stdlib:0.12.200`. ###Gradle ```groovy dependencies { - compile 'nl.mplatvoet.komponents:progress:x.x.x' + compile 'nl.komponents.progress:progress:0.1.+' } ``` ###Maven ```xml - nl.mplatvoet.komponents + nl.komponents.progress progress - x.x.x + [0.1.0, 0.2.0) ``` \ No newline at end of file diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 5dcc25a..b276b89 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -9,5 +9,6 @@ repo_name: 'GitHub' pages: - ['index.md', 'Home'] +- ['documentation.md', 'Documentation'] theme_dir: theme/yeti \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 0087cd3..087988e 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 57efa42..cd69000 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,28 @@ -#Sun May 03 08:59:15 CEST 2015 +# +# Copyright (c) 2015 Mark Platvoet +# +# 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. +# + +#Tue Jun 09 21:11:52 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-rc-1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip diff --git a/gradlew b/gradlew index 91a7e26..26c7146 100755 --- a/gradlew +++ b/gradlew @@ -7,6 +7,7 @@ ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +GRADLE_OPTS="-XX:MaxMetaspaceSize=1024m -Xmx1024m $GRADLE_OPTS" DEFAULT_JVM_OPTS="" APP_NAME="Gradle" diff --git a/gradlew.bat b/gradlew.bat index aec9973..db7d7d1 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -9,6 +9,7 @@ if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set GRADLE_OPTS=-XX:MaxMetaspaceSize=1024m -Xmx1024m -XX:MaxHeapSize=256m %GRADLE_OPTS% set DEFAULT_JVM_OPTS= set DIRNAME=%~dp0 diff --git a/projects/core/src/main/kotlin/nl/komponents/progress/progress-api.kt b/projects/core/src/main/kotlin/nl/komponents/progress/progress-api.kt new file mode 100644 index 0000000..ac3b7dd --- /dev/null +++ b/projects/core/src/main/kotlin/nl/komponents/progress/progress-api.kt @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2015 Mark Platvoet + * + * 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. + */ + +package nl.komponents.progress + + +/** + * Represents the consumer part of progress tracking + */ +public interface Progress { + companion object { + /** + * defaultExecutor is the executor to be used when none is configured + * + * By default this just executes immediately + */ + volatile var defaultExecutor : (() -> Unit) -> Unit = { fn -> fn() } + + public fun control(executor: (() -> Unit) -> Unit = defaultExecutor): SingleProgressControl { + return concreteSingleProgressControl(executor) + } + + public fun containerControl(executor: (() -> Unit) -> Unit = defaultExecutor): ContainerProgressControl { + return concreteContainerProgressControl(executor) + } + } + + val executor: (() -> Unit) -> Unit + val done: Boolean get() = value >= 1.0 + val value: Double + + fun update(executor: (() -> Unit) -> Unit = this.executor, + notifyOnAdd: Boolean = true, + body: Progress.() -> Unit) + + + fun contains(progress: Progress): Boolean +} + +public data class ChildProgress(val progress: Progress, val weight: Double = 1.0) + +public interface ProgressControl { + val progress: Progress +} + +public interface SingleProgressControl : ProgressControl { + var value: Double + fun markAsDone() +} + +public interface ContainerProgressControl : ProgressControl { + + fun child(weight: Double = 1.0): SingleProgressControl { + val child = Progress.control(progress.executor) + addChild(child.progress, weight) + return child + } + + fun containerChild(weight: Double = 1.0): ContainerProgressControl { + val child = Progress.containerControl(progress.executor) + addChild(child.progress, weight) + return child + } + + fun addChild(progress: Progress, weight: Double = 1.0) +} + +public open class ProgressException(msg: String, cause: Throwable? = null) : Exception(msg, cause) +public open class ArgumentException(msg: String, cause: Throwable? = null) : ProgressException(msg, cause) +public open class OutOfRangeException(msg: String, cause: Throwable? = null) : ProgressException(msg, cause) \ No newline at end of file diff --git a/projects/core/src/main/kotlin/progress-jvm.kt b/projects/core/src/main/kotlin/nl/komponents/progress/progress-jvm.kt similarity index 60% rename from projects/core/src/main/kotlin/progress-jvm.kt rename to projects/core/src/main/kotlin/nl/komponents/progress/progress-jvm.kt index 7c695fb..133e8d0 100644 --- a/projects/core/src/main/kotlin/progress-jvm.kt +++ b/projects/core/src/main/kotlin/nl/komponents/progress/progress-jvm.kt @@ -20,26 +20,22 @@ * THE SOFTWARE. */ -package nl.mplatvoet.komponents.progress +package nl.komponents.progress -import java.util.ArrayList -import java.util.concurrent.ConcurrentHashMap +import java.util.* import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.atomic.AtomicReference -public fun concreteProgressControl(): ProgressControl { - return JvmProgress() -} +public fun concreteSingleProgressControl(executor: (() -> Unit) -> Unit): SingleProgressControl = JvmSingleProgress(executor) +public fun concreteContainerProgressControl(executor: (() -> Unit) -> Unit): ContainerProgressControl = JvmContainerProgress(executor) -private class JvmProgress() : ProgressControl, Progress { - private val childProgresses = ConcurrentLinkedQueue() - private val callbacks = ConcurrentLinkedQueue Unit>() + +private class JvmSingleProgress(executor: (() -> Unit) -> Unit) : SingleProgressControl, CallbackSupport(executor), Progress { private val atomicVal = AtomicReference(0.0) - override val progress: Progress - get() = this + override val progress: Progress = object : Progress by this {} override fun markAsDone() { value = 1.0 @@ -52,12 +48,8 @@ private class JvmProgress() : ProgressControl, Progress { public override var value: Double get() = atomicVal.get() set(suggestedValue) { - //checking whether this Progress object is managed by children is not thread safe. - //it's just a way to catch misuse of the API - if (!childProgresses.isEmpty()) throw IllegalStateException("children manage the state of this Progress object") if (suggestedValue !in (0.0..1.0)) throw OutOfRangeException("[$value] must be within bounds (0.0 .. 1.0)") - var notify: Boolean do { val currentVal = atomicVal.get() @@ -67,30 +59,30 @@ private class JvmProgress() : ProgressControl, Progress { } - override fun createChild(weight: Double): ProgressControl { - val child = JvmProgress() - addChild(child.progress, weight) - return child - } + override fun contains(progress: Progress): Boolean = this == progress +} + +private class JvmContainerProgress(executor: (() -> Unit) -> Unit) : ContainerProgressControl, CallbackSupport(executor), Progress { + private val childProgresses = ConcurrentLinkedQueue() + private val atomicVal = AtomicReference(0.0) - override val children: List - get() = ArrayList(childProgresses) + private val self = this + override val progress: Progress = object : Progress by this { + override fun equals(other: Any?): Boolean = self.equals(other) + override fun hashCode(): Int = self.hashCode() + } + public override val value: Double + get() = atomicVal.get() - //Prevents a copy of the children list override fun contains(progress: Progress): Boolean { if (this == progress) return true - - childProgresses forEach { - if(it.progress.contains(progress)) return false - } - - return false + return childProgresses any { child -> child.progress.contains(progress) } } override fun addChild(progress: Progress, weight: Double) { - if (weight < 0.0) throw IllegalArgumentException("weight can not be negative") - if (contains(progress)) throw IllegalArgumentException("circular reference") + if (weight < 0.0) throw ArgumentException("weight can not be negative") + if (progress.contains(this)) throw ArgumentException("circular reference") childProgresses add ChildProgress(progress, weight) progress.update { updateValue() } @@ -116,18 +108,28 @@ private class JvmProgress() : ProgressControl, Progress { } return if (totalWeight > 0.0 && totalWeightValue > 0.0) totalWeightValue / totalWeight else 0.0 } +} +private abstract class CallbackSupport(override val executor: (() -> Unit) -> Unit) : Progress { + private val callbacks = ConcurrentLinkedQueue() - private fun notifyUpdate() { - callbacks.forEach { body -> this.body() } + protected fun notifyUpdate() { + callbacks.forEach { cb -> cb.execute(this) } } - override fun update(notifyOnAdd: Boolean, body: Progress.() -> Unit) { + override fun update(executor: (() -> Unit) -> Unit, notifyOnAdd: Boolean, body: Progress.() -> Unit) { //Could miss an event, should record what's been called already - if (notifyOnAdd) this.body() - callbacks add body + val callback = Callback(executor, body) + if (notifyOnAdd) { + callback.execute(this) + } + callbacks add callback } +} + +private class Callback(private val executor: (() -> Unit) -> Unit, + private val cb: Progress.() -> Unit) { + fun execute(progress: Progress) = executor { progress.cb() } } -public class OutOfRangeException(msg: String, cause: Throwable? = null) : IllegalArgumentException(msg, cause) \ No newline at end of file diff --git a/projects/core/src/main/kotlin/progress-api.kt b/projects/core/src/main/kotlin/progress-api.kt deleted file mode 100644 index afd47a9..0000000 --- a/projects/core/src/main/kotlin/progress-api.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2015 Mark Platvoet - * - * 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. - */ - -package nl.mplatvoet.komponents.progress - -public fun progressControl() : ProgressControl = concreteProgressControl() - -public trait Progress { - val done : Boolean - val value : Double - - fun update(notifyOnAdd: Boolean = true, body : Progress.() -> Unit) - - val intValue : Int get() = (value * 100).toInt() - - val children : List - - fun contains(progress : Progress) : Boolean { - if (progress == this) return true - children.forEach { - if (it.progress.contains(progress)) return true - } - return false - } -} - -public data class ChildProgress(val progress: Progress, val weight: Double = 1.0) - -public trait ProgressControl { - var value : Double - fun createChild(weight : Double = 1.0) : ProgressControl - fun addChild(progress: Progress, weight : Double = 1.0) - - fun markAsDone() - val progress : Progress - - -} - diff --git a/projects/core/src/test/kotlin/example/Example.kt b/projects/core/src/test/kotlin/example/example01.kt similarity index 66% rename from projects/core/src/test/kotlin/example/Example.kt rename to projects/core/src/test/kotlin/example/example01.kt index f7c4a37..745de0f 100644 --- a/projects/core/src/test/kotlin/example/Example.kt +++ b/projects/core/src/test/kotlin/example/example01.kt @@ -22,42 +22,42 @@ package example -import nl.mplatvoet.komponents.progress.OutOfRangeException -import nl.mplatvoet.komponents.progress.progressControl +import nl.komponents.progress.OutOfRangeException +import nl.komponents.progress.Progress import java.text.DecimalFormat import kotlin.properties.ReadOnlyProperty fun main(args: Array) { - val control = progressControl() - control.progress.update { + val masterControl = Progress.containerControl() + masterControl.progress.update { println("${value.percentage}%") } - val sub1 = control.createChild(0.1) - val sub2 = control.createChild(5.0) - val sub2sub1 = sub2.createChild() - val sub2sub2 = sub2.createChild() - val sub3 = control.createChild() - val sub4 = control.createChild(2.0) + val firstChild = masterControl.child(0.1) + val secondChild = masterControl.containerChild(5.0) + val secondChildFirstChild = secondChild.child() + val secondChildSecondChild = secondChild.child() + val thirdChild = masterControl.child() + val fourthChild = masterControl.child(2.0) - sub1.value = 0.25 - sub1.value = 0.50 - sub1.value = 0.75 - sub1.value = 1.0 + firstChild.value = 0.25 + firstChild.value = 0.50 + firstChild.value = 0.75 + firstChild.value = 1.0 - sub2sub1.markAsDone() - sub2sub2.value = 0.5 - sub2sub2.value = 1.0 + secondChildFirstChild.markAsDone() + secondChildSecondChild.value = 0.5 + secondChildSecondChild.value = 1.0 - sub3.value = 0.25 - sub3.value = 0.50 - sub3.value = 0.75 - sub3.value = 1.0 + thirdChild.value = 0.25 + thirdChild.value = 0.50 + thirdChild.value = 0.75 + thirdChild.value = 1.0 - sub4.value = 0.25 - sub4.value = 0.50 - sub4.value = 0.75 - sub4.value = 1.0 + fourthChild.value = 0.25 + fourthChild.value = 0.50 + fourthChild.value = 0.75 + fourthChild.value = 1.0 } private val percentageFormat by ThreadLocalVal { DecimalFormat("##0.00") } @@ -71,6 +71,6 @@ private class ThreadLocalVal(private val initializer: () -> T) : ReadOnlyProp override fun initialValue(): T = initializer() } - public override fun get(thisRef: Any?, desc: PropertyMetadata): T = threadLocal.get() : T + public override fun get(thisRef: Any?, desc: PropertyMetadata): T = threadLocal.get() } diff --git a/projects/kovenant/kovenant.gradle b/projects/kovenant/kovenant.gradle deleted file mode 100644 index 6a41131..0000000 --- a/projects/kovenant/kovenant.gradle +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015 Mark Platvoet - * - * 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. - */ - -project.description = "Progress tracking Kovenant extensions" - -dependencies { - compile project(':progress-core') - compile 'nl.mplatvoet.komponents:kovenant:0.1.2' -} \ No newline at end of file diff --git a/projects/kovenant/src/main/kotlin/kovenant-jvm.kt b/projects/kovenant/src/main/kotlin/kovenant-jvm.kt deleted file mode 100644 index b7d6a4b..0000000 --- a/projects/kovenant/src/main/kotlin/kovenant-jvm.kt +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2015 Mark Platvoet - * - * 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. - */ - -package nl.mplatvoet.komponents.progress.kovenant - -import nl.mplatvoet.komponents.kovenant.* -import nl.mplatvoet.komponents.progress.Progress -import nl.mplatvoet.komponents.progress.ProgressControl -import nl.mplatvoet.komponents.progress.progressControl - -trait ProgressPromise : Promise { - val progress: Progress -} - -public fun async(context: Context = Kovenant.context, body: ProgressControl.() -> V): ProgressPromise { - val deferred = deferred(context) - val control = progressControl() - context.workerDispatcher offer { - try { - val result = control.body() - deferred.resolve(result) - control.markAsDone() - } catch(e: Exception) { - deferred.reject(e) - } - } - return JvmProgressPromise(deferred.promise, control.progress) -} - -public fun ProgressPromise.then(bind: ProgressControl.(V) -> R): ProgressPromise { - val context = when (this) { - is ContextAware -> this.context - else -> Kovenant.context - } - - val masterControl = progressControl() - val children = progress.children - if (children.isEmpty()) { - masterControl addChild progress - } else { - children.forEach { - masterControl.addChild(it.progress, it.weight) - } - } - - val contextControl = masterControl.createChild() - val deferred = deferred(context) - success { - context.workerDispatcher offer { - try { - val result = contextControl.bind(it) - deferred.resolve(result) - contextControl.markAsDone() - } catch(e: Exception) { - deferred.reject(e) - } - } - } - fail { - deferred.reject(it) - } - return JvmProgressPromise(deferred.promise, masterControl.progress) -} - - -private class JvmProgressPromise(private val promise: Promise, - override val progress: Progress) : ProgressPromise, Promise { - override fun always(callback: () -> Unit): ProgressPromise { - promise always callback - return this - } - - override fun fail(callback: (E) -> Unit): ProgressPromise { - promise fail callback - return this - } - - override fun success(callback: (V) -> Unit): ProgressPromise { - promise success callback - return this - } - -} diff --git a/projects/kovenant/src/test/kotlin/examples/progress.kt b/projects/kovenant/src/test/kotlin/examples/progress.kt deleted file mode 100644 index 55ad78a..0000000 --- a/projects/kovenant/src/test/kotlin/examples/progress.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2015 Mark Platvoet - * - * 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. - */ - -package examples.progress - -import nl.mplatvoet.komponents.progress.kovenant.async -import nl.mplatvoet.komponents.progress.kovenant.then - - -fun main(args: Array) { - val promise = async { - 1..10 forEach { - value = 1.0 - ((10 - it) / 10.0) - Thread.sleep(100L) - } - } then { - 1..10 forEach { - value = 1.0 - ((10 - it) / 10.0) - Thread.sleep(100L) - } - } then { - 1..10 forEach { - value = 1.0 - ((10 - it) / 10.0) - Thread.sleep(100L) - } - } - - - promise.progress.update { - println(intValue) - } -} diff --git a/settings.gradle b/settings.gradle index 9730464..8e800f0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -24,7 +24,6 @@ rootProject.name = 'root' include 'core' include 'progress' -include 'kovenant' rootProject.children.each { project -> String projectFileName = project.name.replaceAll("\\p{Upper}") { "-${it.toLowerCase()}" } @@ -34,4 +33,3 @@ rootProject.children.each { project -> } project(":core").name = "progress-core" -project(":kovenant").name = "progress-kovenant"