Slide 1

Slide 1 text

{ Kotlin } Statically typed language for the JVM, Android and the browser. Developed by JetBrains

Slide 2

Slide 2 text

{ Little about the language } ● Null safety ● Expressive ● 100% java interoperability ------------------------------------------------- ● Lambdas ● ( map, filter, reduce ..) ● Higher-order functions ● Extensions ● Automatic type inference ● Inline functions ● …..

Slide 3

Slide 3 text

{ Coroutines } ● NOT A THREAD !!! Is like ● Lightweight threads ● More like daemon threads ● Programs that allows to run multiple program cooperatively

Slide 4

Slide 4 text

Behind the scene ExecutorService ThreadPoolExecutor Executors Thread pools …. + Kotlin implementation of pools, CoroutineDispatcher and etc ● Write asynchronous code as it was synchronous ● Avoid from callback hell ● Run multiple async computations simultaneously(demo in example) ● Less memory usage (compared to Threads) { Coroutines }

Slide 5

Slide 5 text

{ Coroutines VS Threads } Coroutine - ● It is stackless(doesn't have own stack) low memory usage ● Doesn't map on native thread ● Managed by user ● Cooperatively multitasking (no context switch)

Slide 6

Slide 6 text

● Launch ● Async ● Future ● Deferred ● suspend ● await { Coroutines }

Slide 7

Slide 7 text

{ Coroutines } 1 start coroutine 2 var rawData = startSomeNetworkRequest.await() 3 var data = parseData(rawData).await() 4 diplayData(data)

Slide 8

Slide 8 text

Create 100 000 coroutine which runs simultaneously val jobs = List(100_100) { async(CommonPool) { delay(1000) 1 } } jobs.sumBy{ it.await() } { Coroutines }.example