Slide 1

Slide 1 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJO'FTU 5PTIJIJSP:BHJ ,PUMJOίϧʔνϯΛ ཧղ͠Α͏

Slide 2

Slide 2 text

©2018 Lang-8 Inc. ALL Rights Reserved. wീ໦ढ़޿ w!TZTZBHJ w$50PG w"OESPJE&OHJOFFS "CPVU.F Jetpack Handbook ʲC94৽ץʳ ʮୈ6ষ WorkManagerͱόοΫάϥ΢ϯυλεΫʯ ॻ͖·ͨ͠

Slide 3

Slide 3 text

©2018 Lang-8 Inc. ALL Rights Reserved. ©2018 Lang-8 Inc. ALL Rights Reserved. https://hinative.com 8FBSFIJSJOH

Slide 4

Slide 4 text

©2018 Lang-8 Inc. ALL Rights Reserved. wίϧʔνϯͱ͸ͳʹ͔ w,PUMJO͸ͲͷΑ͏ʹίϧʔνϯΛ࣮ݱ ͍ͯ͠Δͷ͔ w,PUMJOίϧʔνϯͷجຊతͳ࢖͍ํ ࠓ೔࿩͢͜ͱ

Slide 5

Slide 5 text

©2018 Lang-8 Inc. ALL Rights Reserved. wίϧʔνϯͱ͸ͳʹ͔ w,PUMJO͸ͲͷΑ͏ʹίϧʔνϯΛ࣮ݱ ͍ͯ͠Δͷ͔ w,PUMJOίϧʔνϯͷجຊతͳ࢖͍ํ ࠓ೔࿩͢͜ͱ

Slide 6

Slide 6 text

©2018 Lang-8 Inc. ALL Rights Reserved. wίϧʔνϯͱ͸ͳʹ͔ w,PUMJO͸ͲͷΑ͏ʹίϧʔνϯΛ࣮ݱ ͍ͯ͠Δͷ͔ w,PUMJOίϧʔνϯͷجຊతͳ࢖͍ํ ࠓ೔࿩͢͜ͱ

Slide 7

Slide 7 text

©2018 Lang-8 Inc. ALL Rights Reserved. wίϧʔνϯͱ͸ͳʹ͔ w,PUMJO͸ͲͷΑ͏ʹίϧʔνϯΛ࣮ݱ ͍ͯ͠Δͷ͔ w,PUMJOίϧʔνϯͷجຊతͳ࢖͍ํ ࠓ೔࿩͢͜ͱ

Slide 8

Slide 8 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯͱ͸ͳʹ͔

Slide 9

Slide 9 text

©2018 Lang-8 Inc. ALL Rights Reserved. w $PCPMίϯύΠϥΛܰྔʹ࣮ ૷͢ΔͨΊʹίϧʔνϯͷ֓೦ Λಋೖͨ͠ w ͋Δ৚݅ԼͰϓϩάϥϜΛ෼཭ ͢Δͱಠཱͯͦ͠ΕͧΕಈ࡞Ͱ ͖Δͱ͍͏ΞΠσΞ w DPSPVUJOFɺͭ·Γର౳ͷϧʔ νϯͱ͍͏ҙຯɻ͓ޓ͍Λݺͼ ग़੍ͯ͠ޚͰ͖Δؔ܎ ϝϧϰΟϯɾίϯ΢ΣΠ ͷ೥ͷ࿦จ͕ॳग़ IUUQNFMDPOXBZDPN)PNFQEGDPNQJMFSQEG

Slide 10

Slide 10 text

©2018 Lang-8 Inc. ALL Rights Reserved. "GUFSZFBSTʜ

Slide 11

Slide 11 text

©2018 Lang-8 Inc. ALL Rights Reserved. w "DPSPVUJOFŠJTBOJOTUBODFPGTVTQFOEBCMF DPNQVUBUJPO*UJTDPODFQUVBMMZTJNJMBSUPB UISFBE JOUIFTFOTFUIBUJUUBLFTBCMPDLPG DPEFUPSVOBOEIBTBTJNJMBSMJGFDZDMFŠJU JTDSFBUFEBOETUBSUFE CVUJUJTOPUCPVOEUP BOZQBSUJDVMBSUISFBE*UNBZTVTQFOEJUT FYFDVUJPOJOPOFUISFBEBOESFTVNFJOBOPUIFS POF.PSFPWFS MJLFBGVUVSFPSQSPNJTF JU NBZDPNQMFUFXJUITPNFSFTVMUPSFYDFQUJPO $PSPVUJOFTGPS,PUMJOʹΑΔͱʜ IUUQTHJUIVCDPN,PUMJOLPUMJODPSPVUJOFTCMPCNBTUFSLPUMJODPSPVUJOFTJOGPSNBMNEUFSNJOPMPHZ

Slide 12

Slide 12 text

©2018 Lang-8 Inc. ALL Rights Reserved. w ίϧʔνϯ͸ɺҰ࣌ఀࢭՄೳͳܭࢉͷΠϯελϯεͰ͢ɻͦ Ε͸֓೦తʹ͸εϨουʹࣅ͍ͯ·͢ɻͭ·Γɺ࣮ߦ͢Δίʔ υϒϩοΫΛ࣋ͪɺಉ༷ͷϥΠϑαΠΫϧΛ࣋ͪɺ࡞੒͞Ε ىಈ͞Ε·͕͢ɺಛఆͷεϨουʹଋറ͞Ε͍ͯ·ͤΜɻ͋ ΔεϨουͰ࣮ߦΛதஅ͠ɺผͷεϨουͰ࠶։͢Δ͜ͱ͕ ͋Γ·͢ɻ͞Βʹɺ'VUVSF΍1SPNJTTͷΑ͏ʹɺԿΒ͔ ͷ݁Ռ΍ྫ֎͕͋Δ৔߹͕͋Γ·͢ɻ $PSPVUJOFTGPS,PUMJOʹΑΔͱʜ IUUQTHJUIVCDPN,PUMJOLPUMJODPSPVUJOFTCMPCNBTUFSLPUMJODPSPVUJOFTJOGPSNBMNEUFSNJOPMPHZ

Slide 13

Slide 13 text

©2018 Lang-8 Inc. ALL Rights Reserved. w ίϧʔνϯ͸ɺҰ࣌ఀࢭՄೳͳܭࢉͷΠϯελϯεͰ͢ɻͦ Ε͸֓೦తʹ͸εϨουʹࣅ͍ͯ·͢ɻͭ·Γɺ࣮ߦ͢Δίʔ υϒϩοΫΛ࣋ͪɺಉ༷ͷϥΠϑαΠΫϧΛ࣋ͪɺ࡞੒͞Ε ىಈ͞Ε·͕͢ɺಛఆͷεϨουʹଋറ͞Ε͍ͯ·ͤΜɻ͋ ΔεϨουͰ࣮ߦΛதஅ͠ɺผͷεϨουͰ࠶։͢Δ͜ͱ͕ ͋Γ·͢ɻ͞Βʹɺ'VUVSF΍1SPNJTTͷΑ͏ʹɺԿΒ͔ ͷ݁Ռ΍ྫ֎͕͋Δ৔߹͕͋Γ·͢ɻ $PSPVUJOFTGPS,PUMJOʹΑΔͱʜ IUUQTHJUIVCDPN,PUMJOLPUMJODPSPVUJOFTCMPCNBTUFSLPUMJODPSPVUJOFTJOGPSNBMNEUFSNJOPMPHZ

