Skip to content

Commit 08b71eb

Browse files
committed
synchs up contents
1 parent ff6e047 commit 08b71eb

File tree

7 files changed

+197
-32
lines changed

7 files changed

+197
-32
lines changed

build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ dependencies {
5656
}
5757
testCompile group: 'junit', name: 'junit', version: '4.12'
5858
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
59+
60+
compile group: 'io.reactivex', name: 'rxjava', version: '1.3.8'
61+
5962
}
6063

6164
compileKotlin {

src/main/kotlin/org/pedrofelix/kotlin/examples/buildstuff18.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fun blockingOperation(input: Int): Int {
2020
}
2121

2222
private val executor = Executors.newScheduledThreadPool(5)
23-
fun asyncOperationWithCallback(input: Int, callback: (Int) -> Unit): Unit {
23+
qfun asyncOperationWithCallback(input: Int, callback: (Int) -> Unit): Unit {
2424
executor.schedule({ callback(input + 42) }, 1000, TimeUnit.MILLISECONDS)
2525
}
2626

src/main/kotlin/org/pedrofelix/kotlin/examples/spring-examples.kt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RestController
1010
import org.springframework.web.context.request.async.AsyncRequestTimeoutException
1111
import org.springframework.web.context.request.async.DeferredResult
1212
import java.util.concurrent.Executors
13+
import kotlin.coroutines.ContinuationInterceptor
1314
import kotlin.coroutines.CoroutineContext
1415
import kotlin.coroutines.EmptyCoroutineContext
1516

@@ -96,6 +97,7 @@ class TheController {
9697
@GetMapping("/example-with-dispatcher")
9798
fun getExampleWithDispatcher() = asyncHandler {
9899
withContext(exampleDispatcher) {
100+
log.info("using interceptor {}", coroutineContext[ContinuationInterceptor])
99101
example7(1)
100102
}
101103
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.pedrofelix.kotlin.examples
2+
3+
import kotlinx.coroutines.*
4+
import org.junit.Test
5+
import org.pedrofelix.experiments.ScopeExamples
6+
import org.slf4j.LoggerFactory
7+
import kotlin.coroutines.ContinuationInterceptor
8+
import kotlin.coroutines.coroutineContext
9+
10+
private val log = LoggerFactory.getLogger(RandomTests::class.java)
11+
12+
class RandomTests {
13+
14+
private suspend fun doSomethingWith(i: Int) {
15+
log.info("ctx {}", coroutineContext)
16+
}
17+
18+
@Test
19+
fun first() {
20+
val items = listOf(1,2,3,4)
21+
runBlocking {
22+
withContext(Dispatchers.IO) {
23+
log.info("ctx {}", coroutineContext)
24+
items.forEach { launch { doSomethingWith(it) } }
25+
}
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.pedrofelix.kotlin.examples
2+
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.delay
5+
import kotlinx.coroutines.launch
6+
import org.junit.Test
7+
import rx.Single
8+
9+
class RxExampleTests {
10+
11+
@Test
12+
fun test() {
13+
14+
val s = Single.create<String> { obs ->
15+
val job = GlobalScope.launch {
16+
delay(1000)
17+
obs.onSuccess("done")
18+
}
19+
// ...
20+
job.cancel()
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)