Upgrade to Pro — share decks privately, control downloads, hide ads and more …

kotlin-mpp-library-tips

uzzu
February 18, 2019

 kotlin-mpp-library-tips

Cookpad.apk #2 登壇資料 https://cookpad.connpass.com/event/117054/

uzzu

February 18, 2019
Tweet

More Decks by uzzu

Other Decks in Technology

Transcript

  1. ؆୯ͳ֓ཁ wl&YQFSJNFOUBMGFBUVSFJO,PUMJOBOEz w1MBUGPSNؒͰίʔυΛڞ༗͢Δ +7. "OESPJE  +BWB4DSJQU J04 -JOVY 8JOEPXT

    .BD FUDʜ  wϓϥοτϑΥʔϜඇґଘͳίʔυ͸DPNNPOQSPKFDU
 ґଘίʔυ͸QMBUGPSNQSPKFDUʹॻ͍͍ͯ͘
  2. Kotlin Source Codes Kotlin / JVM Kotlin / Native Kotlin

    / JS JVM Android Executable Dynamic Library iOS Node.js Browser JS Server app Desktop app etc… Android app iOS(arm32, arm64, emulator x86_64) MacOS(x86_64) Android(arm32, arm64) Linux(x86_64, arm32, MIPS, MIPS little endian) WebAssembly(wasm32) Windows(mingw x86_64) Frontend Web app Server app etc…
  3. Kotlin Source Codes Kotlin / JVM Kotlin / Native Kotlin

    / JS JVM Android Executable Dynamic Library iOS Node.js Browser JS java.util.concurrent.* Handler pthread etc… Promise Coroutines - ඇಉظॲཧ -> abstraction by CoroutineContext GCD
  4. Kotlin Source Codes Kotlin / JVM Kotlin / Native Kotlin

    / JS JVM Android Executable Dynamic Library iOS Node.js Browser JS nghttp2 libcurl etc… Fetch API ktor-client - HTTPClient -> abstraction by HTTPClientEngine NSURLRequest etc… apache Jetty etc… okhttp etc… request node-fetch etc..
  5. 5FDIOPMPHZ4UBDL w(SBEMF ,PUMJOʙ ݱࡏ͸  wLPUMJOTUEMJC LPUMJOYDPSPVUJOFTDPSF  LPUMJOYTFSJBMJ[BUJPO LUPSDMJFOU

    wLPUMJOUFTU LPUMJOYDPSPVUJOFTUFTU LUPSDMJFOU NPDL NPDLL BTTFSUL LUMJOU wޙ͸QMBUGPSNʹ߹Θͤͯ0L)UUQ౳
  6. $PSPVUJOFT class CallCount(val value: Int) { override fun equals(other: Any?)

    = this === other } var callCount = 0 suspend fun increment(): CallCount { ++callCount delay(10) return CallCount(callCount) } ྫ ϝιουίʔϧ͞Εͨճ਺Λฦ٫͢Δ͚ͩͷؔ਺
  7. $PSPVUJOFT @Test fun basicWithHot() = runBlocking(hotInvocation()) { val times =

    3 val results = mutableListOf<CallCount>() val jobs = mutableListOf<Job>() repeat(times) { i -> val job = launch { runCatching { withContext(Dispatchers.IO) { withHot("hot") { increment() } } } .onSuccess { results.add(it) } .onFailure { fail("[$i] Exception occurred: $it") } } jobs.add(job) } jobs.forEach { it.join() } assertAll { assertThat(results.size).isEqualTo(times) // શͯͷ࣮ߦContextʹincrement()ͷ݁Ռ͕ฦ٫͞ΕΔ assertThat(results.distinct().size).isEqualTo(1) // ಉҰΦϒδΣΫτ͕ฦ٫͞ΕΔ assertThat(results.distinct()[0].value).isEqualTo(1) // increment()ͷݺग़ճ਺͸1ճ } }