Slide 14

Slide 14 text

©2018 Lang-8 Inc. ALL Rights Reserved. wαϒϧʔνϯͱҟͳΓɺঢ়ଶ؅ཧΛ ҙࣝͤͣʹߦ͑ΔͨΊɺڠௐతॲཧɺ ΠςϨʔλɺແݶϦετɺύΠϓͳ Ͳɺܧଓঢ়گΛ࣋ͭϓϩάϥϜ͕༰ қʹهड़Ͱ͖Δɻ 8JLJQFEJBʹΑΔͱʜ IUUQTKBXJLJQFEJBPSHXJLJ&#&"#&#$&&#

Slide 15

Slide 15 text

©2018 Lang-8 Inc. ALL Rights Reserved. wαϒϧʔνϯͱҟͳΓɺঢ়ଶ؅ཧΛ ҙࣝͤͣʹߦ͑ΔͨΊɺڠௐతॲཧɺ ΠςϨʔλɺແݶϦετɺύΠϓͳ Ͳɺܧଓঢ়گΛ࣋ͭϓϩάϥϜ͕༰ қʹهड़Ͱ͖Δɻ 8JLJQFEJBʹΑΔͱʜ IUUQTKBXJLJQFEJBPSHXJLJ&#&"#&#$&&#

Slide 16

Slide 16 text

©2018 Lang-8 Inc. ALL Rights Reserved. wҰ࣌ఀࢭՄೳͳܭࢉͷΠϯελϯε wεϨουͷΑ͏ʹ࣮ߦ͢ΔίʔυϒϩοΫΛ࣋ͪɺಉ ༷ͷϥΠϑαΠΫϧΛ࣋ͪɺ࡞੒͞Εىಈ͞ΕΔ͕ɺ ಛఆͷεϨουʹଋറ͞Εͳ͍ w'VUVSF΍1SPNJTTͷΑ͏ʹɺԿΒ͔ͷ݁Ռ΍ྫ֎ ͕͋Δ৔߹͕͋Δ wܧଓঢ়گΛ࣋ͭϓϩάϥϜ͕༰қʹهड़Ͱ͖Δ ίϧʔνϯͱ͸ʜ

Slide 17

Slide 17 text

©2018 Lang-8 Inc. ALL Rights Reserved. Ұ࣌ఀࢭՄೳͳܭࢉͷΠϯελϯε fun loadProfile(id: Int) { val profile = getProfile(id) showProfile(profile) } αϒϧʔνϯ ίϧʔνϯ ։͔࢝ΒϦλʔϯ·Ͱ͕Ұ ͭͷॲཧ୯Ґ தஅ ࠶։ ॲཧͷ్தͰҰ࣌ఀࢭ ͕Մೳ launch { val profile = getProfile(id).await() showProfile(profile) }

Slide 18

Slide 18 text

©2018 Lang-8 Inc. ALL Rights Reserved. εϨουͱίϧʔνϯ Thread { val profile = getProfile(token) showProfile(profile) }.start() εϨου ίϧʔνϯ ίʔυϒϩοΫͱϥΠϑα ΠΫϧΛ࣋ͪɺ࡞੒ͱىಈ ͕͞ΕΔ εϨουʹࣅ͍ͯΔ͕ ಛఆͷεϨουʹଋറ ͞Εͳ͍ launch { val profile = getProfile(token).await() showProfile(profile) } ͲͷεϨουͰ࣮ߦ͞ΕΔ͔͸ίϧʔνϯࣗ਎͸ؾʹ͠ͳ͍

Slide 19

Slide 19 text

©2018 Lang-8 Inc. ALL Rights Reserved. 'VUVSF΍1SPNJTTͷΑ͏ʹ஋Λฦ͢৔߹͕͋Δ fun getProfile(id: Int) = async { //… return profile } launch { val profile = getProfile(id).await() showProfile(profile) }

Slide 20

Slide 20 text

©2018 Lang-8 Inc. ALL Rights Reserved. 'VUVSF΍1SPNJTTͷΑ͏ʹ஋Λฦ͢৔߹͕͋Δ ஋Λฦ͢ίϧʔνϯ fun getProfile(id: Int) = async { //… return profile } launch { val profile = getProfile(id).await() showProfile(profile) }

Slide 21

Slide 21 text

©2018 Lang-8 Inc. ALL Rights Reserved. 'VUVSF΍1SPNJTTͷΑ͏ʹ஋Λฦ͢৔߹͕͋Δ fun getProfile(id: Int) = async { //… return profile } launch { val profile = getProfile(id).await() showProfile(profile) } ผͷίϧʔνϯΛىಈͯࣗ͠਎͸தஅ ͠ɺ݁ՌΛड͚औͬͯ࠶։͢Δ

Slide 22

Slide 22 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜ͕ ༰қʹهड़Ͱ͖Δ

Slide 23

Slide 23 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun loadProfile(id: Int) { val profile = getProfile(id) showProfile(profile) }

Slide 24

Slide 24 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ ஞ࣮࣍ߦ fun loadProfile(id: Int) { val profile = getProfile(id) showProfile(profile) }

Slide 25

Slide 25 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ ௨৴ॲཧ΍%#ΞΫηεɺॏ͍ͨܭࢉͳͲΛ ߦ͏৔߹ɺϒϩοΩϯάͯ͠͠·͏ɻ fun loadProfile(id: Int) { val profile = getProfile(id) showProfile(profile) }

Slide 26

Slide 26 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun getProfile(id: Int, f: (Profile) -> Unit) fun loadProfile(id: Int) { val profile = getProfile(id) showProfile(profile) } ίʔϧόοΫΛड͚औΔܗʹͯ͠ʜ

Slide 27

Slide 27 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun getProfile(id: Int, f: (Profile) -> Unit) fun loadProfile(id: Int) { getProfile(token) { profile -> showProgile(profile) } } ϒϩοΩϯά͠ͳ͍ܗʹ͢Δ

Slide 28

Slide 28 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun getProfile(id: Int, f: (Profile) -> Unit) fun loadProfile(id: Int) { getProfile(token) { profile -> showProgile(profile) } }

Slide 29

Slide 29 text

©2018 Lang-8 Inc. ALL Rights Reserved. お分かりいただけただろうか・・・

Slide 30

Slide 30 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun getProfile(id: Int, f: (Profile) -> Unit) fun loadProfile(id: Int) { getProfile(token) { profile -> showProgile(profile) } }

Slide 31

Slide 31 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun getProfile(id: Int, f: (Profile) -> Unit) fun loadProfile(id: Int) { getProfile(token) { profile -> showProgile(profile) } } ؔ਺͸͜͜ͰҰ౓தஅ͍ͯ͠Δʂ

Slide 32

