File tree Expand file tree Collapse file tree 4 files changed +51
-8
lines changed Expand file tree Collapse file tree 4 files changed +51
-8
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,6 @@ import retrofit2.Response
6
6
7
7
val log: Logger = LoggerFactory .getLogger(" Contributors" )
8
8
9
- /* fun logRepos(req: RequestData, repos: List<Repo>) {
10
- log.info("${req.org}: loaded ${repos.size} repos")
11
- }
12
-
13
- fun logUsers(repo: Repo, users: List<User>) {
14
- log.info("${repo.name}: loaded ${users.size} contributors")
15
- }*/
16
-
17
9
fun log (msg : String? ) {
18
10
log.info(msg)
19
11
}
Original file line number Diff line number Diff line change
1
+ package samples
2
+
3
+ import kotlinx.coroutines.channels.Channel
4
+ import kotlinx.coroutines.*
5
+
6
+ fun main () = runBlocking<Unit > {
7
+ val channel = Channel <String >()
8
+ launch {
9
+ channel.send(" A1" )
10
+ channel.send(" A2" )
11
+ log(" A done" )
12
+ }
13
+ launch {
14
+ channel.send(" B1" )
15
+ log(" B done" )
16
+ }
17
+ launch {
18
+ repeat(3 ) {
19
+ val x = channel.receive()
20
+ log(x)
21
+ }
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ package samples
2
+
3
+ import kotlinx.coroutines.*
4
+
5
+ fun main () = runBlocking {
6
+ val deferred: Deferred <Int > = async(Dispatchers .Default ) {
7
+ loadData()
8
+ }
9
+ log(" waiting..." )
10
+ log(deferred.await())
11
+ }
12
+
13
+ suspend fun loadData (): Int {
14
+ log(" loading..." )
15
+ delay(1000L )
16
+ log(" loaded!" )
17
+ return 42
18
+ }
Original file line number Diff line number Diff line change
1
+ package samples
2
+
3
+ import org.slf4j.Logger
4
+ import org.slf4j.LoggerFactory
5
+
6
+ val log: Logger = LoggerFactory .getLogger(" Samples" )
7
+
8
+ fun log (msg : Any? ) {
9
+ log.info(msg.toString())
10
+ }
You can’t perform that action at this time.
0 commit comments