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

触って分かるコルーチン

izmeal2000
February 13, 2019
590

 触って分かるコルーチン

izmeal2000

February 13, 2019
Tweet

Transcript

  1. Androidʹ͓͚ΔThreadͷ෮श Androidʹ͓͚ΔThreadૢ࡞ͷݪଇ 1. Do not block the UI thread ɹඳը͕ࢭ·ΔͱΫϦςΟΧϧ

    2. Do not access the Android UI toolkit from outside the UI thread ɹUI toolkit͸εϨουηʔϑͰ͸ແ͍ ɹ ࢀߟɿhttps://developer.android.com/guide/components/processes-and-threads
  2. CoroutineͱThreadͷؔ܎ ͨ͘͞Μಈ͔ͯ͠ΈΔ ࢀߟɿLearning Coroutine in Action ࣮ߦ݁Ռ 1 threads active

    at the start 4 threads active at the end Took 1031 ms 1ສݸͷίϧʔνϯʹରͯ͠εϨου3ͭ
  3. ࢀߟ threads are to coroutines what CPU cores are to

    threads ࢀߟɿhttps//stackoverflow.com/questions/49606471/why-and-when-to-use-co-routines- instead-of-threads-in-android-using-kotlin-as-th Coroutineʹͱͬͯthreadͱ͸ɺ threadʹͱͬͯͷCPUͱಉ͡Α͏ͳ΋ͷͰ͋Δ
  4. ·ͱΊ ɾCoroutine is a light way to concurrency with threads

    ɾܰྔͰฒߦॲཧʂ ɾreadableͰγϯϓϧͳฒߦॲཧʂ