Slide 32 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun getProfile(id: Int, f: (Profile) -> Unit) fun loadProfile(id: Int) { getProfile(token) { profile -> showProgile(profile) } } ࠶։͍ͯ͠Δʜ

Slide 33

Slide 33 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ࣋ͭϓϩάϥϜͱ͸ fun getProfile(id: Int, f: (Profile) -> Unit) fun loadProfile(id: Int) { getProfile(token) { profile -> showProgile(profile) } } ܧଓঢ়گΛ࣋ͭϓϩάϥϜͬ

Slide 34

Slide 34 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ༰қʹॻ͘ fun loadProfile(id: Int) { val profile = getProfile(id) showProfile(profile) }

Slide 35

Slide 35 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ༰қʹॻ͘ fun loadProfile(id: Int) { val profile = getProfile(id).await() showProfile(profile) } ˞ٖࣅίʔυͰ͢

Slide 36

Slide 36 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ༰қʹॻ͘ fun loadProfile(id: Int) { val profile = getProfile(id).await() showProfile(profile) } ˞ٖࣅίʔυͰ͢ HFU1SPpMFؔ਺͕ฦ͢ίϧʔν ϯʹ੍ޚΛ౉ࣗ͠਎͸தஅ͢Δ

Slide 37

Slide 37 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ༰қʹॻ͘ fun loadProfile(id: Int) { val profile = getProfile(id).await() showProfile(profile) } ˞ٖࣅίʔυͰ͢ HFU1SPpMFؔ਺͕ฦ͢ίϧʔν ϯ͸ผͷεϨουͰಈ࡞͍ͯ͠ Δ͔΋͠Εͳ͍ͯ͠͠ͳ͍͔΋ ͠Εͳ͍

Slide 38

Slide 38 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ༰қʹॻ͘ fun loadProfile(id: Int) { val profile = getProfile(id).await() showProfile(profile) } ˞ٖࣅίʔυͰ͢ HFU1SPpMFؔ਺͕׬ྃͨ͠Β஋ Λड͚औΔͱ͜Ζ͔Β࠶։

Slide 39

Slide 39 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گΛ༰қʹॻ͘ ίϧʔνϯ BTZODBXBJU fun loadProfile(id: Int) { getProfile(token) { profile -> showProgile(profile) } } ίʔϧόοΫελΠϧ fun loadProfile(id: Int) { val profile = getProfile(id).await() showProfile(profile) } ˞ٖࣅίʔυͰ͢

Slide 40

Slide 40 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گ͕૿͑ͯ΋ fun loadProfile(id: Int) { getProfile(id) { profile -> getReport(profile.id) { report -> //.. } } } } } } ίʔϧόοΫελΠϧ

Slide 41

Slide 41 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓঢ়گ͕૿͑ͯ΋ ίϧʔνϯ BTZODBXBJU fun loadProfile(id: Int) { val profile = getProfile(id).await() val report = getReport(profile.id).await() val a = getA().await() val b = getB().await() val c = getC().await() //… } ˞ٖࣅίʔυͰ͢

Slide 42

Slide 42 text

©2018 Lang-8 Inc. ALL Rights Reserved. wδΣωϨʔλɺετϦʔϜ wνϟϯωϧ wΞΫλʔϞσϧ wύΠϓϥΠϯ wFUDʜ ܧଓঢ়گΛ؆୯ʹॻ͚Δ͜ͱͰ ࣮૷ָ͕ʹͳΔ΋ͷͨͪ

Slide 43

Slide 43 text

©2018 Lang-8 Inc. ALL Rights Reserved. wҰ࣌ఀࢭՄೳͳܭࢉͷΠϯελϯε wεϨουͷΑ͏ʹ࣮ߦ͢ΔίʔυϒϩοΫΛ࣋ͪɺಉ ༷ͷϥΠϑαΠΫϧΛ࣋ͪɺ࡞੒͞Εىಈ͞ΕΔ͕ɺ ಛఆͷεϨουʹଋറ͞Εͳ͍ w'VUVSF΍1SPNJTTͷΑ͏ʹɺԿΒ͔ͷ݁Ռ΍ྫ֎ ͕͋Δ৔߹͕͋Δ wܧଓঢ়گΛ࣋ͭϓϩάϥϜ͕༰қʹهड़Ͱ͖Δ ίϧʔνϯͱ͸ʜ

Slide 44

Slide 44 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJO͸ͲͷΑ͏ʹ ίϧʔνϯΛ࣮ݱ͍ͯ͠Δͷ͔ʁ

Slide 45

Slide 45 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJO͸ͲͷΑ͏ʹ ίϧʔνϯΛ࣮ݱ͍ͯ͠Δͷ͔ʁ fun loadProfile(id: Int) { val profile = getProfile(id).await() showProfile(profile) } )PX

Slide 46

Slide 46 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJO͸+7.ݴޠ

Slide 47

Slide 47 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJOίϯύΠϥ͸ +BWBόΠτίʔυΛग़ྗ͢ Δ

Slide 48

Slide 48 text

©2018 Lang-8 Inc. ALL Rights Reserved. ͭ·Γ,PUMJOͷίϧʔνϯ ͸+BWBͰ࣮૷Ͱ͖Δܗʹ ͳ͍ͬͯΔ͸ͣ

Slide 49

Slide 49 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJO͸ͲͷΑ͏ʹ ίϧʔνϯΛ+BWBͰ࣮ݱͯ͠ ͍Δͷ͔ʁ

Slide 50

Slide 50 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯΛ εςʔτϚγϯʹม׵͍ͯ͠Δ IUUQTHJUIVCDPN,PUMJOLPUMJODPSPVUJOFTCMPCNBTUFSLPUMJODPSPVUJOFTJOGPSNBMNE

Slide 51

Slide 51 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯΛεςʔτϚγϯʹ͢Δ fun simpleCoroutine() { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") }

Slide 52

Slide 52 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯΛεςʔτϚγϯʹ͢Δ fun simpleCoroutine() { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ͜͜Ͱதஅ͢Δͱ͢Δ

Slide 53

Slide 53 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯΛεςʔτϚγϯʹ͢Δ fun simpleCoroutine() { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ̎ͭͷঢ়ଶʹ෼ղͰ͖Δ ̎ͭͷঢ়ଶʹ෼ղͰ͖Δ

Slide 54

Slide 54 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯΛεςʔτϚγϯʹ͢Δ fun simpleCoroutine() { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ̎ͭͷঢ়ଶʹ෼ղͰ͖Δ ԣஅతʹར༻͢Δม਺

Slide 55

Slide 55 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯΛεςʔτϚγϯʹ͢Δ class SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTimeMillis() println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.currentTimeMillis() - start}”) label++ } } } }

Slide 56

Slide 56 text

©2018 Lang-8 Inc. ALL Rights Reserved. ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } }

Slide 57

Slide 57 text

©2018 Lang-8 Inc. ALL Rights Reserved. ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } } ̎ͭͷঢ়ଶΛ࣋ͭ ̎ͭͷঢ়ଶΛ࣋ͭ

Slide 58

Slide 58 text

©2018 Lang-8 Inc. ALL Rights Reserved. ݱࡏͷঢ়ଶΛ࣋ͭ ݱࡏͷঢ়ଶΛද͢ ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } }

Slide 59

Slide 59 text

©2018 Lang-8 Inc. ALL Rights Reserved. ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } } ݱࡏΛมԽͤ͞Δ

Slide 60

Slide 60 text

©2018 Lang-8 Inc. ALL Rights Reserved. ڞ௨ͯ͠࢖͏ม਺ ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } }

Slide 61

Slide 61 text

©2018 Lang-8 Inc. ALL Rights Reserved. ॲཧΛ࠶։͢Δؔ਺ ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } }

Slide 62

Slide 62 text

©2018 Lang-8 Inc. ALL Rights Reserved. ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } }

Slide 63

Slide 63 text

©2018 Lang-8 Inc. ALL Rights Reserved. fun delay(delayTime: Long, coroutine: SimpleCoroutine) { Thread { Thread.sleep(delayTime) coroutine.resume() }.start() }

Slide 64

Slide 64 text

©2018 Lang-8 Inc. ALL Rights Reserved. fun delay(delayTime: Long, coroutine: SimpleCoroutine) { Thread { Thread.sleep(delayTime) coroutine.resume() }.start() } ࠶։ͷͨΊʹ4JNQMF$PSPVUJOF Λड͚औ͓ͬͯ͘

Slide 65

Slide 65 text

©2018 Lang-8 Inc. ALL Rights Reserved. ࢦఆ͞Εͨ࣌ؒεϦʔϓͯ͠ 4JNQMF$PSPVUJOFΛ࠶։͢Δ fun delay(delayTime: Long, coroutine: SimpleCoroutine) { Thread { Thread.sleep(delayTime) coroutine.resume() }.start() }

Slide 66

Slide 66 text

©2018 Lang-8 Inc. ALL Rights Reserved. ass SimpleCoroutine { var label = 0 var start = 0L fun resume() { when (label) { 0 -> { start = System.currentTi println(“start") label++ delay(1000, this) } 1 -> { println("end ${System.cu label++ } } }

Slide 67

Slide 67 text

©2018 Lang-8 Inc. ALL Rights Reserved. val simpleCoroutine = SimpleCoroutine() simpleCoroutine.resume() fun simpleCoroutine() { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ίϧʔνϯ εςʔτϚγϯ

Slide 68

Slide 68 text

©2018 Lang-8 Inc. ALL Rights Reserved. val simpleCoroutine = SimpleCoroutine() simpleCoroutine.resume() fun simpleCoroutine() { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ίϧʔνϯ εςʔτϚγϯ TUBSU FOE TUBSU FOE

Slide 69

Slide 69 text

©2018 Lang-8 Inc. ALL Rights Reserved. εςʔτϚγϯͰίϧʔνϯΛ࣮ݱ͢Δ wதஅͱ࠶։Λঢ়ଶભҠͱݟཱͯΔ w࠶։ʹඞཁͳ৘ใΛεςʔτϚγϯ಺ʹ Ωϟϓνϟ͢Δ w಺෦ঢ়ଶΛมԽͤ͞ͳ͕Β࣮ߦ͢Δ

Slide 70

Slide 70 text

©2018 Lang-8 Inc. ALL Rights Reserved. Ͳ͏΍ͬͯίϧʔνϯΛ εςʔτϚγϯʹม׵͢Δͷ͔

Slide 71

Slide 71 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEम০ࢠͱ ܧଓ

Slide 72

Slide 72 text

©2018 Lang-8 Inc. ALL Rights Reserved. wίϧʔνϯΛϚʔΩϯά͢ΔͨΊʹTVTQFOEम ০ࢠΛಋೖ wϥϜμࣜʹTVTQFOEम০ࢠΛ෇༩͢Δͱίϧʔ νϯຊମΛද͢ TVTQFOEϥϜμ  wؔ਺ʹ෇༩͢Δͱதஅ͢Δ৔ॴΛද͢ɻͦͷؔ਺Λ TVTQFOEؔ਺ͱݺͿ wTVTQFOEؔ਺͸TVTQFOEؔ਺ϥϜμ͔Β͔͠ ݺͼग़ͤͳ͍ TVTQFOEम০ࢠ

Slide 73

Slide 73 text

©2018 Lang-8 Inc. ALL Rights Reserved. wίϧʔνϯࣗ਎ΛܧଓΦϒδΣΫτʹ͢Δ wTVTQFOEؔ਺Λܧଓ౉͠ελΠϧ $POUJOVBUJPO1BTTJOH4UZMF $14 ʹม׵͢Δ wTVTQFOEؔ਺಺ͰܧଓΦϒδΣΫτΛऔΓ ग़ͯ͠೚ҙʹ࠶։Ͱ͖ΔΑ͏ʹ͢Δ ܧଓ

Slide 74

Slide 74 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEؔ਺ͱ$14 fun delay(delayTime: Long, coroutine: SimpleCoroutine) { Thread { Thread.sleep(delayTime) coroutine.resume() }.start() }

Slide 75

Slide 75 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEؔ਺ͱ$14 suspend fun delay(delayTime: Long) { Thread { Thread.sleep(delayTime) coroutine.resume() }.start() }

Slide 76

Slide 76 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEؔ਺ͱ$14 suspend fun delay(delayTime: Long) { Thread { Thread.sleep(delayTime) coroutine.resume() }.start() } // c: Continuation ίϯύΠϧ࣌ʹࣗಈͰ ܧଓΠϯλϑΣʔεͷ Ҿ਺͕૿͑Δ

Slide 77

Slide 77 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEؔ਺ͱ$14 suspend fun delay(delayTime: Long) { // c: Continuation suspendCoroutine { c -> Thread { Thread.sleep(delayTime) c.resume(Unit) }.start() } }

Slide 78

Slide 78 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEؔ਺ͱ$14 suspend fun delay(delayTime: Long) { // c: Continuation suspendCoroutine { c -> Thread { Thread.sleep(delayTime) c.resume(Unit) }.start() } } ܧଓΠϯλϑΣʔεΛऔΓग़͢ ͨΊʹ༻ҙ͞Ε͍ͯΔؔ਺

Slide 79

Slide 79 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEؔ਺ͱ$14 suspend fun delay(delayTime: Long) { // c: Continuation suspendCoroutine { c -> Thread { Thread.sleep(delayTime) c.resume(Unit) }.start() } } ܧଓΠϯλϑΣʔεΛ࢖ͬͯ࠶։ ॲཧΛߦ͏

Slide 80

Slide 80 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") }

Slide 81

Slide 81 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } }

Slide 82

Slide 82 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } } TVTQFOEϥϜμʹΑͬͯίϧʔνϯͷ ൣғ͕ܾ·Δɻ

Slide 83

Slide 83 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } f.startCoroutine(NoOpCompletion) }

Slide 84

Slide 84 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } f.startCoroutine(NoOpCompletion) } TVTQFOEϥϜμͷ֦ுؔ਺͕͍͔ͭ͘༻ ҙ͞Ε͍ͯΔɻTUBSU$PSPVUJOFؔ਺ʹΑͬ ͯίϧʔνϯΛ։࢝Ͱ͖Δ

