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

Swift Concurrency Talk 2

Swift Concurrency Talk 2

Swift Concurrency Talk 2

[email protected]

March 12, 2021
Tweet

Other Decks in Programming

Transcript

  1. શ߲໨ w$PODVSSFODZ3PBENBQ w"TZODBXBJU wSFBTZOD w4USVDUVSFE$PODVSSFODZ w5BTL"1* wBTZODMFU w$POUJOVBUJPOTGPSJOUFSGBDJOHBTZODUBTLTXJUITZODISPOPVTDPEF w5BTL-PDBM7BMVFT w"DUPS

    w(MPCBM"DUPS w"TZODISPOPVT)BOEMFST w4FOEBCMFBOE!4FOEBCMFDMPTVSFT w1SFWFOUJOH%BUB3BDFTJOUIF4XJGU$PODVSSFODZ.PEFM w$VTUPN&YFDVUPS w"TZOD4FRVFODFT w3FUISPXJOH$POGPSNBODFT w'PMMPXVQPO"TZOD4FRVFODFBOEQBSJUZXJUI4FRVFODFCBTFE"1*T w&GGFDUGVM3FBEPOMZ1SPQFSUJFT w$PODVSSFODZ*OUFSPQFSBCJMJUZXJUI0CKFDUJWF$
  2. ࠓճͷ಺༰ Ͱ͖Δͱ͜Ζ·Ͱʜ w5BTL"1* 4USVDUVSFEDPODVSSFODZ  w5BTL-PDBM7BMVFT w4FOEBCMFBOE!4FOEBCMFDMPTVSFT લճ͔Βͷߋ৽  w"DUPS

    લճ͔Βͷߋ৽  w*NQSPWFEDPOUSPMPWFSBDUPSJTPMBUJPO w$VTUPN&YFDVUPS w&GGFDUGVM3FBEPOMZ1SPQFSUJFT w"TZOD4FRVFODFT w3FUISPXJOH$POGPSNBODFT w'PMMPXVQPO"TZOD4FRVFODFBOEQBSJUZXJUI4FRVFODFCBTFE "1*T
  3. w XJUI(SPVQͷ໭Γ஋͸CPEZͰੜ੒͞Εͨ݁Ռ ΋͘͠͸ ΤϥʔΛUISPX͢Δ  w HSPVQ͸SFUVSO͢Δલʹ௥Ճ͞Εͨશͯͷ5BTLͷ׬ྃΛ BXBJU͢Δ 
 OFYU

    ͕OJMΛฦ͢·Ͱ໌ࣔతʹ݁ՌΛड͚औΔ 
 CPEZ͔ΒͷSFUVSO࣌ʹ҉໧తʹ଴ͭ w σϑΥϧτͰ͸EFGBVMUHMPCBMDPODVSSFOUFYFDVUPS ʹDIJMEUBTLΛ௥Ճ͢Δ͕ɺTUBSUJOH$IJME5BTLT0OͰ FYFDVUPSΛࢦఆ͢Δ͜ͱ΋Ͱ͖Δ 5BTL(SPVQT
  4. 5BTLMPDBMWBMVFMJGFDZDMF w XJUI-PDBMͷείʔϓ಺ είʔϓ಺Ͱ࡞੒͞Εͨ$IJMEɹ 5BTL͕શͯ׬ྃ͢Δ·Ͱ  w ஋ܕ΋ࢀরܕ΋5BTLMPDBMʹઃఆͰ͖Δ 
 ஋ܕ͸ίϐʔ͞ΕͯUBTLMPDBMͷTUPSBHFʹอଘ͞ΕΔ

    
 ࢀরܕ͸ࢀর͕UBTLMPDBMͷTUPSBHFʹอଘ͞ΕΔ w 5BTLMPDBMWBMVFͷTUPSBHF΁ͷϝϞϦͷׂΓ౰ͯ͸ɺUBTL MPDBMͷTUBDLͷൣғ಺ʹݶఆͨ͠ϝϞϦΞϩʔέʔλΛ࢖༻ ͢Δ WBMVFΛઃఆͨ͠5BTLΛ௒͑ͯWBMVF͕ଘଓ͠ͳ͍ͨΊ ʹ࣮ݱՄೳ
  5. 3FBEJOHUBTLMPDBMWBMVFT Ϣʔεέʔε w ͔ͳΓগ਺ͷ5BTL͔͠WBMVFΛಡ·ͳ͍ 
 lSPPUz5BTLͰͷΈWBMVFΛઃఆ 
 େ൒ͷDIJMEUBTL͸͜ͷ৘ใΛඞཁͱ͠ͳ͍ 
 MPPLVQ͢Δ͜ͱͰύϑΥʔϚϯε΁ͷӨڹΛখ͘͞Ͱ͖Δ

    w WBMVFΛઃఆ͢ΔUBTLͱར༻͢Δ5BTLͷؒʹͨ͘͞ΜͷUBTL͕͋Δ 
 GSBNFXPSLͳͲͰར༻ऀʹDPOUSPM fl PXΛ౉͢લʹෳ਺ͷWBMVF͕ઃఆ͞ ΕɺDIJMEUBTL͕͜ͷ৘ใͷΈΛར༻͢Δ 
 WBMVFΛઃఆ͍ͯ͠ͳ͍5BTL΁ͷMPPLVQΛTLJQ͢Δ͜ͱ͕Ͱ͖Δ w WBMVF΁DPODVSSFOUʹΞΫηε͢Δ 
 DIJMEUBTL͕DPODVSSFOUʹWBMVF΁ΞΫηε͢Δ 
 UBTLMPDBMWBMVF͸JNNVUBCMFͰ5BTLੜ੒࣌ʹ஋͕ܾ·͍ͬͯΔͨΊڝ߹͢ Δ৺഑͸ͳ͍
  6. 5ISPXFSSPST ໰୊ ؔ਺΍DMPTVSF͸&SSPSʹద߹ͨ͠ͲΜͳܕͷ஋΋UISPXT͢Δ͜ͱ ͕Ͱ͖ɺ$PODVSSFOUʹؔ਺ DMPTVSF ͕࣮ߦ͞ΕΔ৔߹ɺUISPXO ͞ΕΔ஋΋DPODVSSFOUؒ BDUPSؒͳͲ Ͱ౉͞ΕΔ͜ͱʹͳΔ NZ"DUPSEP4PNFUIJOH3JTLZ

    ͕ଞͷ $PODVSSFODZͳྖҬ͔Βݺ͹Εͨ࣌ɺNZ"DUPSͷ NVUBCMFͳঢ়ଶΛDBQUVSFͯ͠1SPCMFNBUJD&SSPSΛ UISPX͠Α͏ͱ͍ͯ͠Δ"DUPSJTPMBUJPOҧ൓ ۩ମతͳ&SSPSͷܕ৘ใ͕ͳ͘ ࠓͷ··ͩͱ&SSPS͕4FOEBCMFʹద߹͍ͯ͠Δ͔ͷν ΣοΫ͕Ͱ͖ͳ͍
  7. 4UBOEBSE-JCSBSZͷܕ΁ͷద߹ ྫ֎ w .BOBHFE#V ff FSCV ff FS΁ͷNVUBCMFͳࢀরΛఏڙ͢Δͨ Ί4FOEBCMFʹద߹ͯ͠͸͍͚ͳ͍ w

    6OTBGF .VUBCMF #V ff FS 1PJOUFSແ৚݅Ͱ 6OTBGF4FOEBCMFʹద߹͢Δ w -B[ZBMHPSJUINBEBQUFSUZQFT4FOEBCMFʹద߹͠ͳ ͍ɻଟ͘ͷ΋ͷ͸OPO!4FOEBCMFͳDMPTVSFΛҾ਺ʹऔΔͨ Ίɺ҆શʹద߹Ͱ͖ͳ͍BSSBZMB[ZNBQ\ʜ^ͳͲ w ٯʹ্هҎ֎ͷTUSVDU FOVN DMBTT͸4FOEBCMFʹద߹͢Δ Α͏ʹͳΔ
  8. JNQPSUͨ͠$0CKFDUJWF$"1*΁ͷαϙʔτ w $ݴޠͷίʔυ͸҉໧తʹ$PODVSSFOUʹར༻͢Δͷ͸҆ શͰ͸ͳ͍ 4XJGU͔Β$ݴޠ"1*ʹਖ਼͍͠ڍಈΛڧ੍ͤ͞ Δ͜ͱ͕Ͱ͖ͳ͍  w ͔͠͠ɺଟ͘ͷ$ݴޠͷܕʹ҉໧తͳ4FOEBCMF΁ͷద߹ Λఏڙ͢Δ͜ͱͰ$PODVSSFOUʹར༻Ͱ͖ΔΑ͏ʹ͢Δ

    
 $FOVN͸ৗʹ4FOEBCMFʹద߹͢Δ 
 $TUSVDU͸಺෦ͷTUPSFEQSPQFSUZ͕શͯ4FOEBCMFͳΒ͹ 4FOEBCMFʹద߹͢Δ 
 $ؔ਺ϙΠϯλ͸4FOEBCMFʹద߹͢Δ ஋ΛDBQUVSFͰ͖ͳ͍
  9. ͳͥඞཁ ΑΓৄࡉʹίϯτϩʔϧ͕ඞཁͳ৔໘ wΑΓίʔυͷಈ࡞ΛΤϯδχΞ͕໌ࣔతʹࢦఆ͢Δ͜ͱͰ ύϑΥʔϚϯεͷ޲্͢Δ ͔΋͠Εͳ͍ ৔߹ 
 
 ҰͭͷBDUPS͕ଞͷBDUPSʹϦΫΤετΛසൟʹߦ͍ͬͯΔ͕ɺͦͷ BDUPS͕$PODVSSFOUʹಈ࡞ͯ͠΋͋·ΓϝϦοτ͕ͳ͍৔߹͸ಉ͡

    FYFDVUPSͷதͰ࣮ߦͨ͠ํ͕FYFDVUPSΛεΠον͢ΔΑ͏΋ SVOUJNFίετ͕ݮΔ͔΋͠Εͳ͍ 
 
 ͋ΔBTZODؔ਺͕ಉ͡BDPUS΁ͷݺͼग़͠ΛTVTQFOEͳ͠ʹߦͬͯ ͍Δ৔߹ɺ໌ࣔతʹFYFDVUPSΛࢦఆͯ͠FYFDVUPSؒͷεΠονΛ ݮΒ͢͜ͱ͕Ͱ͖Δ
  10. 'PSNBMUSFBUNFOUPGDPODVSSFODZ w 4XJGUͰ͸͋Δఔ౓ɺ$ݴޠͱಉ༷ʹIBQQFOTCFGPSFͰ಺෦ͷ 5ISFBEͷॱ൪ΛܾΊ͍ͯΔɻ w 4XJGUͰ͸શͯͷϝϞϦʹӨڹ͢Δૢ࡞͸ܾ·ͬͨΞΫηεظؒʹ ඥ͍͓ͮͯΓɺݱࡏͷ5ISFBEͰ࣮ߦ͞Ε͍ͯΔଞͷΠϕϯτͱ׬ શʹ௚ྻʹͳΔɻ ಉ࣌ʹى͖Δ͜ͱ͕ͳ͍ 

    w ϝϞϦ΁ͷΞΫηεͷऴΘΓ͕͋ΔΠϕϯτΑΓ΋લʹൃੜͨ͠৔ ߹ɺͦͷϝϞϦ΁ͷ࡞༻΋ͦͷΠϕϯτͷલʹൃੜ͢Δ w ٯʹϝϞϦ΁ͷΞΫηεͷ։͕࢝͋ΔΠϕϯτΑΓ΋ޙʹൃੜͨ͠ ৔߹ɺͦͷϝϞϦ΁ͷ࡞༻΋ͦͷΠϕϯτͷޙʹൃੜ͢Δ
  11. &YFDVUPSTBOEKPCT w શͯͷFYFDVUPS͸͜ͷϓϩτίϧʹద߹͠ͳ͚Ε͹ͳΒͳ͍ w ϝιουͷݺͼग़͠ʹґଘؔ܎͕͋Δ 
 KPCFYFDVUF DVSSFOU&YFDVUPS ͸FORVFVF @

    ͷޙʹݺ͹ͳ͚Ε ͹ͳΒͳ͍ 
 TFSJBMFYFDVUPSͷ৔߹ɺશͯͷKPC͸׬શʹॱংཱͯΔඞཁ͕͋Δɻ KPC"ͷશͯͷΠϕϯτ͸KPC#ΑΓ΋લʹൃੜ͠ͳ͚Ε͹ͳΒͳ͍ɻ
  12. ͳͥඞཁ w DPNQVUFEQSPQFSUZͰඇಉظॲཧ͔Β໭Γ஋ΛಘΔʹ͸ϒϩοΫ͕ඞཁ w GVODUJPOΛ࢖ͬͯXPSLBSPVOEΛ࡞੒Ͱ͖Δ͕ɺޡͬͯHFUUFSΛ࢖ͬͯϒϩ οΫΛҾ͖ى͜͢Մೳੑ΋͋Δ Ҿ਺ TFMGҎ֎ Λ౉ͤͳ͍ DPNQMFUJPOIBOEMFSΛ౉ͤͳ͍

    BTZODΛઃఆ͢Δ͜ͱ͕Ͱ͖Ε͹ɺݺͼग़͠ଆʹ΋େ͖͍DPNQVUBUJPO͕͋Δ͜ ͱΛܕνΣοΫ͔Β఻͑Δ͜ͱ͕Ͱ͖Δ "1*EFTJHOHVJEMJOFʹ΋Ϛον͢Δ IUUQTTXJGUPSHEPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFTHFOFSBMDPOWFOUJPOT