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

Understanding Coroutines

Understanding Coroutines

09387cf644abcfd34e981378f9e70541?s=128

zhanpon

March 25, 2020
Tweet

Transcript

  1. ίϧʔνϯΛཧղ͍ͨ͠

  2. ͸͡Ίʹ — Goal: ίϧʔνϯΛཧղ͢ΔͨΊͷಓےΛࣔ͢ — Non-Goal: Kotlinͷίϧʔνϯͷৄ͍͠࿩

  3. XΛཧղ͢Δͱ͸ʁ

  4. ઃܭॻΛಡΜͰΈΔ — KEEP: Kotlin Evolution and Enhancement Process — Kotlinͷ৽͍͠ݴޠػೳͷϓϩϙʔβϧ͕ࡌ͍ͬͯΔ

    — ίϧʔνϯͷઃܭʹ͍ͭͯ΋ίϯύΫτʹ·ͱ·͍ͬͯΔ
  5. KEEPͷ಺༰ — Ϣʔεέʔε: ඇಉظॲཧɺFutureɺδΣωϨʔλʔɺඇಉ ظUIͳͲ͕ίϧʔνϯʹΑͬͯͲ͏ॻ͚Δ͔ — ίϧʔνϯͷ֓ཁ: ༻ޠूɺͦͯ͠جຊతͳ֓೦ͷղઆ — ࣮૷ͷৄࡉ:

    CPSม׵ɺState machineͳͲ
  6. XΛཧղ͢Δͱ͸ — XΛ࢖ͬͨϓϩάϥϜΛॻ͚Δ — XͷηϚϯςΟΫε͕෼͔Δ — Xͷ࣮૷Λ஌͍ͬͯΔ

  7. ͳͥKotlinͷίϧʔνϯ͸೉͍͠ͷ͔ — ৽͍֓͠೦͔ͩΒ: Javaͷݴޠػೳʹίϧʔνϯ͸ͳ͍ ʢProject LoomʹΑͬͯࠓޙ࣮૷͞ΕΔ͔΋ʣ — ͍Ζ͍Ζͳॻ͖ํ͕༻ҙ͞Ε͍ͯΔ: suspend fun,

    launch{}, future{}, .await(), sequence{}, yield, ... — ϚϧνεϨουͱͷؔ܎
  8. ίϧʔνϯΛཧղ͢ΔͨΊͷγϯϓϧͳ࿮૊Έ — Revisiting CoroutinesΑΓ — ϓϦϛςΟϒ͸3͚ͭͩ: create, resume, yield —

    ಈ࡞͢ΔαϯϓϧίʔυͷͨΊʹLuaΛ࢖͏ — ҎԼͷεϥΠυͰར༻͢Δαϯϓϧίʔυ: https:// gist.github.com/zhanpon/ 5db10a44649b60f234732453907ffb6f
  9. ίϧʔνϯ͸ݺͼग़ͤΔ — createͰ࡞੒ — resumeͰݺͼग़͠

  10. ίϧʔνϯ͸தஅͰ͖Δ — yieldͰதஅ

  11. Ԡ༻: ϚϧνλεΫ — தஅͱ࠶։͕Ͱ͖Δίϧʔνϯͷੑ࣭ΛԠ༻͢Δ — ෳ਺ͷίϧʔνϯΛॱ൪ʹதஅɾ࠶։ͤ͞Ε͹ಉ࣌ʹಈ͍ ͍ͯΔΑ͏ʹݟ͑Δʂ

  12. ࢀߟจݙ — KEEP: Kotlin Coroutines — Revisiting Coroutines — Programming

    in Lua, Chapter 9
  13. ѻΘͳ͔ͬͨτϐοΫ — ܧଓͷ֓೦ — ίϧʔνϯΛ࢖ͬͯྫ֎Λ࣮૷͢Δ — CPSม׵