Slide 85

Slide 85 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } f.startCoroutine(NoOpCompletion) } TUBSU$PSPVUJOFؔ਺͸$POUJOVBUJPO ΛҾ਺ʹऔΔɻίϧʔνϯ͕׬ྃͨ͠Βݺ ͼग़͞ΕΔ

Slide 86

Slide 86 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } f.startCoroutine(NoOpCompletion) } ৑௕ʹͳΔͨΊศ্ٓ༻ҙ ͨ͠Ϋϥε object NoOpCompletion : Continuation { override val context: CoroutineContext = EmptyCoroutineContext override fun resume(value: T) { // no op } override fun resumeWithException(exception: Throwable) { // no op }

Slide 87

Slide 87 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } f.startCoroutine(NoOpCompletion) }

Slide 88

Slide 88 text

©2018 Lang-8 Inc. ALL Rights Reserved. TVTQFOEϥϜμͱίϧʔνϯ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } f.startCoroutine(NoOpCompletion) } TUBSU FOE

Slide 89

Slide 89 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯϏϧμʔͱ ܧଓΠϯλʔηϓλʔ

Slide 90

Slide 90 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯΛ࡞Δͷ͸ΊΜͲ͍͘͞ fun simpleCoroutine() { val f: suspend () -> Unit = { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } f.startCoroutine(NoOpCompletion) }

Slide 91

Slide 91 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯϏϧμʔ fun simpleCoroutine() { launch { val start = System.currentTimeMillis() println(“start") delay(1000) println("end ${System.currentTimeMillis() - start}”) } } ͦΕͧΕͷੑ࣭Λ΋ͭίϧʔνϯϏϧμʔ ͕ίϧʔνϯඪ४ϥΠϒϥϦͰఏڙ͞ΕΔ ͷͰීஈ͸ͦͪΒΛ࢖͏͜ͱʹͳΔɻ

Slide 92

