Skip to content

Instantly share code, notes, and snippets.

@Dviejopomata
Created June 25, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dviejopomata/d54cda4b518eb6d4b49703d57424e66c to your computer and use it in GitHub Desktop.
Save Dviejopomata/d54cda4b518eb6d4b49703d57424e66c to your computer and use it in GitHub Desktop.
Kotlin future example
import kotlinx.coroutines.experimental.guava.future
import kotlin.system.measureTimeMillis
fun main(arr: Array<String>): Unit {
var metadata = "vavlue"
val t = measureTimeMillis {
val f = future {
val v = 1
Thread.sleep(1500)
println(Thread.currentThread().name)
metadata = "Changed value"
v
}
val f1 = future {
val v = 2
Thread.sleep(1000)
println(Thread.currentThread().name)
metadata = "Changed value2"
v
}
val i = f.get() + f1.get()
println("I1=$i")
}
println("T=$t METADATA=$metadata")
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.50'
}
group 'com.nextagilesoft'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile group: 'com.github.kittinunf.fuel', name: 'fuel', version: '1.13.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '0.23.3'
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-guava', version: '0.23.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment