Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

upgrade kotlin to 1.3 #30

Merged
merged 1 commit into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.61'
ext.kotlin_coroutines = '0.25.3'
ext.kotlin_version = '1.3.20'
ext.kotlin_coroutines = '1.1.1'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 01 14:51:15 EDT 2017
#Mon Feb 18 10:48:58 EST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
2 changes: 1 addition & 1 deletion snail-kotlin/src/main/java/com/compass/snail/Fail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.compass.snail

import kotlinx.coroutines.experimental.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher

open class Fail<T>(private val _error: Throwable) : Observable<T>() {
override fun subscribe(dispatcher: CoroutineDispatcher?, next: ((T) -> Unit)?, error: ((Throwable) -> Unit)?, done: (() -> Unit)?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.compass.snail

import kotlinx.coroutines.experimental.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher

interface IObservable<T> {
fun subscribe(dispatcher: CoroutineDispatcher? = null, next: ((T) -> Unit)? = null, error: ((Throwable) -> Unit)? = null, done: (() -> Unit)? = null)
Expand Down
2 changes: 1 addition & 1 deletion snail-kotlin/src/main/java/com/compass/snail/Just.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.compass.snail

import kotlinx.coroutines.experimental.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher

open class Just<T>(private val value: T) : Observable<T>() {
override fun subscribe(dispatcher: CoroutineDispatcher?, next: ((T) -> Unit)?, error: ((Throwable) -> Unit)?, done: (() -> Unit)?) {
Expand Down
7 changes: 4 additions & 3 deletions snail-kotlin/src/main/java/com/compass/snail/Observable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
package com.compass.snail

import android.util.Log
import kotlinx.coroutines.experimental.CoroutineDispatcher
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.util.concurrent.Semaphore

open class Observable<T> : IObservable<T> {
Expand Down Expand Up @@ -70,7 +71,7 @@ open class Observable<T> : IObservable<T> {

fun notify(subscriber: Subscriber<T>, event: Event<T>) {
subscriber.dispatcher?.let {
launch(it) {
GlobalScope.launch(it) {
safeNotify(subscriber, event)
}
return
Expand Down
2 changes: 1 addition & 1 deletion snail-kotlin/src/main/java/com/compass/snail/Replay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.compass.snail

import kotlinx.coroutines.experimental.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher

open class Replay<T>(private val threshold: Int) : Observable<T>() {
private var values: MutableList<T> = mutableListOf()
Expand Down
2 changes: 1 addition & 1 deletion snail-kotlin/src/main/java/com/compass/snail/Subscriber.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

package com.compass.snail

import kotlinx.coroutines.experimental.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher

data class Subscriber<in T>(val dispatcher: CoroutineDispatcher?, val eventHandler: (Event<T>) -> Unit)
29 changes: 15 additions & 14 deletions snail-kotlin/src/test/java/com/compass/snail/ObservableTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

package com.compass.snail

import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.newSingleThreadContext
import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.newFixedThreadPoolContext
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -108,11 +109,11 @@ class ObservableTests {

@Test
fun testSubscribeOnRequestedDispatcher() {
var future = CompletableFuture<Boolean>()
val future = CompletableFuture<Boolean>()

async {
subject?.subscribe(dispatcher = CommonPool, next = {
future.complete(Thread.currentThread().name.toLowerCase().contains("commonpool"))
GlobalScope.async {
subject?.subscribe(dispatcher = Dispatchers.Default, next = {
future.complete(Thread.currentThread().name.toLowerCase().contains("default"))
})
subject?.next("1")
}
Expand All @@ -122,10 +123,10 @@ class ObservableTests {

@Test
fun testOnDispatcher() {
var future = CompletableFuture<Boolean>()
val future = CompletableFuture<Boolean>()

val threadName = "testThread"
val dispatcher = newSingleThreadContext(threadName)
val dispatcher = newFixedThreadPoolContext(1, threadName)
val observable = Observable<Boolean>()
observable.on(dispatcher).subscribe(next = {
future.complete(Thread.currentThread().name.contains(threadName))
Expand Down Expand Up @@ -167,12 +168,12 @@ class ObservableTests {
@Test
fun testThrottle() {
val observable = Observable<String>()
var received = mutableListOf<String>()
val received = mutableListOf<String>()

var future = CompletableFuture<Boolean>()
val future = CompletableFuture<Boolean>()
val delayMs = 100L

async {
GlobalScope.async {
delay(delayMs)
future.complete(true)
}
Expand Down