Slide 92 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓΠϯλʔηϓλʔͱ ࣮ߦεϨου launch(CommonPool) { // … } launch(UI) { // … } launch(JavaFx) { // … } launch(Swing) { // … } async(CommonPool) { // … }

Slide 93

Slide 93 text

©2018 Lang-8 Inc. ALL Rights Reserved. ܧଓΠϯλʔηϓλʔͱ ࣮ߦεϨου launch(CommonPool) { // … } launch(UI) { // … } launch(JavaFx) { // … } launch(Swing) { // … } async(CommonPool) { // … } ίϧʔνϯϏϧμʔʹܧଓΠϯ λʔηϓλʔΛ౉࣮ͯ͠ߦεϨο υΛίϯτϩʔϧͰ͖Δ

Slide 94

Slide 94 text

©2018 Lang-8 Inc. ALL Rights Reserved. wίϧʔνϯΛεςʔτϚγϯʹม׵͠ ͍ͯΔ wม׵ͷͨΊʹTVTQFOEम০ࢠͱܧ ଓΛಋೖͨ͠ wܧଓΠϯλʔηϓλʔʹΑΓɺ࣮ߦͷ εϨουΛݶఆ͠ͳ͍ ,PUMJO͸ͲͷΑ͏ʹ ίϧʔνϯΛ+BWBͰ࣮ݱ͍ͯ͠Δͷ͔ʁ

Slide 95

Slide 95 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJOίϧʔνϯͷ جຊతͳ࢖͍ํ

Slide 96

Slide 96 text

©2018 Lang-8 Inc. ALL Rights Reserved. ,PUMJO͔Βొ৔

Slide 97

Slide 97 text

©2018 Lang-8 Inc. ALL Rights Reserved. ֤छػೳ͸ϥΠϒϥϦͰఏڙ wDPSF SFBDUJWF OBUJWF VJ KTͳͲ ͷϞδϡʔϧʹ෼͔Ε͍ͯΔ IUUQTHJUIVCDPN,PUMJOLPUMJOYDPSPVUJOFT

Slide 98

Slide 98 text

©2018 Lang-8 Inc. ALL Rights Reserved. ಛఆͷ؀ڥ޲͚ͷϥΠϒϥϦ΋͋Δ w"OESPJE +BWB'Y 4XJOH޲͚͕༻ҙ͞ Ε͍ͯΔ ܧଓΠϯλʔηϓλʔͷ࣮૷ IUUQTHJUIVCDPN,PUMJOLPUMJOYDPSPVUJOFTUSFFNBTUFSVJ

Slide 99

Slide 99 text

©2018 Lang-8 Inc. ALL Rights Reserved. wLPUMJOYDPSPVUJOFTFYQFSJNFOUBMύοέʔ δʹؔ࿈͢ΔΫϥε͕͋Δ wຊ൪౤ೖʹ͸ͦΕͳΓʹ֮ޛ͕ඞཁ͕ͩͬͨ FYQFSJNFOUBM࿮Ͱఏڙ

Slide 100

Slide 100 text

©2018 Lang-8 Inc. ALL Rights Reserved. ͰTUBCMFʹͳΔ༧ఆʂʂ

Slide 101

Slide 101 text

©2018 Lang-8 Inc. ALL Rights Reserved.

Slide 102

Slide 102 text

©2018 Lang-8 Inc. ALL Rights Reserved. ˞ࠓճ͸·ͩFYQFSJNFOUBMͷ؀ڥͷํͰղઆ͠·͢

Slide 103

Slide 103 text

©2018 Lang-8 Inc. ALL Rights Reserved. ؀ڥߏங kotlin { experimental { coroutines 'enable' } } dependencies { implementation”org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.60" implementation “org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0" // platformʹ߹Θͤͯ௥Ճ implementation “org.jetbrains.kotlinx:kotlinx-coroutines-android:0.24.0" } BQQCVJMEHSBEMF

Slide 104

Slide 104 text

©2018 Lang-8 Inc. ALL Rights Reserved. ؀ڥߏங kotlin { experimental { coroutines 'enable' } } dependencies { implementation”org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.60" implementation “org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0" // platformʹ߹Θͤͯ௥Ճ implementation “org.jetbrains.kotlinx:kotlinx-coroutines-android:0.24.0" } BQQCVJMEHSBEMF ແͯ͘΋ಈ͚͘Ͳ*%&্ͱ ͔Ͱܯࠂ͕ͰΔ

Slide 105

Slide 105 text

©2018 Lang-8 Inc. ALL Rights Reserved. $PSFϥΠϒϥϦ͕ఏڙ͢ΔίϧʔνϯϏϧμʔ

Slide 106

Slide 106 text

©2018 Lang-8 Inc. ALL Rights Reserved. $PSFϥΠϒϥϦ͕ఏڙ͢ΔίϧʔνϯϏϧμʔ

Slide 107

Slide 107 text

©2018 Lang-8 Inc. ALL Rights Reserved. ࠷ॳͷίϧʔνϯ launch { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") }

Slide 108

Slide 108 text

©2018 Lang-8 Inc. ALL Rights Reserved. ࠷ॳͷίϧʔνϯ launch { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ίϧʔνϯϏϧμʔ

Slide 109

Slide 109 text

©2018 Lang-8 Inc. ALL Rights Reserved. w݁ՌΛ࣋ͨͳ͍ίϧʔνϯΛ࡞੒͢Δί ϧʔνϯϏϧμʔؔ਺ MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job

Slide 110

Slide 110 text

©2018 Lang-8 Inc. ALL Rights Reserved. MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job ίϧʔνϯຊମɻ$PSPVUJOF4DPQFͷ֦ு TVTQFOEϥϜμ

Slide 111

Slide 111 text

©2018 Lang-8 Inc. ALL Rights Reserved. MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job ίϧʔνϯͷ࣮ߦίϯςΩετɺڞ༗σʔ λ΍ܧଓΠϯλʔηϓλʔͳͲΛ͜͜Ͱࢦ ఆͰ͖Δ

Slide 112

Slide 112 text

©2018 Lang-8 Inc. ALL Rights Reserved. MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job

Slide 113

Slide 113 text

©2018 Lang-8 Inc. ALL Rights Reserved. %FGBVMU%JTQBUDIFS public actual val DefaultDispatcher: CoroutineDispatcher = if (useCoroutinesScheduler) ExperimentalCoroutineDispatcher() else CommonPool

Slide 114

Slide 114 text

©2018 Lang-8 Inc. ALL Rights Reserved. %FGBVMU%JTQBUDIFS tcher() else CommonPool

Slide 115

Slide 115 text

©2018 Lang-8 Inc. ALL Rights Reserved. %FGBVMU%JTQBUDIFS tcher() else CommonPool εϨουϓʔϧΛ࢖ͬͯίϧʔνϯΛ࣮ߦ͢Δ ܧଓΠϯλʔηϓλʔɻ࣮ߦ؀ڥͷ$16ίΞ ਺ʹԠͯ͡εϨου਺͸มԽ͢Δ

Slide 116

Slide 116 text

©2018 Lang-8 Inc. ALL Rights Reserved. MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job ίϧʔνϯͷ։࢝ํ๏Λࢦఆ͢ΔɻσϑΥ ϧτͰ͸ଈ࠲ʹ։࢝͢Δ

Slide 117

Slide 117 text

©2018 Lang-8 Inc. ALL Rights Reserved. MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job ىಈͨ͠ίϧʔνϯͷ׬ྃΛ଴ͪ߹Θͤͨ ΓΩϟϯηϧͰ͖Δ

Slide 118

Slide 118 text

©2018 Lang-8 Inc. ALL Rights Reserved. MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job ਌+PCΛઃఆ͢Δɻෳ਺ͷίϧʔνϯ ΛҰׅͰDBODFM͍ͨ࣌͠ͳͲʹ࢖͏

Slide 119

Slide 119 text

©2018 Lang-8 Inc. ALL Rights Reserved. MBVODIؔ਺ public fun launch( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> Unit ): Job ίϧʔνϯͷ׬ྃΛίʔϧόοΫͰड͚औ Γ͍ͨ৔߹ʹࢦఆ͢Δ

Slide 120

Slide 120 text

©2018 Lang-8 Inc. ALL Rights Reserved. ࠷ॳͷίϧʔνϯ launch { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") }

Slide 121

Slide 121 text

©2018 Lang-8 Inc. ALL Rights Reserved. ࠷ॳͷίϧʔνϯ launch { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ඪ४ϥΠϒϥϦ͕ఏڙ͢Δ TVTQFOEؔ਺

Slide 122

Slide 122 text

©2018 Lang-8 Inc. ALL Rights Reserved. ࠷ॳͷίϧʔνϯ launch { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } TUBSU FOE

Slide 123

Slide 123 text

©2018 Lang-8 Inc. ALL Rights Reserved. ίϧʔνϯͱ࣮ߦεϨου launch { val start = System.currentTimeMillis() println("start") delay(1000) println("end ${System.currentTimeMillis() - start}") } ͲͪΒͷঢ়ଶ΋εϨουϓʔ ϧͰ࣮ߦ͞ΕΔ

Slide 124

Slide 124 text

©2018 Lang-8 Inc. ALL Rights Reserved. ྫ͑͹6*Λ৮ΔΑ͏ͳίϧʔνϯͩͱʜ launch { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false }

Slide 125

Slide 125 text

©2018 Lang-8 Inc. ALL Rights Reserved. ྫ͑͹6*Λ৮ΔΑ͏ͳίϧʔνϯͩͱʜ launch { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false } %FGBVMU%JTQBUDIFS͸εϨουϓʔ ϧͰίϧʔνϯΛ࣮ߦ͢Δ

Slide 126

Slide 126 text

©2018 Lang-8 Inc. ALL Rights Reserved. ྫ͑͹6*Λ৮ΔΑ͏ͳίϧʔνϯͩͱʜ launch(UI) { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false }

Slide 127

Slide 127 text

©2018 Lang-8 Inc. ALL Rights Reserved. ྫ͑͹6*Λ৮ΔΑ͏ͳίϧʔνϯͩͱʜ launch(UI) { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false } LPUMJOYDPSPVUJOFTBOESPJE͕ఏڙ͢Δ ܧଓΠϯλʔηϓλʔɻৗʹ6*εϨουͰ࠶։ ͢Δ

Slide 128

Slide 128 text

©2018 Lang-8 Inc. ALL Rights Reserved. ྫ͑͹6*Λ৮ΔΑ͏ͳίϧʔνϯͩͱʜ launch(UI) { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false } 6*εϨουͰ࣮ߦ 6*εϨουͰ࣮ߦ

Slide 129

Slide 129 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU launch(UI) { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false }

Slide 130

Slide 130 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false }

Slide 131

Slide 131 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true delay(1000) prograssBar.isVisible = false } ٖࣅతͳ௨৴ॲཧ

Slide 132

Slide 132 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true val profile = loadProfile() nameText.text = profile.name prograssBar.isVisible = false }

Slide 133

Slide 133 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true val profile = loadProfile() nameText.text = profile.name prograssBar.isVisible = false } ϒϩοΩϯά͢Δ

Slide 134

Slide 134 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } BTZODؔ਺Λ࢖͏

Slide 135

Slide 135 text

©2018 Lang-8 Inc. ALL Rights Reserved. w݁ՌΛ࣋ͭίϧʔνϯΛ࡞੒͢Δίϧʔ νϯϏϧμʔؔ਺ BTZODؔ਺ public fun async( context: CoroutineContext = DefaultDispatcher, start: CoroutineStart = CoroutineStart.DEFAULT, parent: Job? = null, onCompletion: CompletionHandler? = null, block: suspend CoroutineScope.() -> T ): Deferred

Slide 136

Slide 136 text

©2018 Lang-8 Inc. ALL Rights Reserved. %FGFSSFE5 public interface Deferred : Job { //… public suspend fun await(): T //… } தஅͯ݁͠ՌΛ଴ͬͯ࠶։͢Δ

Slide 137

Slide 137 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false }

Slide 138

Slide 138 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false }

Slide 139

Slide 139 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } ܧଓΛड͚औͬͯॲཧͷ׬ྃΛ଴ͭ

Slide 140

Slide 140 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { Thread.sleep(1000) return Profile() } launch(UI) { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } ඇಉظॲཧ͕׬ྃ͢Δͱɺ6*εϨο υͰܧଓΛ࠶։͢Δ

Slide 141

Slide 141 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJU class Profile(val name: String = "Jack") fun loadProfile(): Profile { val profile = http.get(“http:/.”) return profile } launch(UI) { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false }

Slide 142

Slide 142 text

©2018 Lang-8 Inc. ALL Rights Reserved. wMBVODIؔ਺͸݁Ռ͕ແ͍ίϧʔνϯΛɺBTZOD ؔ਺͸݁Ռ͕͋ΔίϧʔνϯΛ࡞Δ wσϑΥϧτͰ͸$PNNPO1PPM͕࢖ΘΕΔͷͰ ඞཁʹԠͯ͡ܧଓΠϯλʔηϓλʔΛηοτ͢ Δ wMBVODIؔ਺ͱBTZODؔ਺Λ૊Έ߹Θͤͯ࢖͏ େମ͜ΕͰࣄ଍ΓΔ ίϧʔνϯͷجຊతͳ࢖͍ํ

Slide 143

Slide 143 text

©2018 Lang-8 Inc. ALL Rights Reserved. BTZODBXBJUͱඇಉظॲཧ

Slide 144

Slide 144 text

©2018 Lang-8 Inc. ALL Rights Reserved. جຊܗ launch(UI) { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false }

Slide 145

Slide 145 text

©2018 Lang-8 Inc. ALL Rights Reserved. ΤϥʔϋϯυϦϯά launch(UI) { ɹtry{ prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: Exception) { showError(e) } }

Slide 146

Slide 146 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛ௚ྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: Exception) { showError(e) } }

Slide 147

Slide 147 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛ௚ྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val token = async { getToken() } val profile = async { loadProfile(token.await()) }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: Exception) { showError(e) } }

Slide 148

Slide 148 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛ௚ྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val token = async { getToken() } val profile = async { loadProfile(token.await()) }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: Exception) { showError(e) } } ͜͜Ͱ͸தஅͤͣ։࢝ ͚͍ͩͯ͠Δ

Slide 149

Slide 149 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛ௚ྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val token = async { getToken() } val profile = async { loadProfile(token.await()) }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: Exception) { showError(e) } } ͜͜Ͱ݁ՌΛ଴͍ͬͯΔ

Slide 150

Slide 150 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛฒྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val profile = async { loadProfile() }.await() val articles = async { loadArticles() }.await() show(profile, articles) prograssBar.isVisible = false } catch (e: Exception) { showError(e) } }

Slide 151

Slide 151 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛฒྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val profile = async { loadProfile() }.await() val articles = async { loadArticles() }.await() show(profile, articles) prograssBar.isVisible = false } catch (e: Exception) { showError(e) } } ௚ྻͰ࣮ߦ͞Εͯ͠·͏

Slide 152

Slide 152 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛฒྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val profile = async { loadProfile() } val articles = async { loadArticles() } show(profile.await(), articles.await()) prograssBar.isVisible = false } catch (e: Exception) { showError(e) } }

Slide 153

Slide 153 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦΫΤετΛฒྻͰ࣮ߦ͢Δ launch(UI) { ɹtry{ prograssBar.isVisible = true val profile = async { loadProfile() } val articles = async { loadArticles() } show(profile.await(), articles.await()) prograssBar.isVisible = false } catch (e: Exception) { showError(e) } } ฒྻͰ։͓͍࢝ͯͯ͠ɺ଴ͪ߹Θͤ Δͱ͜ΖͰҰؾʹBXBJU͢Δ

Slide 154

Slide 154 text

©2018 Lang-8 Inc. ALL Rights Reserved. $BODFM launch(UI) { ɹtry{ prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: Exception) { showError(e) } }

Slide 155

Slide 155 text

©2018 Lang-8 Inc. ALL Rights Reserved. $BODFM val job = launch(UI) { ɹtry { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: CancellationException) { // cancel } catch (e: Exception) { showError(e) } } //… job.cancel()

Slide 156

Slide 156 text

©2018 Lang-8 Inc. ALL Rights Reserved. $BODFM val job = launch(UI) { ɹtry { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: CancellationException) { // cancel } catch (e: Exception) { showError(e) } } //… job.cancel() ίϧʔνϯΛىಈ͢Δͱ͖ʹ+PCΛ ड͚औ͓͚ͬͯ͹೚ҙͷλΠϛϯά ͰΩϟϯηϧ͕Ͱ͖Δ

Slide 157

Slide 157 text

©2018 Lang-8 Inc. ALL Rights Reserved. $BODFM val job = launch(UI) { ɹtry { prograssBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name prograssBar.isVisible = false } catch (e: CancellationException) { // cancel } catch (e: Exception) { showError(e) } } //… job.cancel() Ωϟϯηϧͷྫ֎͕ඈΜͰ͘ΔͷͰ Ωϟον

Slide 158

Slide 158 text

©2018 Lang-8 Inc. ALL Rights Reserved. $BODFM "OESPJEͷྫ class MainActivity : AppCompatActivity() { var job: Job? = null //… fun doSomething(){ job = launch(UI) { … } //… override fun onPause() { job?.cancel() super.onPause() } }

Slide 159

Slide 159 text

©2018 Lang-8 Inc. ALL Rights Reserved. $BODFM "OESPJEͷྫ class MainActivity : AppCompatActivity() { var job: Job? = null //… fun doSomething(){ job = launch(UI) { … } //… override fun onPause() { job?.cancel() super.onPause() } } ϥΠϑαΠΫϧʹ߹Θͤ ͯΩϟϯηϧ

Slide 160

Slide 160 text

©2018 Lang-8 Inc. ALL Rights Reserved. ·ͱΊͯ$BODFM class MainActivity : AppCompatActivity() { var rootJob: Job? = null //… fun doSomething(){ launch(UI, parent = rootJob) { … } fun doSomething2(){ launch(UI, parent = rootJob) { … } //… override fun onResume() { super.onResume() rootJob = Job() } override fun onPause() { rootJob.cancel() super.onPause() }

Slide 161

Slide 161 text

©2018 Lang-8 Inc. ALL Rights Reserved. ·ͱΊͯ$BODFM class MainActivity : AppCompatActivity() { var rootJob: Job? = null override fun onResume() { super.onResume() rootJob = Job() } //… fun doSomething(){ launch(UI, parent = rootJob) { … } fun doSomething2(){ launch(UI, parent = rootJob) { … } //… override fun onPause() { rootJob.cancel() super.onPause() }

Slide 162

Slide 162 text

©2018 Lang-8 Inc. ALL Rights Reserved. ·ͱΊͯ$BODFM class MainActivity : AppCompatActivity() { var rootJob: Job? = null override fun onResume() { super.onResume() rootJob = Job() } //… fun doSomething(){ launch(UI, parent = rootJob) { … } fun doSomething2(){ launch(UI, parent = rootJob) { … } //… override fun onPause() { rootJob.cancel() super.onPause() }

Slide 163

Slide 163 text

©2018 Lang-8 Inc. ALL Rights Reserved. ·ͱΊͯ$BODFM class MainActivity : AppCompatActivity() { var rootJob: Job? = null override fun onResume() { super.onResume() rootJob = Job() } //… fun doSomething(){ launch(UI, parent = rootJob) { … } fun doSomething2(){ launch(UI, parent = rootJob) { … } //… override fun onPause() { rootJob?.cancel() super.onPause() } ·ͱΊͯΩϟϯηϧ

Slide 164

Slide 164 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦτϥΠ launch(UI) { try { progressBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name progressBar.isVisible = false } catch (e: Exception) { showError(e) } }

Slide 165

Slide 165 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦτϥΠ launch(UI) { repeat(3) { try { progressBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name progressBar.isVisible = false return@launch } catch (e: Exception) { if (!shouldRetry(e)) { return@repeat } } } showError() }

Slide 166

Slide 166 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦτϥΠ launch(UI) { repeat(3) { try { progressBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name progressBar.isVisible = false return@launch } catch (e: Exception) { if (!shouldRetry(e)) { return@repeat } } } showError() } GPSจͱҰॹɻ͜Ε͸ί ϧʔνϯͰ͸ͳ͍ɻ

Slide 167

Slide 167 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦτϥΠ launch(UI) { repeat(3) { try { progressBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name progressBar.isVisible = false return@launch } catch (e: Exception) { if (!shouldRetry(e)) { return@repeat } } } showError() } ੒ޭͨ͠ΒMBVODI͔Β ൈ͚Δ

Slide 168

Slide 168 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦτϥΠ launch(UI) { repeat(3) { try { progressBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name progressBar.isVisible = false return@launch } catch (e: Exception) { if (!shouldRetry(e)) { return@repeat } } } showError() } ϦτϥΠ͢΂͖ΤϥʔͰͳ ͍ͳΒSFQFBUΛൈ͚Δ

Slide 169

Slide 169 text

©2018 Lang-8 Inc. ALL Rights Reserved. ϦτϥΠ launch(UI) { repeat(3) { try { progressBar.isVisible = true val profile = async { loadProfile() }.await() nameText.text = profile.name progressBar.isVisible = false return@launch } catch (e: Exception) { if (!shouldRetry(e)) { return@repeat } } } showError() } ϦτϥΠ͕શࣦͯഊ͔ͨ͠Ϧτϥ Π͢΂͖Ͱͳ͍Τϥʔ͕ൃੜ৔߹

Slide 170

Slide 170 text

©2018 Lang-8 Inc. ALL Rights Reserved. wUSZDBUDIͰΤϥʔॲཧ w௚ྻɺฒྻ͸ݺͼग़͠ํͰίϯτϩʔϧ w+PCΛ࢖ͬͯΩϟϯηϧ wϦτϥΠͳͲ΋ϧʔϓͰॲཧͰ͖Δ BTZODBXBJUͱඇಉظॲཧ

Slide 171

Slide 171 text

©2018 Lang-8 Inc. ALL Rights Reserved. ·ͩ·ͩ͋ΔΑίϧʔνϯ

Slide 172

Slide 172 text

©2018 Lang-8 Inc. ALL Rights Reserved. 3FUSPpUΛ%FGFSSFEԽ IUUQTHJUIVCDPN+BLF8IBSUPOSFUSPpULPUMJODPSPVUJOFTBEBQUFS +BLF8IBSUPO੡ɻ$BMM"EBQUFSΛ࣮૷ͯ͠%FGFSSFE Λฦ͢Α͏ʹ͍ͯ͠Δɻ @POST("/api/v1/articles/{id}/like") fun like(@Path(“id") id: Long): Deferred @DELETE(“/api/v1/articles/{id}/like") fun likeCancel(@Path("id") id: Long): Deferred @POST(“/api/v1/users/sign_up”) fun signUp(@Body params: SignUpParameter): Deferred @POST("/api/v1/users/sign_in") fun signIn(@Body params: SignInParameter): Deferred

Slide 173

Slide 173 text

©2018 Lang-8 Inc. ALL Rights Reserved. &WFOU#VTͱ$IBOOFM class EventBus { private val channel = BroadcastChannel(1) fun send(event: Any, context: CoroutineContext = DefaultDispatcher) { launch(context) { channel.send(event) } } fun subscribe(): ReceiveChannel = channel.openSubscription() inline fun subscribeToEvent() = subscribe().filter { it is T }.map { it as T } } IUUQTHJTUHJUIVCDPNTWFOKBDPCTBCEEBCDEB

Slide 174

Slide 174 text

©2018 Lang-8 Inc. ALL Rights Reserved. &WFOU#VTͱ$IBOOFM val bus: EventBus by inject() override fun onResume() { super.onResume() launch(UI, parent = rootJob) { bus.subscribeToEvent().consumeEach { // logged out } } } override fun onPause() { rootJob.cancel() super.onPause() } //… bus.send(LogoutEvent)

Slide 175

Slide 175 text

©2018 Lang-8 Inc. ALL Rights Reserved. PO"DUJWJUZ3FTVMUΛTVTQFOE launch(UI) { val result = activityResult(intent) if (result.isOk) { // ok val data: Intent? = result.flatMap() } else { // ng } } IUUQTHJUIVCDPNQEWSJF[FBOESPJEDPSPVUJOFT BOESPJEDPSPVUJOFTͱ͍͏αʔυύʔςΟϥΠϒϥϦ͕ ఏڙɻSFRVFTU1FSNJTTJPO΋͋ΔΑ

Slide 176

Slide 176 text

©2018 Lang-8 Inc. ALL Rights Reserved. w ܧଓঢ়گΛ࣋ͭϓϩάϥϜ͕༰қʹهड़Ͱ͖ͯศར w ,PUMJO͸ίϧʔνϯΛεςʔτϚγϯʹม׵࣮ͯ͠ݱ͠ ͍ͯΔ w BTZODBXBJUͳͲͷ֤ػೳ͸,PUMJOͷެࣜϥΠϒϥϦ ͕ఏڙ͍ͯ͠Δ w MBVODIؔ਺ͱBTZODؔ਺Ͱେ఍଍ΓΔ w ඞཁʹԠͯࣗ͡෼Ͱίϧʔνϯͷ࢓૊ΈΛ࣮૷Ͱ͖Δɻ͢ ͰʹαʔυύʔςΟϥΠϒϥϦ͕͍͔ͭ͋͘Δ ,PUMJOίϧʔνϯ·ͱΊ

Slide 177

Slide 177 text

©2018 Lang-8 Inc. ALL Rights Reserved. ©2018 Lang-8 Inc. ALL Rights Reserved. &OKPZ,PUMJO$PSPVUJOF

Slide 178

Slide 178 text

©2018 Lang-8 Inc. ALL Rights Reserved. ©2018 Lang-8 Inc. ALL Rights Reserved. ͋Γ͕ͱ͏͍͟͝·ͨ͠