From 34b065520f01e408463feeef77e2315564e80e34 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Thu, 16 Apr 2020 21:36:22 +0900 Subject: [PATCH 001/173] add managed dlls --- Assets/Plugins.meta | 8 +++++ ...System.Runtime.CompilerServices.Unsafe.dll | Bin 0 -> 23600 bytes ...m.Runtime.CompilerServices.Unsafe.dll.meta | 33 ++++++++++++++++++ .../System.Threading.Tasks.Extensions.dll | Bin 0 -> 33048 bytes ...System.Threading.Tasks.Extensions.dll.meta | 33 ++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 Assets/Plugins.meta create mode 100644 Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll create mode 100644 Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta create mode 100644 Assets/Plugins/System.Threading.Tasks.Extensions.dll create mode 100644 Assets/Plugins/System.Threading.Tasks.Extensions.dll.meta diff --git a/Assets/Plugins.meta b/Assets/Plugins.meta new file mode 100644 index 0000000..4d1ab8a --- /dev/null +++ b/Assets/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 14eb6ba721535664b9d31e3a2d7664f9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll b/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll new file mode 100644 index 0000000000000000000000000000000000000000..3156239266db9cceede249731f00c3822e479a1f GIT binary patch literal 23600 zcmeHv2V4|OllW{P=ZwT92MM!eL~@p>BoUCf1PP0~OEi!a5k*juAO=uSR0P3=hrCdY9sDx+=IfUXLNeJ|hiXzhp0VDz?CW;Ui zMX+#kAw-gcNNOA$tg`g1oh>2A9)p8qs!P0POY4EKQfwGD2;v76<{9c&A_xiKH32UI z2q3`D)EmUm`XeEf3|>HQDuzJ2Og2IgH~RZMq@#chc}{?Q?U0BGco~rh{gHqm*a*b^ zAc%dI_8$oeb5%!EF$3IYUV1eeDV_#!JTCy?8`@S-@A(e_l&(ghQUVboQa2NNCsV&W+Uom_4<^PJ*Ysj2(R{q8_?$lS*@hOl$J*94`m6MEG01T|8dRJbH^D!e z))kCB%Nl#@g`;3vJdaM%P2aNW+vhh9*sKg(PxZw&vH2W(xzuE@O4Mc>#jZ02=8pSc zEIrz@`0f2Ga*lpBL;JrtxUZ8_h&K>1T|nH;WI1+`Yb76yftcu3!>-0akf<_*&{$__ zUwJWf@}JPLvuX!naVcmfd@vRQ8i_tw9LQvb4D$Fr9f*<6kCsSJ0ikJr{|$qVM$ zPRF3?h_(qZ;y`~O_6D?u2g}N+jP%c}>SNI|f5dTfV-Uz5l|tu=GS#uvsT2aEe%de7hFJ462|U(X-&Mfk9D_6Uca!5L;auCvmV%6piuQV5O<+b z!lFW`2nRE07-DK=+*}}T5C>KhlCgHPwE!Uj;7y=|WXvMS0RTrHfMTo#u*@uoK&Rw1 zAz+h`(z(EkkYvGY23|zZVelf~=D(rtLe3~mhN3`xFA5t`_y~m) zDCEH)UsX_Oi9!-)C591NgTho4Zbe}!fJiAbWgyZ?!Ei%wFsu*}!~qpxA2FO*Z4d`$ z4`7N|RtUjlp*sX5VIH&?>jLn8I<^F0Sm?_f<^{$oztjxpa%>=Ixgs5l1{fn`GKWO~ z=`N>ZN!S?BPTCxn1bQroj%~nhhB%>OI<^hF14#4~9ovP?2Uyb_Rt)h%Pw3bY@J#?3 zpTmkFVTfINre^inBakRWn8T_e2}p~Mb%JkFko_E14cZ<=#|E(HAO(m<$6jF@AVp}y z9M%jeLAi6BouCIx>DXs%H?$C{pTmYARj6wYdk3jQBXo=d_YU;M7dj@7>xMKTe$W+& zFyWI@N&K{|cNm5!O=zCZ?05FPWvF<}g$csdpZFk@&d9ZLh4DO8ML zP`dCE&_m|XsXt(#XviGoIHGtw!7=Vlr0TRJnz^XwmP(FZs&;^Vd7!^+d zltJM_Xc)vbQD^`O03HK~2%tG+4WJ#g7CNG75`P*nq+w6hb(ZAB83;^h04X z3X4(LfWjUWLU@!Pg(fJJWsn9nyn+>h@X0gQ8xQ1;0b_(0vkUYNV$WwE8K?*OfIc|L z6zB;uyUc`4^pJ%fve82hdI#S?eDqKN4e`L%%zRg(hYRVUD)bJE6sihMpy}1= zbRs>}q=(w{P?sL+(?bJ#Xh;u@>7gk-G^dA_^blI?Kn{wDAQ?d}2~-*>Qf*mG6fG>0 zq-IWzj1G$+QCvur*swqn6`CRV)56G6%SaLa@o0={N(1w1Kn#rpsRh!=6o{T2VFnBV zVG&`pgzr4FWsrg+NP$RBkSUc)iVTQIumWYdlPFX``_4Z5(KafWOo>Db^pE&0muna; zg7kA@3lcSu5*Ce=_VY&v63suzpXUGb7jtrS0wpXYl=iDnpm9<2nl)QbX9|#I;Jg$w z?S;(kT@Zmpg!xC!`{)#~3J3w3m;bCR-KhQ{^II}YclD=)kZ9C@)m3V4QB?n6l3Gwi z#1E{{%ooU!97PwSf53d1&Grvn2k1Ot-2~ZEmy!H~oT4J;H5;Kot`L?71kfn{ptEKp^VsG^$v|Pkq99Ni z&`ppjh2-KNNrECs!88a}B_Kt5C9NqWf6!ppQ2(g!M0-$sl=4G2{5TZp{R^g70%DS& zayGvUr)4Z1&IgWJcuW~Qhwuaph8cXsAQ4Um0v5x`iA1qj35WrNJci6CjD3@M?y@eD z$Dqq)Fil}OOd}%5aSkyNw6N$15+JbHMun1)ehh+`xG@+Bhzm0lax*Y10fd%d<0A&is!~a%*+rDU|bj$B*M+W&A`HhQf5MK1_l;Jv=lKU8JZsC ziA2CJ3pWr|d9Xfnc z*c>*>;!nxDlCJi~ac5s=igQvL(%{_jl3}EONUEXi&Ct6bZ+rHgmyZ=H`UI#PC8>x{ z-7}>5kX2v2Tfef3>uR2%yjUi$IZ2oh*|1Z~VMWJIW*{I?D+rQ6YU7F(^q}}hgJEhJ zA4o!Nmuo1697n~lgQ_Ci9q+3?!iDXbIFG=wuw35dRN z5qp4lrGSwNX<;DsD@Op+k% zsG>zggo8gAg^|=iGKDl_1(7u0J~F^& zo)dUHs4E843Cu#^OB59Hi=28uHW=W&nEla$0ze!B{e>ABM5Ap< z0Fv`Z^FzKnplK-}Ut}r|1|<{FQYfGlGTQp@t&TE)XCS;7g1F(vJW&F#|oZ2$X{Kmp>Sh zL`Vzl3@yM9Vr`rt57fSxLe`)*Fz^{^170Nkj5P=Z{fDGRQ6*D zUBI_MbR2=DFv^ScI1Ok36=3S%Cj``l2J(pkrKwHV8EV9t_%}3F?KkOB>V+u?9#xkS{?1NBEGhy5Q9Y zl7%2WuuQ@L{i336i3GVt02vX0JP^J5KH3oZ!r(>1xn%?}Xy}>I%#cI#`#> zCl(9AsYVivEXwIN=@T3nCTwx45f>n_VKEpY8_dGUu#gjn6=8s2dq&oUj2Jv7RTqoF z7aPHgVWD{xE|>*}fr{}5u*ncCH7^~W|1-YYHSlZiyN7B!WzJ@5b6k?ub}dd7$beJv zkKk0?m0}zgY)$wy!IaCIrd9rV`i@>K(hV3^m}9PD7zR*sc#q6934P+0kXy%Z-(!IH>#9G~#qdYs@2 zoIa{9H2=tGg0s0PEFr`})PwajG&NxGqqhQ}`b6R!3a8xsW6co3p*6#LnEoefqzW%Y zlC$y2ey@=&IOg?_3L-c~lV&y@RDyk2B(fbP%EPiV?BZa*96_QITwPoUmM)Hq^epu) zRkh44U{wuE3z#Se%gi)X?0dHJ8j9>%fNu*<#YoQ=Jca?nrDC{%o?uw9sTd4&d6yJx zi|ozynoZe3{0hqZmPB5TY!x3PG;%lQ)U57HzFyoK5Y%v-<3+FAEtjSa_5Dh*Pm=le zupU~qc@dGCcOv-IWc=zKdlOF&xo5lIsAtVB$Y~!wi1$c#tZJ-XaD~CH_q_O-JU!>; zv#$IF#+=iB3$$2BW4>hb{ozEj%}zHc3fu<1cD%t8Wywmr$Nio^estOmj@8p?I!~>? zXKf?dplh)K+X2?9|~)Pc-r@7ZJK{EV4zQP2_R&)zXPCS!~ryPO)P zn6KCKlrAw!()kuvb^2Dn=W5v}(;xKe-HglX8{csbqiqo(DU2wGVNPhf$f zV-BWbSb#(rU~wQ)aZbD-oA-YJucP z_2}?0gsKj%Ss;!zs`^|vBE5)eD^ON7zydF4WCnwkfq@Bw!P~=2V4GPS#-=Z(7Z4X0 z_p1U(lt0Ot2J<2HmBX{ctg~6-nCGht7^gs8zyiBkf+s2b8(ZHYp?t%FJLL5`8Zp6M zktY1b`h@O{Yd^b{=L*)QzZ}V5g4Ok16j2#txVh{YA*Xk{^`r8Aql;~eXpQ_nnZ;@0 z=h!jc{5?4>mHpG#B|r9a*eTzt(jnb{*MxT+J>P#Nhh4K~o!_A&Bg(E1uU)_45pd`Q z)@ZRSX=~lx$BJK`=$J-dZ9cvL{||x9o4cG?b>L{ z{@7_p!nL+fEaZ-fPI;~Z@NSc4VXwI>ZA4z*45CV zqcH8?QZ>3^#{I@H|4TzuwCtjj$|-S|7DFEyi8E;j_cy#)(&KUR%B1SO%! zv1hH~$HR-B4z>`avb&5p<#H*D;sb-#PW$#g&Y#ZMR-TdXW-l&bbR^7Hl`rtq`o^-O zotKiXFzHLd!8*J0$%mgFE93pRaX3^lOuk5D-`T1Wmw0mHEh4<>MuDtT#n zD|>SH^CkOKX>KC}hbsXmr^A5uEvU03b#)*W47d0yOsas2C4UsR9l-I8YCT^Z}vfw*~-5Y0= zD(s95W*)pPY+Y&zn-i5_1w>ca_~yB}=FK zOxM0_Z|JMA)Xej#o}SufRb$&{&bXjpDfx&7oUWkl++EZJ$LB7&X*b$ z3eFKzSB(TFIOfGs-tMWYt30QAq%>AsVraAcWSr$**|zlFt;%)y1u*Z}rTsSYdpIEu z#p7j9EmUuHZTgmLyUT;!L2Hi;Yj_#jya>8~j#ON5c=J@T!VcQ3=g<_mK7JX=Id6FIA1tTFQK=@m0anY$F|v9<^6 z=9`rS+wr%d6%KY;Wfv0cRu@?_J(`w#wl^l@_ED-u(*2aj?=Ot$ls0=?KB+ox*rOPl zFLJnyLUn&9l-ob8ol7ac7wan#XPLH9Pw)=ai{X68vaGV2F!e_Z*uL(dDfPvwyLR)# zo|7F}0n;tbzE(u%a|(R@Ch%>F61SrC4P8gWVhzKb))GC&joyy#sfx-B8fWe9I|UAQ zs0O^VG#sp8hCW)A>}&VhD(^Cscy!5_)otCydizerd6x<8%WC1tc3*tCg2fltIcvaH z0t2=J=0Yq39|rRc&j8~u798kFPLNE$Ku%~Sb--2+1-Pa;Xl|i&Wcn&6L*FD7jk@G zlzUlSc6s)f&X`Y0#C*b*#pcDP>BfKEmd)uq1*mo)&}`I-xz1WGV8v`;E7)Qd2Ubk) zuUWB~;|XNIAmat(`m_B4XX>8%MoIEkRj_TBJWqSy!Q*6#x z-CI?kFX^a{9xUfLfGczFsm-+W7~5sG=iU1^ub-z&YAvpH-~HA_W}|Xxs@TrHTqg0c zKF7(eB{zro%Cih_@m0MRE?-FrMvk0Uxf`GIiPZ}X(2Z!Xm{~@;Mr=RkGPb zX@4Ja^YTdaL603C>vFS-MQv~^CT<@LVWpMnjH;>&H4RX7dB@4si$hXBEvw1W6eLM- zW_EKw4H_r6S#@;^4JTa1pX&Uq@=P*wUj^%DJ_VEG{hxY|Bw5ul`B{_vOdL;`jW~{; zj7@mJs>Kp1mQ0lF<8jSLY+cKJKg{L?v zS(gtQR$)z6eG4nf>*FrxKBeo-e6P_EPGw{Q_WRAO{T2*Gy!PPY@IPU{VO>}YTv*i5 z)`XF@rv?#4!5v0`{&SoDe`US*mqb)Qdu+2qd2P7bg5C>#Om2p1a)-CKP%k{eb zaJ&6+8cg7M#dOzomw;`qsM(In0&iIU5fnbO=EBHkCawuie8JnzwrYvu>+*w(5=Y$#lz^6kIJ45a(KCyB+k$&feqLrFLMY@yQ zGWLF)%I8%%IdIgb_nz?HsrC2rPYy}tub=GTd(V8Oof3V)%b4D0gZ(z?MIHdrw z?lSn495^K_ng3Vjw|19cIrUZ-1(V} z-Z%@L?%`9%;~uvqEOo$CtI<|_MY8i9YrD86yH>4>_rTW3fLaf1iz9*0xv)FYq|c+S zYWZ%lUU5u%MP2;ZmOCQ`nAd$5vsoFMvTXX^x(IYT9ox}An6>I|^5uctF-G-`xZ&-} zveMC?KYr-1O?%lX-RJtB$B-_g?+sOK^c_R+;AD3wy;k z@djZHRjWL+Yx|{MoIY_g@Kn4jLzk(Vb4BinviM^si}PYc9`4x07bC5%QO+Dy?6pK{ql5lF?{o1x?0z)EiW?R=3)-(|H@^F3|QRy4!H81Z64x%LwrquTttGNk= zH}f5wCZ;Ni!>Ni3fX5dG!|k7QL(KSqfAo@kcR?4Y96*+9bXPSCj>taG0gVS<-tP`- zHXR>D#JtK8u>jSAP^TzS^A z;B|dDw`}LM&Db87YL!RXk)=DKg!XjXXahx_$6@J`lN#k$w=`{y7;WF-)fr);vb-UQ zGAvfyHlf2^l!c;vO}O@I;m4I=a|phthgzf z)QyY9CpTb=?x_x*KYqq6Ksc!JNJ*+3*ehaXzxMzmF%>HSNIa;{ZTrXO_+Oto%+oj@ zSonLbaYVK`gb4%mZBC;Yh+OCifj&_m*3cwsf@RB(`exY`*y&=pVSsjF@sR}G`>E_K z5;y1T3hDX9mC0(bf8@@fRR2?jM-1O?g&sN<5LLI{eHkm0>#fJkZ?_!Vc`4H{ zZ$k(thj!sco}F)~R}wc>T2Fqvwn!-Qfcb`^@-LNUiVgOzI%TlU}X z9oK)FBoMoW>D$*XIY;f2enkoc4|QED1{S_KR$x~8>9Ll0yHfcxU27-Lio<)mTywc% zOGgyzGPa-9-qWKmBYy}^mC5-&2=N$Vs!TGVt(}uKazZ5&2}of;cZghw2>sG+FeDrv z3x*r){XH=_r9vD*zdfZwT@~}v;t3_`rIqiy+k6_S1+|;P`cH8-d-(MXHj30wjv9Tk zTYj-Pl_Lc>KE8p4^WZ$cE^eiqSfS)W3G^>0F}V4?$_A>m{@>y}RfOfi3JIKANzR=D z{N&dqApTqW;T7uKh4r*%4zFgMyD0kK)VbT98>=&reoW_U*e9#CTQZzma-x$?xE+xd zU#~yNu%D}9O@2)qmGyI1k*v4iY5i`|^_mepUkv2m7aa9*2|wC6!dKhz=C()DEmBLB zgPKOQ`$9)8rp;f&q%Ig)e16KicjKkCvFYn5)v-nX1DQegR&8hQF4`KmGcH7G&zTjB zE3MN%EN*AH$zj-9GhE^v-@YNE53^YMOI058EuX@M(N|?F3U+*GGI3l*t$O;Lme}cQ zm0#Z%q8L|Laha1SmcGnK84@ z0o;5?ul2=-mfl0g)1-TPV>q9)RdEw0-~Jv)uOPnxEEWa6p-Szu}tzVuyk)x^T*%nadIX5h#y}k%gg>_Y7J=8(sKig*DAaR3T;H9%T zaFEP;l7C+SaEPF%W`9xy4Xhhx{ZLqN|7+e6G#JddRIp&)|DoB1!gx&h(70yxQA? zq}#()4a!vna+NxC^9HoPv9~ob3JUI%t?twR6vY|;fL-*AlAl7XmTXb?x%`+GjKT3# zUP0;P%>oCC3Ycr<-A?fqR_WR~7ILhQ+GKdJ^^1mtpV;sTQTVe; z9g|w#hMks*uHLPA)5VWd9-M)1npeNKX{fOh^H~|IynKJx>#^}E8~fA#TTW~>9X?vS zH)s6YDl@KgM#G#VxnHu9>*Alw9FF&@iIn{0d3oKLcKzmro-{E()<=dX+DCORSuzca z>O{RTG+@9T?m8^Tn>`SFkng1B3UgxWqX!!*&z+Er`S4ME-BKQ1g`v~h8&*$v9Ic$% zyt=udW8aFP*o#{m*9olJ{*Hfq?4dTX_AzDZR7_Jw(W*-YmN$ZH?tg3BkrUJZY9PI% zN%XNogV!#yEqS?5nDSE>yUC%OYd%H@e8Mf@;@NoAY4@e09^HP|KddH7FbGZGL zmbGEbl=O(3@u~&-;oQS3jJJ);#KSdXhxA&svyK*c%9_+J3MpmsE&lqzz?Sbbd+#V) zWSVo^+a#l&hs;A;rIwgpdHQOb*K1s(cvRGYt9Eb*Wv$4|Wgn%lQj9C%R3>n|#}F{< zJK@afKz%1aS^kuae~ak{{_Ppluk_vY|K36VeG(u7KZ~9QtgS!eWzj)VB8;H__#~Bz z{rS=X7P)kQ1(y!Mm^=1%ioz|XcKkuq(Nt~+t@C4NmP_q76IBi$Ug3PSmQhaxZ+kwe zkzJx&H~c#91Gcw%R|*+VH0j^P@Dt5CH*+KeZCan}CmT_<&vwsn=*o^~MJ_e0DvebS zk1VWAWU0EJ=Xujlgkd;1c1UBHJg@rTF=pr6CoRtUJh-Zci#Znhz9sVgBJUExajWw^ zdO;OYLE7<$iUYY+J56>@K7Y!@ao0Pc%vNcT<6<#i+{IkOH=my`T){2r;I4Qekhgn#-@9HTtU2c@k$>T~oC~ zZ+*w!WR(w&?%Sobaju0Vf@&h53;J1WIw4j%~~@t0iHt7yB|H=|F^r&G$#XxY`%9>%h`x9y2u>UU+H zNBeLswTe4A3H8=jU{ie`Hwc`(All_-H>h92H7sLWFI;P}*0TR{BPFqiGAR4(l2swt ztB83#PRkl`u!RpF+xBe4Yk$?3?i0a%m-AEBjNTiy8?;qA%%^zh@Vb!Xfy{t--x~D| z_dWJ_Uy4&yd^Z}|sFo@H5{Ch1{=>7hs6kL{#kLzOqA$3tNCTG}XRc7sT&z|ji2rK#4H-)>E9h}e5K-%VKnsyBV$0*{ z4ct*^mbb1Wfj#Fk$yZIqXtI&g9+~#_qVW*xO@m9;M-ILZdmMO4TDvUYhqNJQ-4-in zw+HMy)^>>4iM?NJwq@C!6Vu_(jhNJwiUtft%eqdB$K~qx4F@$_7{({cyyshYD2JAo zHQpkRwNk#4$z4}^gn_+iG;}IdZCA0fv2yrw+dxT{u&5OUdHreQ4cYIl7C!xAaOZ;d zn<%-;7gY+Qce>wmRuwAd7dUVlvW+osz9-qJA>8-&nrfTZzEigPtk+quTt8m+UQBy788OB& zwlh}8Nb+Cw_dosi$#qfu#b>5BI2B(%C8>|(e=PCNdjQ=lvAW>-KEI5`&W5`%S@I5~ zbgjCm%-AwcLi>8hfdl&!6Q!qYc1a%lY%P=gVc+DX@UwRLeXnBTMMhrg7A6SWeY@J8w*PL^4{B24!L#DrfnP?_1dfD8)Isj@}5ia z*Grkc3ySEoD)YPAC>AqWffkMzE5u3<`s4@!r3 z6w1DQl5UdM?|w)?&7@I(bb*>`$TiP*A2Ot6*r(Wrn78j&q7F+;TQfhPG8{}~ijmKI z>zCE#q2pq_4@10OI=D|*f3%%rbWzsp;`9faD)=kolcyNWvd&JhaVph@8$_C5Pcv3% zRU{0V3DrM%XxGZk9xP(%r@nl6(}!1;>n%@|r1HLiQ+a#mc4Rmla98lQ16u1`4K?5;?~EM;VyRSa(6u}H<305{NLFw5xy9ieBv!IKq-0T*5V=FZ@(Y2^9sS&}rq*?FfWQ)Gtb#z%JqpJN%lvN_($jS2IC*+mbgd#ALB;NOF2 zt$^{#Sj>2F%AL}b*8i>-SWPvwU~qv|PeYZc30wZf3#`SdoIrl~cfd>Y@Vl1=>ZuVv z($#+D)C9U#@A+YBf!F?9mg@AYxi~)Y?@RT0S8l;QCS-XI|KWnME=-(%!5BgRNA(ZT z?Vs2B^Dh`*$)612ym2UE&l>)#=d1=c*T}N4Ppf8D>|=Qqneosn`jN z^i?uc-k!coqW|o+6&`8p8m5ZM-ZK{k2{B&19K%{6XKW%#j5@`+Pq}E!E;7RB#*|~G z%rVW+lpN<#UMg)QraddVms6-Ip8I4^U>~z-&_uF`kXVI4Z^*|lCr1}&DhS9{Q~Xc+ zAAO`ISTLcqiST~b^&<)-B{c6AOt@($>lyvFiZ@^P=^YQ>5gD7jY3L7rn7e_CyfcY8 z@6Fe&wGzFi8M!X407aI+Y>aEB-=>WLwui_^d1!rgE3{?P^VuMRR%zYMr? z%qIDC@53Ga+UKt`ep$Q8qC7jX`vYbqQ+QXJv&+W?SB@tP^qtOU_Lj_zVJWk(8m4G% zY8>+|JEkrlyX9gC)586Wbc;xM;ZZd$k9g`8iN?J655DKI8J(|;Y=jHqTJ}|f|JBnf z7;Zg!zE&k>Po41As(WYoamSW1iH9U#o4S6zVS$0Ok6G3^P4UU#8@o0y|9bw$K#Ofx z;pc}PJl@3TK7DGev8}q>v#(qxc`|XHImO&2R`uk)H|J~N$}?|lebYFyO4I}%tju^K zFG-M(+Fej&l=-=XOY>rYx7p)1_{l5j<}#O~_iH6x;oX;CjB)7^{J&UT zRuGpB;iZU3Wmee*ZFUZ*_L+{8G<@q3Q*j~F%)w-7JJ%jYqmZNz!40@Pi}i2r*iA>h z*nP9Qd@NC!mH76NBjffn8O+*4@nR>23tJZts#}~tJpLr;LMi4lfn{fW>zDe5W(%K{ zf_pFwPSOsumTCZ4s=hznmH*N-{VlulyC2)q4{?iz2D>wcH_n9ZXCG)nX(H`*#W0y|6xO(0vpclr!j)W-)_jA?QCauOrJnfABvn{=#4$OZ7pE7yXXS3UbM_%{B+jq-hR&p*|VhP!$&FI<{x!Tb4~%hp@te!Q8n zw@ge-i=KE3ee?dbQb@Z%*4>Ww#*DkE>Qd76q%qxfD~!d)3KN!WUj|j_aS44;Pe>s> zJaRg`|3=%#n~4zF4z`e$UVM8LSC*IUsZ@Vv8s8heUt@{Fv|E+>*E27+Y1Re!?tbiH zGW@QsFgR!Hw^ad2-Pe||ZI|!UA6c+ub>QALQjv{&4jx!Mm9#EzRZje&$d2AUpTxiD zJ;)uuUdEc2UV34lNG0AZt@djORIxDwU$Jz@{6KFXNMwOR1I z|6!h%-48gecPC%F(|Y*Mn{{b#dkt2zJoBLyNHhCCI^irqzVNOWdNxR8D&4tgf@B>( zG+AzQY~m?py?;14?np|@VU`O0x{>QG4^mH2TE)j}H)14`KZ|ZwcGa)(dep?>R+zYn zYQQ{Dp!zbaM^lYg=|h9MtAf--Q-$Lr#oFp4kMn8{n;mGry};C=C;gN1?t?tRaAzG& z!|qw&nh%AU>Y_KKsyt6uKCxJw@4WhcNyjy}=V4DhF1J608>Vj!IDF=~>x?eY2m^GHiKEQn78oOAG!e5ZoS_Ecu_e zoj4%F3Yx}5|3gTe0CYW}bnA z71*)hUN#dN=W&{0a9DN#VbGbE97_bJ({uN4klib`m=$J5lHr(22qm*|OnUMBr3vz< zV<{<+X5A70!`3{uTDaf^t&i-)MiVFcsvl%tE+liBrR*(FeSLv#YOpqnWZAhtF!jO) zTip`I=_*lN-4(X6J)s2-3FU>gJ)Eo>K5968Q5=sfIpr<0aA^4>f6~3|g_-rbdaW@2 z%FVnJ$A{}qaCR>=>(+IMU|-I`-fx6`V&*oH5>8CTae%!e3#!pO|Jfcz-AljPy3Thm zrDB%AB6A)Ga4(AE4?YF>M}N`Rd-t?mxAG7_-tQe$?v0FGo;xtQR-dq^#yqG{JXtdi zPMMmQ0al%u@)AxNgj4$AlnZ!5S&F(_sitC$2PJK3j-gx7AUlViaW=(gcX3^Ng_$q7 zuUYWlU?}`raKKq6yv_Y(W8#5FW<^uiFMHo+?yt$tdAQLa&iu9imFF(DY4a5lY%GvF zIoWz5Z<1Dd?z6u1(R!s?3Wk-9!`n+V=yB4BrGxd7+Wy418)DDsT*W@z8T|gj`Ziw1 z3zJ`bUObkFKYhNL>KB;&Cf&G9>|?%(w(L0nmAo4UHOD#zp<~Q>buDpQEVpSdb|&1~ zvFFZ;Vg;|_Re_5}3t#OKpV*jl{N;hPI?2?n(F<3Itc}~ec+`u*NL!kBApK(J_OV-- zVh=u{vw%Gji#@PaP4!O~Kaxp%m^is6ysP(Sb|NL;Vt_SC OyIXQg_#$)@0sTLk9O=pc literal 0 HcmV?d00001 diff --git a/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta b/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta new file mode 100644 index 0000000..4f6fc19 --- /dev/null +++ b/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 28705d6096348bb4893f8f783cd912bb +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/System.Threading.Tasks.Extensions.dll b/Assets/Plugins/System.Threading.Tasks.Extensions.dll new file mode 100644 index 0000000000000000000000000000000000000000..e059050bb2066f749b6e37a5b42e4bffc3f48a70 GIT binary patch literal 33048 zcmeHv2Ut_h((s;>kU;1i0g z;*U2;|2ip#VvSZ?G|)Pg;})B!kmD9H=@}C9+&pnwo-o@yS(uX}mYOGt%=7Yd%rkP# z{llZpv&AVQzPdWkT24A50HF|yh3@I9^lt3!2C_6)r5J?V0i!I#ruKlRIeh!V7a=W@ zr)7L&1m>T7svrgYOHT^M@U0SS^t%N7`PUX4T@1jRtgTXJA((tI8q`oHgkoxL+1Yzfw@%Mia4Qb)6b>22cQ! z(Pe1V7M>JB+A<u zw}4z5ZMN7Lo@&?h3C zJFsFfh;}yiP!HQLu8-~40iF^*M$-N9NM!aq8t8)O!S;*!5ko&f-9D)i27Bg_KGd!y zVf%F~5&#C{|cagP!= zNWjc-Q!sM{8xK>o@$be?Y+OF#W*f(&Rv5+iHvZf8-`V&NBz~~*?`dEgZRSC4<3AAi z-p2o`z1+rsXy0t(o-j|)Tl4&LW%J+61eiLk*~HW#KEX~;ff$}fZ0dO8B_0?UEYl1b z6}d7>U;*bzI^tqohC=P2PiUY`+d%I;`@gDErobM4;Bz@XsE9aX2Y>_qYGh@*(@72*5W3}88BPRS3d$yT!N-xaXfI5uc!_Y)R~ zv;*ReV*s~E#sCYl2^m8m5M<#vf{Z~11!2Z2=pn)I1n*HO!*<13kWM#vLf_zYd3Y?c z!cYvYp@(2B40{N!BniVvsEX;xD%wC?D7R$HX>$Sa4=N(#|2wP-##%zR=2&)4^bq`% zKwQfq*eKiuVDVEDjR9QON>;ZJKW!i)!b^n=fGOo*S?e-Ns24n8^0Z||BqrfCt-o4L zs}IX22Gix(o5>c^B3MV*EO{efn%zPSE<+x5G%i{4M*mztv47o<;V=6kjpB>IMY6wg zGJp|DcOX-YnIy7+U=&NJ5I=2tDgxLd6lI}CWP$6+9d)CR09nY*lVuZ!8xdJx6K#|Q zX@p&33voQIK*A;>3w0gVkFxk%{lMh>RX>Km?1#u=0&N4c%%jQb%LZ*|gXgQLHKa7# zKqkZZB3Mm8URh1@!o_yb6#IN=lOUr2dd6cF^&xUTd4Eri5j6&gWC=*?s{6F9?MaCchH~cAZAYYA zA(5{xTZe6fr%qQ%M~P)a<_>tneh2Hozse&RIOY*#{7W7cxRA^EZ*xeb%$I-=IK|kR z;O%BV+#B#rBT!(Z336rS+u$7+&w*=%7e0<1N1TZ(@g?x!6l1Hh!+R^R34BBV_4Q#D zYt6IgafVHraitH3DFT9FBn)%#+vVnvuG43uhIMI2%Lllp!30 zg%|J$oR=)-azq9J$Oy0$Uy=i5#n?oF4;BIgM%siA9*!~zAK13P=L2J)Yi#W#id5q? zLOA#kiy>)dg9MC(4OfE4Y&7wq?=R!SH@d4Yg?Fp)0e^=ExbPXiGvh4qz!)V2BSZUi z5V9&lh|xtT2H3NTmgZ&Tq)Bj%5iLO`@U)7JMx!AQvP4#0VuStRIRoHAF2KH7V$d-1 zp@D@St>&w!m;v~aaz?NZ$GyYKgdluC5E~;H27;xG#4yjta@Mm9(MMj$pd8FtuI;!&brgR}g@6&?b@^k(6R#%ncf+!3d`}m4+&FkOmj$ zoe<8i;$k|pNogg)yha#P&Bk@ME9103p<_vEE~Rm4ItQogSRHvBG??TUkXGTO-=0vX z4vhtoa8P%^uOxXM>Pp%^SH}IenKNpeKG{P zNFZH+s_}eLIxs6na;O!OLC%C`8qA;%l(`Ye10)fLTEM;&_qQEJ7zgyd36u+Cj6>#d zriIILNtp%eic|nvO4?bX5CT0TW!5MP`qn~@q=(iB0tBde8nna*wMIP=3m|;{#ses> z3DQ9}5S7tTRt-{)gDAeY0%VVp5X(Xf8Ni4GkON9nfcU7N0_2FY!GCB_S6JPP?1>sap#QZ>BB~Ler?Tq1(ngw>>H9!! zg9=WMLfVKgQ+f;-R|==INg4yG1*)N*vnUkHeGREU^g^K&E>2^)x-^AwFN$~zBvN`0 ztwc(8v@=p?NoYlk0Qqqw(8_@R40SN)&6rH6i7|@x@!TRdPT3?ap(D&;YEYTcNzio) zeGl~{WmC{ojxw7OWhFqA%6_XIzNOkzmsqjDV83>8p)Xu=jL>!mW4ZHpVhM^+QByZCcJ3D<-;n0yW>^-@Ws9MMM7 z1J=4(Z~%Wm1}Q(HtJnfmPoQat!>R@79)_qgG*#s|B|r_bnrH`oiE@IYYfQ8ZrK@m| zGioJ=RJk`{iDhJv@*L1C7nCY5lTt4!7gQ*RdIRK!DhY)9Tf%lnOE4tw&mC=&*TnsK zpaXI!UB#O2fF8>s++RoZK?Xs81#C~$h6tk!;r=|4ryRolbw*JbqK3oR*Rs7)F9Kox z+|2et=}l!zDIe6oscZ+^7Zo*?tp#Y5tc+NPAF7ns>;;nWLklp3?okDl2knQ{$W+{; zk^u5Y5(3F|J^+ou5aDGh6@aD?NM>d$b`yhcKOar1^oaG zBQ^0%JFtUL4S{66cST#8%A{0RbWNcw1iitKTuLG6D}iL3g(6jZTvi60aZo5S!jOEl zp=gsF!lMmCu@EdbjxQYbA&`tp1j>{_WPA~55QgMbB9JM>${4~_BGFa?$+(U}2MHwe z&{3$KK*M1*EvKVUgF?;d?`lTN!Z|b?ym~nujS6wlhh#KkzN;C7Mw2pGO&k+aXq?Jl zrT3I@sUZ!)Jc4Z&?kq%Fo!D3^;*Y#70+!RyH zGlgWS46le$oCU@F&ozI>U^!4k8aU-ZB+G@ps5Y7j-^mc^&xG$}WC%|~cpAae2%akF zB$t93IAUl4DG%8~ss)h;PCZEKL(*W9Mv^p+q(YKrK&p@WLu!l)AmyMBBvqkKa=nl( zq#RU2Fq0wGf_`yYPS%HV5)WihSGZBIH^DXakTN$1(mAk_?M8U@-i=NukAf7h*1Hj2 zjdp{-n~E+H3oZcq`hdBiGK-`&$eu)9_9XtZCy}2$iJa^aUPnDqYn4ACtyI1V^&?bX zLw&q5+LN`@9(b^#LJ(f9LV$iE;BnMwO?b0LVbHrZ;mw-x83TAJxf6kZ3ksW}kWXj9nlYg5?YOGzAA zNY<}HvTjL9d|3#qmNhLUBbAc4vk+klxL<3!kZ@Q?){jDj>12_Ja|Ge%BEp{iBEsHj z9AE~4|_N08&4Gn=b8m)x17upSJGD_y~Q6|bD=}3~!=J+8A^yLS;o8zoxl20c2-6X#k zZ0tB|FIq#b=G-Rv+mL?+!8mTkqJ}^^9LDL&y$$gzU}&6Lk<^c*$@FlPz#R^$h z2Wl8~h`LX)=n#4WT}MBnU(ghI4hlR62js2_=b38YL)5`PXuxPR!E*-rGyBMF_z)}J7p&)I; znhmQBh8sV6tn0V{YT+-*qLwT>QbivmY5*fJ1a6H$iYNqz?i&(XpyuDB)!Du zNQ9}P@Ep0!pcX+ZBIHzLLT#cND9q220^}(la7;n2sB>mwqOUMH6OJnbGelWX*hCf! z=%?ZwkyIiT=A;PoQhu6C)I}u4jRM7aO>&VkEr|{X-2jP zvT>r|oB`rY(eE@s0pHYT)BNM^eDc!rvqd@5Fk!X`#Y9Vm zQcZ?kQ|vR1xcbLnHpiKBELKlG(?ib48pxk z^Za2-(+C<<1uc|_vXin3K+S|Hpy@tRI5kenhmwHoBvA@zLo=pPI7DHfu|iQ(rC5nD zP1FP-e^F9?S{k;WW?W;JF&R=tbhIcrKMxc;8uZE!G8xIjtmZ}_kmSsmJYljZC-xDcI44z{mo3DmC(Qb(7HA(_&C84urOJ)sX9E5rNpfCBE+(K@ z2qyfUfhv~C1nVzK#TxIEl_8Wgmj-4D(-c6NWC?pwqAcMcl2a&e9AiWtm~^tVnNDMY zpE$Q5FC#5op~x>JnpjbWFh>C!EQt~cQ^Iqy3VuZdTuP2Yf!r!E8Q>@>1N)ukW{JeF zpolz?1gxdWlw#6B?NY#$QG_UmJY&SNR}m;toYaqKEH+TkOSpeZJPZM`yC4jUK(h#@ z$(H2$4vl1%>?0xNQcOke(3*PX<01(^V31UlgLOf|Psz%X*Fpg~`PoS3$g+rxW5B9& zP@+Of zEHPVgp+brI5|P~VAh9%ElqVZPkSHq`=jCgWf@{RR{fuqutg#4>6ECemL@0mq@mh{# zOFFRFI1&CC!n7Q*1Uy9(>UVy;vB{5WBGV^{+)shh!kQ_P{HSjVs~Ry}l#0z4g=Qq@ zi6!DxDJ&Z)A|LQ91(J*=R(|LTk%jwrr3(6rnk+0vm9&&k4q z#@cx@0!_NssLBWiLDoJ5eC0_Im=&=y96Jber8t^`xQg7hj+Ka_lhZ{Iw7^6(A_KF; z0|N%Z+JLRH5ebW!uz)ZNVM=3wLE;yQBo&OKK&FeqsZE8jj^psAu~?j&*ceD5$Oq?$ zSJapuGlsm04WMl%qvaX2_JyqjYRE zxk}pBIx#vz9T6b_eb720WpkvjlMk(xxU{K`5E?>fNV|A5m&*cJJDUwqwlbo1gv#2* z+m#Rn8IG)976}s0tpNPbvbO!+}Sqj1(RgZYmRoTqLqqFjQ@8 z4x~Vz3(~^X;DOunK(ew*98DOpoP>4(6k*Yj3=9{;APL+|I|%ZG4x40S=EhRe=I1Kyj^h@nYxzGBV9r+>*;_B3-;3ngMI8;UTNag9+0n zXd3g3%T=%-NfnI2Rh77yUmlkY`e*}MDS}~vX6SI)jWddw!v)I6hUk7f?r=3yd6ie< zFzs`^4#idYr3||m!C4Eu?WQ3CI4aslfVZu9XWOl8-_b!avt71qFz#rCZgu>+e(e(v zBxUQn)!jaNaabbzq~^%}v5P7uEU|t3Mf>E|zCADG4C|dTZTcuWZ+ha!(YvpcnZs4Be1^x)GkI=(%+~P0Mcv!AKF%Fl zDqY-hx}Ez`U;`M$dsuie2?-o)f?6oEINEwF4%isTAHHzHsT0fQXcw0QU<7~-d{f|? z4n{_4>%l38PO$6|s;vh&4Q)N3tRo~^B;>#}>)3EO<}8>#8fJ`!nWt!NIL@UZB^st} z1QQ1aZ-b54ABwd-X?(^C#|?5Dm8lWYbgWM#BiC=aI%8eHrb7X4B8_4t% z7s$FwAZ@WWvXy~JmJOoWHefK2KqDKZZKP}ijYu!}+5rBT;n|9z4SM7Wb73da1DePDslf`+W)IpBYJdw!J&AGkMJ;l{M zwY^iSQxcOZ5VjWx+}pc4Gs(`$sV>gWA`e$#dsiX3?g4sf0)oO4Xc9nU;19Cahxa4$ z{VLvQv19V`MKUae=Bc8*;G87!AUW2XLLKGv^1D!pPeQ|{u&8ug;8NAgmQyGhcARs1VEeHKwWp0wbSN? zd$y|?+uEgHPhDr*!9E^clwS^F<>)RvgjuWi|1ujB={sGV&zV7cJ@e+B*^q7 zAt@s#0rpJ^J~;*9(R@h#B4YWlOT@aD@DFV)LE)_AAJ^vRrX&F?|FutakdKqA8^^3#TuVU8T*sv&|Bi#RK{KVqCc_Z}wv++;oWLVf;=J{u3g$grrP__h1 zS48%Pr1V>BAcC*O{V)Gegh{wRS^Pbtvh!iMU-%Oq*9(Gg&%Ovrl`tgxNR?b5(;Y>l zL`VZr6y$>8FD=6W4u&*P_E(o^JNx-pY<(P9tSPhvn|UTG2kvM6OlcLV z!=T20E^wy{WPlRjMhXRQS;TO2D;xUG0V?<+WHh`jlt5ktSU&Wh4zxwkcZ$3Rj1xi) zIGlj;05piy#T?3b!!$zR^t_RFF5$lbq$MQ%VBSNaZZgmnLn|?iSPF`TImv^2Za7sO zX%^wLaa{hui-fezfVztE_;>K#0nW>*CK+~zzVe#Jh52@Y5xc?H3EpD3BLRH*AWQJq z@X11Lpe>$3EW12-3IW$V>i;=^e3*kQ_=gpk4}FC|KWU^FEW2EoH>?F|Fk@1vvlwLh z_vOro+CGH3xdIglVDaor$cP3&ngTt8jgYa1%WGoI!((lnBMf1U`giD3^O$4cy$sx) zgFeN;MLy_&R6)AG(y0}|Js;`>fX12wcUZ45UjvDbL41VbDOj3*p!wsh|8CCBkvIGy zaz02r3pnuw>34u$@C*sT!UUiz4q)T{#CwFpdmHR8d{7tQh5@}{pe}ANv+iV=Gu#@> z8v6lkUm|$V;{^N*NX=*{OC~k~Z-q%+Jj+s;bqPR@@GlKGkpi83=pDZ$#dhro{D=XY z18t-LVJz+=6|B|~FgTCM^ zh09sGM$MbP7p z4~P!y;O_4taB%SrZ13Rf?Au<@nz51%)U=tb!a(tM7T!%VrIe+j;3*}qZxwlnWcr_&!}6Fn0Ee4*lyc{}J>#d%H?iRZ`!f>$$7BN#lD^JEAu{IOBOnul<2gXWx~p#!nvP z4uKD_hJ|eWo9{tf4_y!(1=ua-DiWPEGH--F=Jvje8}f zMDH3pG@LH#JW*xc1V29-6rHLmrBpy7N=!=-X-f^Z0b5Uh;LGbO?IP~&m>m=RuCV>a z7utH8iE6d9VjD3A#d=mQ?=MCL=JK9;e;V*RFoc76f zWp}U0PcwG4c1oFh>h7eGB?Vuk%a;{w)Eu!$_4U%hfsYCfda>IM2)pwl-|cB;-5sa0 zQ8}XpuBo*b3#b>pN=)9eEm|4hYe;{wK20tCt%3QsJI|*?2bt_nTi4T4bwc&Ltgp8h ze_Ec^(8DG*x#3BBenlzTj5Nlc>-?%++5ENsE8_2o>uhan7S8hum=%@T^I?hl`K4Ll z-Cl!tyR6{dZV#<#RXXCzooc+Vp>F>mHKyQuAM$VVZdQzi%;=j>z2HbIMPweGk(L8K zv&p}CFs_V~lfa2_b^`zA#3+D_^gqIy+%dC$UUoh(A*ZtXqF%dTAY_0z~`%{}M(YVjY8Kha@fYx<%0496jlDi>*d zo^fBiO!L{0E@5Y;^hLKL4w{GdQPx#;%^7W~t$pRi6#q9xx2nHsynoU6k2z+RiSKLA z8BDcRe)aSPTjSaT--|uRjrF`cwqIrEbEA{J1Sc2ub5HFOcgOR<=4bJ>$I2tDT=HB) z)Gn{Bncmq}^^^O0>o0SZzmZ8^q>O8OdUS0i%bjD(R{_IeEA<&h1=WT?C*qcqwi4cb9XwMY&YYeLTJG!t-Y@ zY+sVyMLCQ~!WCMvdogiLkE+|?P@Q`!H+Hw(ve4sO-Hfcgb(?l-y$kM>db{S`#-;1>1lx7;Vy+&$J1=KM?Bks4 zHWedyS1wK2V;BJW29}Z5{H;=1} zh>4nGvwFS(<>HleX!d}ZgJbB8+9${DtleB-b@kGUaWPiqcF!IheV;q?}`YeT18 zyK~xLRGU!?&vc(?{C4Zm4%4dncLug-J1G~9Y&k2JDOK7AZf}9i?eTS{p3d@SZ?gknzNs|ov#82Q~H}STs@AOpYe_;Zv&eTn7SlpiEhMT+2JbyXt z-NcdAiS0~__e_dNY*E5dIX&rN)kb@NS!?P{d8kFYRSFT@?JSlSZ?k`{6 z`xL&pvFz=ahG*++y{}geu-o23v~pbbhPEsA)V*7+uX=B4zmfxW*Hb5?4;=QT&+_BD zRJ1f+w1_&qTM{|NZbPJ1Rq(P`s%P0NE=2UX9-i#A-f`lxqoM8kH^kW}wGCBjbZmXV zvBfi**kkBY)Hk*g!-9u`Q~RZdQN{H&+3@2RR2iegQIYRj^eHwFrV$NMa1#!GYJsii zxpMaW%dxpf-evfHo2g|o(|z=<9!!g-N_sR~&5Q?UeE5{W5BYrO<206)_Vw=GcKY4c zx}WWC@}j54-B}=WtF5qGWdf@Fs(i}4{=ScE()T=2?PSnw;?ZInJs5bjASRIUZ-l|4 zx&JdB4I2!$7ohsH|Dxd~%#aKG8*Zzz@c;KeC5dL)<=vstvLHWdDNI0UXmRDq*ljn8o@}&LiCE5Q*Wpi-PUEKb zC^_yvW7YLp?)4?lrnKFlf22UEqsxPbfH4cI8x7R_&aM%Ql*qIC1`3(~Doc zS~PNPC;b<8FWZ+t?bLq1d!1dE*=cd>9Nr9GYc_E1gRa4L()LSlRXASJdhh43-s#GR z@%r0Cg2&aZFxF4y~nq;rrb&yePV3!;ax*FjLq($ z+skfZ-v;UU zG#}nV{WttK)1GmGA0u#r*OwkL|BXTTeF6agdxru4$a~ML&RTu_a!`d`VJ5%D&F!~t z@1GfI6|wxpRiiL#&1a|TPK7L&GUnQkx#wc0>IYYv_*Sf#k-)UMgfbrt+5V)QtNBiY zJ>y0Bu~tW&tw+s$)sSXt|9Qy$(Jdd{538x(Z54fF{KtTkD)oI<*01tq&;PJ6Yf9Rm zHdg|pSC!S@wF%_6T~-zz8>M!KW&f$)q)AN9sMm4K+>b@)r>}irF}>*hY2DY#8>6$M z)&)$O7lgWYN!4y^o4RQFoim)0uJb>PsMGGEr&2m^#M9V8U#VFwBa}xXEhg~k#%orA zTlYD{%v)(T$VV{n*zD^ahfk>%((7BQum1dQ_8RJhWw)4bAC&g)F;{K$-b=xI*Zr0E z{^fr7JMXR4LL4=+l!3YHsGcde>j9wO=4 zz}4l8{;%=+e`^O1veueDW^V$^-|gzdb;}1{K2Z=EO0DKg`}fLL(_MOE$B>De_-A$I zkIPQl)Pp`6X097C^Xg#lTRpa}>^aNyW=pDU+15d?#@0XSNIko?V!(smp64&wa1(^ zhy9TnkCGC+3}%cq_qxS3cKUEk&~<>IQ@cFXLyvMheH+Qsy}pMhobck$O@@!d#tz%> z+OAK{&d1w^s`?H&8=YtIj5)G(kSL)SWysUhIDJWP#v9MgsXf;^INtv-vg}x7_Xl%x zE3=k)gq(d_uycvg;3V7U^Jm+-a0VJD9qwe7-KzA3>OuRhC;ism{qSVy`r8W@NnJOE z?eA};(`JCGXVkd<@qvDN+t#jK6`FQvp6|Ef0*m55^qJHLzB+x35B*_jQSbM#-NUU7 zLC5URUT`W7X=4{;of!Y9`}2j@X3jm*LA<@Bt(2qvY=Fhi*`>SN#%x&KuTy#T0O7iv zYTbo9mvnidBmOeRDQnHw>yd}XSshN@KDXs4ofNv0!^*gco9|6T zDC5w*oJV!jPY7(kY3%Qna3R#B`oc%YKfL&{2APL-YrY6dZJslwHjm*Xm;rP9?;TIb z&W3+HJ!w9gt}2<2!!`L4whBw2rf@LLhST5XgKJfR2BTQ2kAuO+hHL=@gSK3LkoVz@ z@vrNj){OmJyRy%+%5RLX0tq#N3*%I!SFH2%o5E`2Vx!*$V~Xo19I3KPDdaNbmiOG@ zMIF0)o@+bf;vk>;rD>L{E6etDU0u(vd9Z!D_d3(CmovQP+&Eg%&1FRAtLg9Vw{hec zZ+gGVd+nh%j`Tdfbme2OynPkwLn`w6jJ)#M zWQ?SLizgF&<3gUbkG|#^N1N=Zk_>-pp@1Jls3`13IDY<{?~6K6f~|kW7NzwOQ6~Wa4FEYCXG@O zXyR7|jGMq+;O6QIyU?HXZSL02tCt5(qSLO|em64O&y%$pjSL*k@@e1z!=dOLbPp0nIePeRr z^p@vFtPOiYTF!}N9bW3$ZNL{E)$-l0ZWE99P8pHfv3~i@>dY6x3ocBfk@MjCzP`J& z-=4G#Jgu|Oa+X$L&>5vd_mmeS+{SS=#6yK+I$o_V-;CbA+pD=nb3%EqKz2j;=@8Fc zP3OpVbJtasM{g-V&|+#Zvtg&7*UuWzoJGG}d{$}1ac+xOe6#(8pZ|DKokBd!ZMO+!)?og)t$& ze|shPp)K2dc^+*MBhCI)de%d!!M}G&c#K2T2iN5*X5I68v+u=u)2dSS5;*wy27&W^ zh4bFXKgLh=?q8$fg9B(PQgK#Qfu*AV$f2qY(*`0Wc$?L#>FvNz=e_1|C?X&SB=SRF z=k_jc3WvS~{9k(LJ2n15Sw@$ZE@m%d_on8*O^Pw~3MdzWT|=;~iHo+Hl8|o0@&s(h|0l2RjXRKCo-=#7TV~fBMic zw3kcp1-qEXSz5NEM|vN;wzpPz_tV7cg7o$U9X_Z?p1Yfdmub&7efi8;f5EqB+g2mCq}+{AI#asDuzh>W_1TM# z3Yz@4&c|0}^55nBjmVmWgH}8(}yg z3HaTbjNhn{4&Xq9yiNOyE~F4QG@e7za4$^Z)ifA0s}us}c+KMFeDuePBP&MRSB_{~ zwfl5$zsFyUCs^wA_%w7v&b{_bud7qFTW7b^X={Ay=<8CI=~1hn&%3~z^gi)z#yCnt zq?LV}dNtIx?}jw@_wyD%`|Pj%c4+sk?S*+o_Lt4>osS>c%2m9-O?Qz)p~{TjyQ_Ax zFU{@LZczMiwQuwPo-LzI(#~hSJyxEhaWT>{syoNJhMg7v zHMvK5uf@#Qbva5WbXWD)WAb+tzwR)=ZD7&b^}TublvbrH-|jU>^N1k!9dZ&36&8hF zI?-m@MZ39OHhwjUT~XN8hGBxsllnaw;JAsm_uk&~J}th@a&~BO_?r9Pit;JT-Z{(< z^s-%;zvNznYw$hy>aW-Jd0%ICw_ZtkaQM-iczug596eWIb20o`Ma?6=>+`3_Gv7V7 z9CV-KJ6U<&HDSlytsZ-n-d|hWV6Z;S#BJj3muhZ1D(l~AT%V@>>1B&m1BVX%Fyda> z*E15W%kc@z3l_ciU%qO};GXA4ti3R0-<{VvZfQe}(>_+;zBrtJXzb~3{FOR$ea}7J zIod10FkoW8_i2&iju&eeEnGeOxu>O#N#Kl@s@r$Z=4majS@LH7>(9Ll?pIiy3VpCV z_twY==iy8#cQ7miNsVVG8k0_A&yQF?C<{|E`ak0O;gnnE`fZzC|L+gTn->8AoU^z) zF|Ho6Qx-P@3K$Ij*B7Z$`sd3CG`@^L!({}pxuq{Y=4qMomtV+PQmPf|vgOr=o)+_b zP3$rs#z!pK#Bn!f2X7g+SIz8d`^*D67gS%k@0rP2b;#o!r6=$`Q?6c+GODPuuXWbS zKZ55xOz(60`t0a6Jo~*XFD`DkVzA1}Kc~eV>1(X?Fm=EKr>HhMj`x=;N1R;izp?j) zeSB8_()8CyvtM^es5WQ_+;YP`Wm!&&>!5{I$(jylyr;aseT}PrE}@_{*!I5qjw;=O zJ1RRp|8%=uyjH8w?l$uW=iSihuravLg{M#bCJ(yeW(EPBfv&E+kuMjUO} z!YUj8F7ZWu)Xs60qqgm`khV@Vve|H~t&Mx@86I8TP8P1NSYc{aw>b5QuvNdCHoh*lzbd zsx=>41#dIjC|^Q?+2OpwAbz3cj~Op;m#v2tr~53?T@gAX{)vcR%OjNedGM- zaZQI!PhmNH$oza>)O(TWW#5ffe&TGg#A`0u|10P_XAg=2bno7J?~B{I&5PEKU8>(jWn!D1K1L@;5E zFf4Yyf3?^-;ui{JrTYu|Ql?}cX5O4#GMy=@WJ)GCox<^1Ov!M@tFb$pGI0K@?(o{0 zB2JdTjg^dSVO~LUu7sa1&1Srt2+)j+nUi@-g=@Kqa6MBD*BFy^1RAWgHJtvXHnW^%<$-)Tcn7pP6zElT9ucYeP& z?^O2iuRFXR@Q!rc*=2Ff>x|3EJ1t#nr}q|(m^5^3U_|T%wTi;i#@$R`d-{%zs$cab z^LA%0-*)!BPA0Wy*S8#4>2d2}%3=Rbg9cl@)*ZTVl63g^hNErhK)XF-w6-o-tfV&k zY5K=>{?sZvFT2d1!O5*uGIHW)OuI9@Vb{dhf$gq+?pVLw^?6R~6?a#*eOiC@wZ_Vs zHq&Q>YIIV4rCff#)m|r~TQBxIoapt(x?m690p6Yi%U9f8bMdnN=*WPc?oR#N8V_6D z(DwZ``wr$AGuFhFr{{?4HcIz;D{&T5b~c?$y>vrURd=loeRFf-FjKMq(15xDcfIXI zHG6wUC6(=Mnd~;b?E0nG?_U{I&uV+~cs&os|npxbc9@*|+J-gN`V4#`n zfz$Kn&l^10@?+4{R!cv1u_}J^$NQa`8@o-v^*Dc!@smgGXBHTB`*wb5?%Gd5yu6k2Hs4mfhRdSnEKydxMU{? zzt{mPY)Y$2cEb%uUgPmo3$_4`xT$~rD9f>FGpxcEShCI0;TnOk;EFRk_44f7v+qX5 z&I$GN;8(}y&e}bI8d$UbKXk06)=w~=)B>luj-mIx=i%(i`uXq_l~em)?DK z>`DDmvSiDtt(_VYgHl_*$uV1_-|N8WF%{nyuXuIy+ueA&r^|}ZX}3ar401Fa3~o5o zD)C|%&#C8bwp^stR^^q;<1xLuR2uZSmGE%(&DCw12Wn_l!h7Zp71H3L?>?E$Z z<(Yi<<8+NKs-0i?#+`jU&!7I&xyZfm()U}xcB$vz=LLUu?9{TZ*y2^y$U!NcvKDRB zHDKNQIMS{5Yv&$|S5(DZ-<&e z4B_Jn-ARBN2R~Ew^KnHf)sv&zs2EysVo^$Ufny*)SmnGxN93eO#PL`Z^YeLy-OGtl zfsebMUG;pC#VwQRB@^R9dakaRkYO=%eZsD3d>5LNaJTNW@U@XHtS$8hN_aY3rbEgB`5wP!RkM8*XXzRTiZLi`#bo#xCS}|dIb3Xqx-G$zh$f{)ocZq z^WMN=&DG|^8g!<>m8B&(+kk zqN!nvl|_ZejzxLjJ=3$(IFZh<4s{13+t9AgmnsG>cRO;i?5IfZY{MIrJpOKvO!EU@ z=6hOy-hTFL=I9$rQ{FpHkka`_^dC2HM6p!DB#`ST{E!eX1V&50LK3Z9B=ptON4rj_dS;FJRag{aBFC)W2cOxiPa8f)Y-Xl#k<1zi!7~njTt$^_le-)w9Z4OdbT`t zV6=L#;g`}jf1EQn>a}HV|CPJW)%9FBLpgi$o5oWh6Ofdl!i5-{$RnC7`)PHY&CQ7K z8B_J7-`TW5-`!U^m)s#?j9}7hzafQzCi|V!<40!4!u>cBtA;ah3%LqzAvc|v{JlHK zps{fI7?c$s$}r?mMnK}!_{KO7;#7R(+O-jeIJNU%1&+;e>ThWOcpCGM-f5B}8n~6* zDe1)*J%e?tMt}1=zWIXaMX#=t(t~$aPdzhg)aXYhK{o8E`-eH5*HDhV@v-9pr{49V z<4Wc$ca%Ku>Q}mK%{-OzcJoUXs?Q!af5M==Hj*)^)h`nof_gg4Fzi%lXFAO_P|e}y z&=ln}T^}?Y7!()0aEsAOhtHY2_)*z5_OlXiFF2|?PHX2$@h}SurTfF;zZC>dNL(`P zDaG~d_ReMSa$oAAnr26prJLhsSs+1e!0A^@`vc8vG7vXFi@9e984)L)eAocaA!}YWHOMZsQA)RreybSD%FnYh)Azvj!nqesN}sr?zc$z6G^@6{>G&P$jc zZAxnb)axI;=~8lhr*&Vao_zyf_3TpSG{Q_OOq-lo60`c`l#q(u`xf>-CDhHaIbi&u zta$5n;pf2JZChHW>Esz(j9J+&r92{Ob?+|&TXlNTBY)ZUF}|VRk*750a5|?Ady~40 zHO;^1d40DpId^9rS-t4hU^|}R#icOLhT^|fGUG;G0anJjX{#)uAuB2>VKA|sd7@U zKTpgu+V?+odQBT>xzlrVaB}{4IlbS|hK+d@*_h+IkR?-@k_x6|;&*%V5~fq5i-o

uOEA4w_w)p*`Ip2-}N{5UkuuQaM2&FZ-3bKG&81$a=XY2qJLLo0UGj-CqZ~c;nUESYRb#j|q9#2|y?Vmh%h(-3^IW_Y=KMor@ zt>2_U3$st(ob#dOXZH)04F_s@)5;cX|HF6%+jsb;^~JL--ObmxzMJyoUBk|zAP!rMZ!$+z{Mp;>r|F`Y<+Uz=!MdCdB&{; zoqzab3!l&%WgqNj)o7|QJ)-}g)u;Ez-p;tz zWA~|R%&srT?uC9*-`P9-;asy8?vC3|_Eh3OSFeh2z4TnAt?9Y7MXqMbTQ0d>K9e}{ znsjuqPIW13IULwdB|G!4)&Fm9E9ST6!QQ?3iU3O=rTND9U(sNBDXz8a-mzzM`pwko zomN$HjVZajpyUEma_&E}rT8cIRc)Ep;7;JrJ{P=60xgY+qOT|C}?k>ZZ_^ z7Qk!pri(sgn_R_XlyQ5O!R@})jd^ah`49Y(KjIK_#~w6`2{EVJ3i`H0!Fd+Ld6EX> zeO_1FcI%M5sQAmqlwD&du1h}haH#&)lt1^?^lv%0aCDnMW32-RI&NY-&Q=xXxrg;w z(myQwAN!Z{cCmsZx$kOfI!M}|T&di8M3jfI_v*7%PpA1EjM5lCVXR3=X^XCgeEnlD zH_ZOFX;nZ_?~P*)pNXzN_TrDdFIu_vep6R#IY7MrikX$)Cma5k`)~^fw#W2KVz5*G zy8#wCNc+|9T=5{SlyYK>o6c6?2AKMHrzgyhCu47|1Lk;VAA1r~sXDIWqtA{vdrJ+M z>F!jzG;qycPx@^SrsS3a0a{H^a+)bQ$&?&pN>;P=er4BiF_kGPUQqPEQCM)Rtc`8M-_72OpzANEK1mQl*~(|aCSDBpB`J-6pZgUkaGhSQ-%E;~8t zOwr;G!;f70IJZr=rP^b3W~pS2DZaergyol-F3yr@zgX+^2^U9BAF-fA_O_sqi{0xZ zb<|f6;?{J~sBK>cRlqj@y~fj=FBP0 z7l{uI9&*V&qQ9h2GTG{WP$*DMXa>|j0u>7m@UKse!e1ngE{tqFOh#LR^ literal 0 HcmV?d00001 diff --git a/Assets/Plugins/System.Threading.Tasks.Extensions.dll.meta b/Assets/Plugins/System.Threading.Tasks.Extensions.dll.meta new file mode 100644 index 0000000..ce46b66 --- /dev/null +++ b/Assets/Plugins/System.Threading.Tasks.Extensions.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 563706d062bb0b545959896ab500001a +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: From 232e2eb1f2fdcc256698beefa10550ff11f41736 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Fri, 17 Apr 2020 11:15:15 +0900 Subject: [PATCH 002/173] add readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 286528d..4a0b4d6 100644 --- a/README.md +++ b/README.md @@ -352,6 +352,8 @@ After Unity 2019.3.4f1, Unity 2020.1a21, that support path query parameter of gi or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=Assets/UniRx.Async"` to `Packages/manifest.json`. +If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#1.3.0`. For example `https://github.com/Cysharp/UniTask.git?path=Assets/UniRx.Async#1.3.0`. + License --- This library is under the MIT License. \ No newline at end of file From 2ccaf0a03ba063d988a1323b208fc0d17cc4ab8a Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Sat, 18 Apr 2020 05:07:59 +0900 Subject: [PATCH 003/173] complete infrastructure --- Assets/Scenes/SandboxMain.cs | 105 ++- Assets/Scenes/SandboxMain.unity | 114 +++- .../AsyncUniTaskMethodBuilder.cs | 245 ++++++- .../AsyncUniTaskVoidMethodBuilder.cs | 47 +- .../CompilerServices/MoveNextRunner.cs | 49 ++ Assets/UniRx.Async/DiagnosticsExtensions.cs | 52 +- .../Editor/UniTaskTrackerTreeView.cs | 8 +- .../Editor/UniTaskTrackerWindow.cs | 197 ++++++ Assets/UniRx.Async/IAwaiter.cs | 21 + Assets/UniRx.Async/Internal/PromisePool.cs | 53 ++ .../UniRx.Async/Internal/PromisePool.cs.meta | 11 + Assets/UniRx.Async/Internal/TaskTracker.cs | 118 ++++ Assets/UniRx.Async/UniTask.Factory.cs | 11 + Assets/UniRx.Async/UniTask.cs | 614 ++++++++++++++++++ Assets/UniRx.Async/UniTaskCompletionSource.cs | 584 +++++++++++++++++ Assets/UniRx.Async/UniTaskScheduler.cs | 8 +- Assets/UniRx.Async/UnityAsyncExtensions.cs | 121 ++++ ProjectSettings/EditorBuildSettings.asset | 6 +- ProjectSettings/ProjectSettings.asset | 64 +- ProjectSettings/UnityConnectSettings.asset | 2 +- 20 files changed, 2325 insertions(+), 105 deletions(-) create mode 100644 Assets/UniRx.Async/Internal/PromisePool.cs create mode 100644 Assets/UniRx.Async/Internal/PromisePool.cs.meta diff --git a/Assets/Scenes/SandboxMain.cs b/Assets/Scenes/SandboxMain.cs index 1faf82d..f8c9e07 100644 --- a/Assets/Scenes/SandboxMain.cs +++ b/Assets/Scenes/SandboxMain.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Threading; +using System.Threading.Tasks; using UniRx.Async; using UnityEngine; using UnityEngine.Networking; @@ -12,15 +13,111 @@ public class SandboxMain : MonoBehaviour { public Button okButton; public Button cancelButton; + public Text text; + CancellationTokenSource cts; - async void Start() + UniTaskCompletionSource2 ucs; + + void Start() { - UnityEngine.Debug.Log("DOWNLOAD START:" + Time.frameCount); + // Setup unobserverd tskexception handling + TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; - var req = await UnityWebRequest.Get(Path.Combine(Application.streamingAssetsPath, "test.txt")).SendWebRequest(); + // Optional: disable ExecutionContext if you don't use AsyncLocal. + //if (!ExecutionContext.IsFlowSuppressed()) + //{ + // ExecutionContext.SuppressFlow(); + //} - UnityEngine.Debug.Log("DOWNLOAD RESULT:" + Time.frameCount + ", " + req.downloadHandler.text); + //// Optional: disable SynchronizationContext(to boostup performance) if you completely use UniTask only + //SynchronizationContext.SetSynchronizationContext(null); + + // ----- + + Application.logMessageReceived += Application_logMessageReceived; + + + ucs = new UniTaskCompletionSource2(); + + okButton.onClick.AddListener(UniTask.VoidUnityAction(async () => + { + await OuterAsync(true); + })); + + cancelButton.onClick.AddListener(async () => + { + text.text = ""; + + ucs.SetResult(); + + await ucs.Task; + }); + } + + private void Application_logMessageReceived(string condition, string stackTrace, LogType type) + { + text.text += "\n" + condition; + } + + async UniTask2 OuterAsync(bool b) + { + UnityEngine.Debug.Log("START OUTER"); + + await InnerAsync(b); + await InnerAsync(b); + + UnityEngine.Debug.Log("END OUTER"); + + // throw new InvalidOperationException("NAZO ERROR!?"); // error!? + } + + async UniTask2 InnerAsync(bool b) + { + if (b) + { + UnityEngine.Debug.Log("Start delay:" + Time.frameCount); + await UniTask2.DelayFrame(60); + UnityEngine.Debug.Log("End delay:" + Time.frameCount); + await UniTask2.DelayFrame(60); + UnityEngine.Debug.Log("Onemore end delay:" + Time.frameCount); + } + else + { + //UnityEngine.Debug.Log("Empty END"); + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) + { + // e.SetObserved(); + // or other custom write code. + UnityEngine.Debug.LogError("Unobserved:" + e.Exception.ToString()); } } diff --git a/Assets/Scenes/SandboxMain.unity b/Assets/Scenes/SandboxMain.unity index 59e7906..8f96fdb 100644 --- a/Assets/Scenes/SandboxMain.unity +++ b/Assets/Scenes/SandboxMain.unity @@ -96,6 +96,7 @@ LightmapSettings: m_PVRFilteringAtrousPositionSigmaAO: 1 m_ExportTrainingData: 0 m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 m_LightingDataAsset: {fileID: 0} m_UseShadowmask: 1 --- !u!196 &4 @@ -168,7 +169,7 @@ MonoBehaviour: m_GameObject: {fileID: 16537670} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} m_Name: m_EditorClassIdentifier: m_Navigation: @@ -202,8 +203,6 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] - m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, - Culture=neutral, PublicKeyToken=null --- !u!114 &16537673 MonoBehaviour: m_ObjectHideFlags: 0 @@ -213,7 +212,7 @@ MonoBehaviour: m_GameObject: {fileID: 16537670} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} @@ -222,8 +221,6 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, - Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} m_Type: 1 m_PreserveAspect: 0 @@ -233,6 +230,7 @@ MonoBehaviour: m_FillClockwise: 1 m_FillOrigin: 0 m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 --- !u!222 &16537674 CanvasRenderer: m_ObjectHideFlags: 0 @@ -282,6 +280,7 @@ MonoBehaviour: m_EditorClassIdentifier: okButton: {fileID: 16537672} cancelButton: {fileID: 628393011} + text: {fileID: 2101290655} --- !u!20 &519420031 Camera: m_ObjectHideFlags: 0 @@ -387,7 +386,7 @@ MonoBehaviour: m_GameObject: {fileID: 628393009} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} m_Name: m_EditorClassIdentifier: m_Navigation: @@ -421,8 +420,6 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] - m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, - Culture=neutral, PublicKeyToken=null --- !u!114 &628393012 MonoBehaviour: m_ObjectHideFlags: 0 @@ -432,7 +429,7 @@ MonoBehaviour: m_GameObject: {fileID: 628393009} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} @@ -441,8 +438,6 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, - Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} m_Type: 1 m_PreserveAspect: 0 @@ -452,6 +447,7 @@ MonoBehaviour: m_FillClockwise: 1 m_FillOrigin: 0 m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 --- !u!222 &628393013 CanvasRenderer: m_ObjectHideFlags: 0 @@ -506,7 +502,7 @@ MonoBehaviour: m_GameObject: {fileID: 865871444} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} @@ -515,8 +511,6 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, - Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_FontData: m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} m_FontSize: 14 @@ -566,7 +560,7 @@ MonoBehaviour: m_GameObject: {fileID: 872009839} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 1077351063, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3} m_Name: m_EditorClassIdentifier: m_HorizontalAxis: Horizontal @@ -585,7 +579,7 @@ MonoBehaviour: m_GameObject: {fileID: 872009839} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: -619905303, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3} m_Name: m_EditorClassIdentifier: m_FirstSelected: {fileID: 0} @@ -633,7 +627,7 @@ MonoBehaviour: m_GameObject: {fileID: 1556045504} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} m_Name: m_EditorClassIdentifier: m_IgnoreReversedGraphics: 1 @@ -650,7 +644,7 @@ MonoBehaviour: m_GameObject: {fileID: 1556045504} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} m_Name: m_EditorClassIdentifier: m_UiScaleMode: 0 @@ -697,6 +691,7 @@ RectTransform: m_Children: - {fileID: 16537671} - {fileID: 628393010} + - {fileID: 2101290654} m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -751,7 +746,7 @@ MonoBehaviour: m_GameObject: {fileID: 1584557231} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} @@ -760,8 +755,6 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, - Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_FontData: m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} m_FontSize: 14 @@ -786,3 +779,80 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1584557231} m_CullTransparentMesh: 0 +--- !u!1 &2101290653 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2101290654} + - component: {fileID: 2101290656} + - component: {fileID: 2101290655} + m_Layer: 0 + m_Name: Text + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2101290654 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2101290653} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1556045508} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 1.5, y: -61.4} + m_SizeDelta: {x: 588.7, y: 398.7} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2101290655 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2101290653} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: New Text +--- !u!222 &2101290656 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2101290653} + m_CullTransparentMesh: 0 diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs index 586f859..1d15f0b 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs @@ -5,10 +5,12 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security; namespace UniRx.Async.CompilerServices { + // TODO:Remove public struct AsyncUniTaskMethodBuilder { UniTaskCompletionSource promise; @@ -138,7 +140,7 @@ namespace UniRx.Async.CompilerServices } } - + // TODO:Remove public struct AsyncUniTaskMethodBuilder { T result; @@ -269,6 +271,247 @@ namespace UniRx.Async.CompilerServices { } } + + + + + + [StructLayout(LayoutKind.Auto)] + public struct AsyncUniTask2MethodBuilder + { + // cache items. + AutoResetUniTaskCompletionSource promise; + IMoveNextRunner runner; + + // 1. Static Create method. + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncUniTask2MethodBuilder Create() + { + return default; + } + + // 2. TaskLike Task property. + public UniTask2 Task + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + return promise.Task; + } + } + + // 3. SetException + [DebuggerHidden] + public void SetException(Exception exception) + { + // runner is finished, return first. + if (runner != null) + { + runner.Return(); + runner = null; + } + + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + promise.SetException(exception); + } + + // 4. SetResult + [DebuggerHidden] + public void SetResult() + { + // runner is finished, return first. + if (runner != null) + { + runner.Return(); + runner = null; + } + + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + promise.SetResult(); + } + + // 5. AwaitOnCompleted + [DebuggerHidden] + public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : INotifyCompletion + where TStateMachine : IAsyncStateMachine + { + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + if (runner == null) + { + runner = MoveNextRunner2.Create(ref stateMachine); + } + + awaiter.OnCompleted(runner.CallMoveNext); + } + + // 6. AwaitUnsafeOnCompleted + [DebuggerHidden] + [SecuritySafeCritical] + public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : ICriticalNotifyCompletion + where TStateMachine : IAsyncStateMachine + { + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + if (runner == null) + { + runner = MoveNextRunner2.Create(ref stateMachine); + } + + awaiter.OnCompleted(runner.CallMoveNext); + } + + // 7. Start + [DebuggerHidden] + public void Start(ref TStateMachine stateMachine) + where TStateMachine : IAsyncStateMachine + { + stateMachine.MoveNext(); + } + + // 8. SetStateMachine + [DebuggerHidden] + public void SetStateMachine(IAsyncStateMachine stateMachine) + { + // don't use boxed stateMachine. + } + } + + [StructLayout(LayoutKind.Auto)] + public struct AsyncUniTask2MethodBuilder + { + // cache items. + AutoResetUniTaskCompletionSource promise; + IMoveNextRunner runner; + + // 1. Static Create method. + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncUniTask2MethodBuilder Create() + { + return default; + } + + // 2. TaskLike Task property. + [DebuggerHidden] + public UniTask2 Task + { + get + { + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + return promise.Task; + } + } + + // 3. SetException + [DebuggerHidden] + public void SetException(Exception exception) + { + // runner is finished, return first. + if (runner != null) + { + runner.Return(); + runner = null; + } + + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + promise.SetException(exception); + } + + // 4. SetResult + [DebuggerHidden] + public void SetResult(T result) + { + // runner is finished, return first. + if (runner != null) + { + runner.Return(); + runner = null; + } + + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + promise.SetResult(result); + } + + // 5. AwaitOnCompleted + [DebuggerHidden] + public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : INotifyCompletion + where TStateMachine : IAsyncStateMachine + { + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + if (runner == null) + { + runner = MoveNextRunner2.Create(ref stateMachine); + } + + awaiter.OnCompleted(runner.CallMoveNext); + } + + // 6. AwaitUnsafeOnCompleted + [DebuggerHidden] + [SecuritySafeCritical] + public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : ICriticalNotifyCompletion + where TStateMachine : IAsyncStateMachine + { + if (promise == null) + { + promise = AutoResetUniTaskCompletionSource.Create(); + } + if (runner == null) + { + runner = MoveNextRunner2.Create(ref stateMachine); + } + + awaiter.OnCompleted(runner.CallMoveNext); + } + + // 7. Start + [DebuggerHidden] + public void Start(ref TStateMachine stateMachine) + where TStateMachine : IAsyncStateMachine + { + stateMachine.MoveNext(); + } + + // 8. SetStateMachine + [DebuggerHidden] + public void SetStateMachine(IAsyncStateMachine stateMachine) + { + // don't use boxed stateMachine. + } + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs index 2fcd55f..9fad249 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs @@ -11,23 +11,38 @@ namespace UniRx.Async.CompilerServices { public struct AsyncUniTaskVoidMethodBuilder { - Action moveNext; + IMoveNextRunner runner; // 1. Static Create method. [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncUniTaskVoidMethodBuilder Create() { - var builder = new AsyncUniTaskVoidMethodBuilder(); - return builder; + return default; } // 2. TaskLike Task property(void) - public UniTaskVoid Task => default(UniTaskVoid); + public UniTaskVoid Task + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return default; + } + } // 3. SetException [DebuggerHidden] public void SetException(Exception exception) { + // runner is finished, return first. + if (runner != null) + { + runner.Return(); + runner = null; + } + UniTaskScheduler.PublishUnobservedTaskException(exception); } @@ -35,7 +50,12 @@ namespace UniRx.Async.CompilerServices [DebuggerHidden] public void SetResult() { - // do nothing + // runner is finished, return. + if (runner != null) + { + runner.Return(); + runner = null; + } } // 5. AwaitOnCompleted @@ -44,14 +64,12 @@ namespace UniRx.Async.CompilerServices where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { - if (moveNext == null) + if (runner == null) { - var runner = new MoveNextRunner(); - moveNext = runner.Run; - runner.StateMachine = stateMachine; // set after create delegate. + runner = MoveNextRunner2.Create(ref stateMachine); } - awaiter.OnCompleted(moveNext); + awaiter.OnCompleted(runner.CallMoveNext); } // 6. AwaitUnsafeOnCompleted @@ -61,14 +79,12 @@ namespace UniRx.Async.CompilerServices where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { - if (moveNext == null) + if (runner == null) { - var runner = new MoveNextRunner(); - moveNext = runner.Run; - runner.StateMachine = stateMachine; // set after create delegate. + runner = MoveNextRunner2.Create(ref stateMachine); } - awaiter.UnsafeOnCompleted(moveNext); + awaiter.OnCompleted(runner.CallMoveNext); } // 7. Start @@ -83,6 +99,7 @@ namespace UniRx.Async.CompilerServices [DebuggerHidden] public void SetStateMachine(IAsyncStateMachine stateMachine) { + // don't use boxed stateMachine. } } } diff --git a/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs b/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs index ddf7a03..7c7155f 100644 --- a/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs +++ b/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs @@ -2,11 +2,14 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using UniRx.Async.Internal; namespace UniRx.Async.CompilerServices { + // TODO: Remove it. internal class MoveNextRunner where TStateMachine : IAsyncStateMachine { @@ -18,6 +21,52 @@ namespace UniRx.Async.CompilerServices StateMachine.MoveNext(); } } + + internal interface IMoveNextRunner + { + Action CallMoveNext { get; } + void Return(); + } + + internal class MoveNextRunner2 : IMoveNextRunner, IPromisePoolItem + where TStateMachine : IAsyncStateMachine + { + static PromisePool> pool = new PromisePool>(); + + TStateMachine stateMachine; + internal readonly Action callMoveNext; + + public Action CallMoveNext => callMoveNext; + + MoveNextRunner2() + { + callMoveNext = MoveNext; + } + + public static MoveNextRunner2 Create(ref TStateMachine stateMachine) + { + var result = pool.TryRent() ?? new MoveNextRunner2(); + result.stateMachine = stateMachine; + return result; + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void MoveNext() + { + stateMachine.MoveNext(); + } + + public void Return() + { + pool.TryReturn(this); + } + + void IPromisePoolItem.Reset() + { + stateMachine = default; + } + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/DiagnosticsExtensions.cs b/Assets/UniRx.Async/DiagnosticsExtensions.cs index 041b0c3..d0dfd33 100644 --- a/Assets/UniRx.Async/DiagnosticsExtensions.cs +++ b/Assets/UniRx.Async/DiagnosticsExtensions.cs @@ -13,9 +13,11 @@ using System.Security; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using UnityEngine; namespace UniRx.Async { + // TODO: Internal. public static class DiagnosticsExtensions { static bool displayFilenames = true; @@ -45,36 +47,6 @@ namespace UniRx.Async { typeof(UniTaskVoid), "UniTaskVoid" } }; - public static string ToStringWithCleanupAsyncStackTrace(this Exception exception) - { - if (exception == null) return ""; - - String message = exception.Message; - String s; - - if (message == null || message.Length <= 0) - { - s = exception.GetType().ToString(); - } - else - { - s = exception.GetType().ToString() + ": " + message; - } - - if (exception.InnerException != null) - { - s = s + " ---> " + exception.InnerException.ToString() + Environment.NewLine + " Exception_EndOfInnerExceptionStack"; - } - - string stackTrace = new StackTrace(exception).CleanupAsyncStackTrace(); - if (stackTrace != null) - { - s += Environment.NewLine + stackTrace; - } - - return s; - } - public static string CleanupAsyncStackTrace(this StackTrace stackTrace) { if (stackTrace == null) return ""; @@ -143,7 +115,7 @@ namespace UniRx.Async if (fileName != null) { sb.Append(' '); - sb.AppendFormat(CultureInfo.InvariantCulture, "in {0}:{1}", SimplifyPath(fileName), sf.GetFileLineNumber()); + sb.AppendFormat(CultureInfo.InvariantCulture, "(at {0})", AppendHyperLink(fileName, sf.GetFileLineNumber().ToString())); } } @@ -212,7 +184,7 @@ namespace UniRx.Async { return "(" + string.Join(", ", t.GetGenericArguments().Select(x => BeautifyType(x, true))) + ")"; } - if (!t.IsGenericType) return shortName ? t.Name : t.FullName ?? t.Name; + if (!t.IsGenericType) return shortName ? t.Name : t.FullName.Replace("UniRx.Async.Triggers.", "").Replace("UniRx.Async.Internal.", "").Replace("UniRx.Async.", "") ?? t.Name; var innerFormat = string.Join(", ", t.GetGenericArguments().Select(x => BeautifyType(x, true))); @@ -222,7 +194,7 @@ namespace UniRx.Async genericType = "Task"; } - return typeBeautifyRegex.Replace(genericType, "") + "<" + innerFormat + ">"; + return typeBeautifyRegex.Replace(genericType, "").Replace("UniRx.Async.Triggers.", "").Replace("UniRx.Async.Internal.", "").Replace("UniRx.Async.", "") + "<" + innerFormat + ">"; } static bool IgnoreLine(MethodBase methodInfo) @@ -248,11 +220,19 @@ namespace UniRx.Async { return true; } + else if (declareType.StartsWith("UniRx.Async.UniTaskCompletionSourceCore")) + { + return true; + } + else if (declareType.StartsWith("UniRx.Async.AwaiterActions")) + { + return true; + } return false; } - static string SimplifyPath(string path) + static string AppendHyperLink(string path, string line) { var fi = new FileInfo(path); if (fi.Directory == null) @@ -261,7 +241,9 @@ namespace UniRx.Async } else { - return fi.Directory.Name + "/" + fi.Name; + var fname = fi.FullName.Replace(Path.DirectorySeparatorChar, '/').Replace(Application.dataPath, ""); + var withAssetsPath = "Assets/" + fname; + return "" + withAssetsPath + ":" + line + ""; } } } diff --git a/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs b/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs index 7e03931..7e5e3cd 100644 --- a/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs +++ b/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs @@ -10,11 +10,14 @@ using System; using UnityEditor.IMGUI.Controls; using UniRx.Async.Internal; using System.Text; +using System.Text.RegularExpressions; namespace UniRx.Async.Editor { public class UniTaskTrackerViewItem : TreeViewItem { + static Regex removeHref = new Regex("(.+)", RegexOptions.Compiled); + public string TaskType { get; set; } public string Elapsed { get; set; } public string Status { get; set; } @@ -43,7 +46,8 @@ namespace UniRx.Async.Editor } sb.Append(str[i]); } - return sb.ToString(); + + return removeHref.Replace(sb.ToString(), "$1"); } public UniTaskTrackerViewItem(int id) : base(id) @@ -128,7 +132,7 @@ namespace UniRx.Async.Editor var children = new List(); - TaskTracker.ForEachActiveTask((trackingId, awaiterType, status, created, stackTrace) => + TaskTracker2.ForEachActiveTask((trackingId, awaiterType, status, created, stackTrace) => { children.Add(new UniTaskTrackerViewItem(trackingId) { TaskType = awaiterType, Status = status.ToString(), Elapsed = (DateTime.UtcNow - created).TotalSeconds.ToString("00.00"), Position = stackTrace }); }); diff --git a/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs b/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs index 73bbb18..f35e1f8 100644 --- a/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs +++ b/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs @@ -12,6 +12,7 @@ using UniRx.Async.Internal; namespace UniRx.Async.Editor { + // TODO:Remove public class UniTaskTrackerWindow : EditorWindow { static int interval; @@ -206,6 +207,202 @@ namespace UniRx.Async.Editor #endregion } + + public class UniTaskTrackerWindow2 : EditorWindow + { + static int interval; + + static UniTaskTrackerWindow2 window; + + // TODO:Remove 2 + [MenuItem("Window/UniTask Tracker 2")] + public static void OpenWindow() + { + if (window != null) + { + window.Close(); + } + + // will called OnEnable(singleton instance will be set). + GetWindow("UniTask Tracker").Show(); + } + + static readonly GUILayoutOption[] EmptyLayoutOption = new GUILayoutOption[0]; + + UniTaskTrackerTreeView treeView; + object splitterState; + + void OnEnable() + { + window = this; // set singleton. + splitterState = SplitterGUILayout.CreateSplitterState(new float[] { 75f, 25f }, new int[] { 32, 32 }, null); + treeView = new UniTaskTrackerTreeView(); + TaskTracker2.EditorEnableState.EnableAutoReload = EditorPrefs.GetBool(TaskTracker2.EnableAutoReloadKey, false); + TaskTracker2.EditorEnableState.EnableTracking = EditorPrefs.GetBool(TaskTracker2.EnableTrackingKey, false); + TaskTracker2.EditorEnableState.EnableStackTrace = EditorPrefs.GetBool(TaskTracker2.EnableStackTraceKey, false); + } + + void OnGUI() + { + // Head + RenderHeadPanel(); + + // Splittable + SplitterGUILayout.BeginVerticalSplit(this.splitterState, EmptyLayoutOption); + { + // Column Tabble + RenderTable(); + + // StackTrace details + RenderDetailsPanel(); + } + SplitterGUILayout.EndVerticalSplit(); + } + + #region HeadPanel + + public static bool EnableAutoReload => TaskTracker2.EditorEnableState.EnableAutoReload; + public static bool EnableTracking => TaskTracker2.EditorEnableState.EnableTracking; + public static bool EnableStackTrace => TaskTracker2.EditorEnableState.EnableStackTrace; + static readonly GUIContent EnableAutoReloadHeadContent = EditorGUIUtility.TrTextContent("Enable AutoReload", "Reload automatically.", (Texture)null); + static readonly GUIContent ReloadHeadContent = EditorGUIUtility.TrTextContent("Reload", "Reload View.", (Texture)null); + static readonly GUIContent GCHeadContent = EditorGUIUtility.TrTextContent("GC.Collect", "Invoke GC.Collect.", (Texture)null); + static readonly GUIContent EnableTrackingHeadContent = EditorGUIUtility.TrTextContent("Enable Tracking", "Start to track async/await UniTask. Performance impact: low", (Texture)null); + static readonly GUIContent EnableStackTraceHeadContent = EditorGUIUtility.TrTextContent("Enable StackTrace", "Capture StackTrace when task is started. Performance impact: high", (Texture)null); + + // [Enable Tracking] | [Enable StackTrace] + void RenderHeadPanel() + { + EditorGUILayout.BeginVertical(EmptyLayoutOption); + EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, EmptyLayoutOption); + + if (GUILayout.Toggle(EnableAutoReload, EnableAutoReloadHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableAutoReload) + { + TaskTracker2.EditorEnableState.EnableAutoReload = !EnableAutoReload; + } + + if (GUILayout.Toggle(EnableTracking, EnableTrackingHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableTracking) + { + TaskTracker2.EditorEnableState.EnableTracking = !EnableTracking; + } + + if (GUILayout.Toggle(EnableStackTrace, EnableStackTraceHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableStackTrace) + { + TaskTracker2.EditorEnableState.EnableStackTrace = !EnableStackTrace; + } + + GUILayout.FlexibleSpace(); + + if (GUILayout.Button(ReloadHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption)) + { + TaskTracker2.CheckAndResetDirty(); + treeView.ReloadAndSort(); + Repaint(); + } + + if (GUILayout.Button(GCHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption)) + { + GC.Collect(0); + } + + EditorGUILayout.EndHorizontal(); + EditorGUILayout.EndVertical(); + } + + #endregion + + #region TableColumn + + Vector2 tableScroll; + GUIStyle tableListStyle; + + void RenderTable() + { + if (tableListStyle == null) + { + tableListStyle = new GUIStyle("CN Box"); + tableListStyle.margin.top = 0; + tableListStyle.padding.left = 3; + } + + EditorGUILayout.BeginVertical(tableListStyle, EmptyLayoutOption); + + this.tableScroll = EditorGUILayout.BeginScrollView(this.tableScroll, new GUILayoutOption[] + { + GUILayout.ExpandWidth(true), + GUILayout.MaxWidth(2000f) + }); + var controlRect = EditorGUILayout.GetControlRect(new GUILayoutOption[] + { + GUILayout.ExpandHeight(true), + GUILayout.ExpandWidth(true) + }); + + + treeView?.OnGUI(controlRect); + + EditorGUILayout.EndScrollView(); + EditorGUILayout.EndVertical(); + } + + private void Update() + { + if (EnableAutoReload) + { + if (interval++ % 120 == 0) + { + if (TaskTracker2.CheckAndResetDirty()) + { + treeView.ReloadAndSort(); + Repaint(); + } + } + } + } + + #endregion + + #region Details + + static GUIStyle detailsStyle; + Vector2 detailsScroll; + + void RenderDetailsPanel() + { + if (detailsStyle == null) + { + detailsStyle = new GUIStyle("CN Message"); + detailsStyle.wordWrap = false; + detailsStyle.stretchHeight = true; + detailsStyle.margin.right = 15; + } + + string message = ""; + var selected = treeView.state.selectedIDs; + if (selected.Count > 0) + { + var first = selected[0]; + var item = treeView.CurrentBindingItems.FirstOrDefault(x => x.id == first) as UniTaskTrackerViewItem; + if (item != null) + { + message = item.Position; + } + } + + detailsScroll = EditorGUILayout.BeginScrollView(this.detailsScroll, EmptyLayoutOption); + var vector = detailsStyle.CalcSize(new GUIContent(message)); + EditorGUILayout.SelectableLabel(message, detailsStyle, new GUILayoutOption[] + { + GUILayout.ExpandHeight(true), + GUILayout.ExpandWidth(true), + GUILayout.MinWidth(vector.x), + GUILayout.MinHeight(vector.y) + }); + EditorGUILayout.EndScrollView(); + } + + #endregion + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/IAwaiter.cs b/Assets/UniRx.Async/IAwaiter.cs index 6450ea5..46708d1 100644 --- a/Assets/UniRx.Async/IAwaiter.cs +++ b/Assets/UniRx.Async/IAwaiter.cs @@ -1,10 +1,13 @@ #if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) #pragma warning disable CS1591 +using System; using System.Runtime.CompilerServices; namespace UniRx.Async { + // TODO:rename to UniTaskStatus + public enum AwaiterStatus { ///

The operation has not yet completed. @@ -17,6 +20,24 @@ namespace UniRx.Async Canceled = 3 } + + + // similar as IValueTaskSource + public interface IUniTaskSource + { + AwaiterStatus GetStatus(short token); + void OnCompleted(Action continuation, object state, short token); + void GetResult(short token); + + AwaiterStatus UnsafeGetStatus(); // only for debug use. + } + + public interface IUniTaskSource : IUniTaskSource + { + new T GetResult(short token); + } + + public interface IAwaiter : ICriticalNotifyCompletion { AwaiterStatus Status { get; } diff --git a/Assets/UniRx.Async/Internal/PromisePool.cs b/Assets/UniRx.Async/Internal/PromisePool.cs new file mode 100644 index 0000000..5667bac --- /dev/null +++ b/Assets/UniRx.Async/Internal/PromisePool.cs @@ -0,0 +1,53 @@ +using System.Collections.Concurrent; +using System.Runtime.CompilerServices; +using System.Threading; + +namespace UniRx.Async.Internal +{ + internal interface IPromisePoolItem + { + void Reset(); + } + + internal class PromisePool + where T : class, IPromisePoolItem + { + int count = 0; + readonly ConcurrentQueue queue = new ConcurrentQueue(); + readonly int maxSize; + + public PromisePool(int maxSize = 256) + { + this.maxSize = maxSize; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public T TryRent() + { + if (queue.TryDequeue(out var value)) + { + Interlocked.Decrement(ref count); + return value; + } + + return null; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool TryReturn(T value) + { + value.Reset(); // reset when return. + + if (count < maxSize) + { + queue.Enqueue(value); + Interlocked.Increment(ref count); + return true; + } + else + { + return false; + } + } + } +} diff --git a/Assets/UniRx.Async/Internal/PromisePool.cs.meta b/Assets/UniRx.Async/Internal/PromisePool.cs.meta new file mode 100644 index 0000000..76cc60b --- /dev/null +++ b/Assets/UniRx.Async/Internal/PromisePool.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fcb1f7467a3e2b64c8a016c8aee2f9b4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/Internal/TaskTracker.cs b/Assets/UniRx.Async/Internal/TaskTracker.cs index 9d2e65c..a1d2ae6 100644 --- a/Assets/UniRx.Async/Internal/TaskTracker.cs +++ b/Assets/UniRx.Async/Internal/TaskTracker.cs @@ -10,6 +10,7 @@ namespace UniRx.Async.Internal { // public for add user custom. + // TODO: Remove public static class TaskTracker { #if UNITY_EDITOR @@ -147,6 +148,123 @@ namespace UniRx.Async.Internal } } } + + public static class TaskTracker2 + { +#if UNITY_EDITOR + + static int trackingId = 0; + + public const string EnableAutoReloadKey = "UniTaskTrackerWindow_EnableAutoReloadKey"; + public const string EnableTrackingKey = "UniTaskTrackerWindow_EnableTrackingKey"; + public const string EnableStackTraceKey = "UniTaskTrackerWindow_EnableStackTraceKey"; + + public static class EditorEnableState + { + static bool enableAutoReload; + public static bool EnableAutoReload + { + get { return enableAutoReload; } + set + { + enableAutoReload = value; + UnityEditor.EditorPrefs.SetBool(EnableAutoReloadKey, value); + } + } + + static bool enableTracking; + public static bool EnableTracking + { + get { return enableTracking; } + set + { + enableTracking = value; + UnityEditor.EditorPrefs.SetBool(EnableTrackingKey, value); + } + } + + static bool enableStackTrace; + public static bool EnableStackTrace + { + get { return enableStackTrace; } + set + { + enableStackTrace = value; + UnityEditor.EditorPrefs.SetBool(EnableStackTraceKey, value); + } + } + } + +#endif + + + static List> listPool = new List>(); + + static readonly WeakDictionary tracking = new WeakDictionary(); + + [Conditional("UNITY_EDITOR")] + public static void TrackActiveTask(IUniTaskSource task, int skipFrame) + { +#if UNITY_EDITOR + dirty = true; + if (!EditorEnableState.EnableTracking) return; + var stackTrace = EditorEnableState.EnableStackTrace ? new StackTrace(skipFrame, true).CleanupAsyncStackTrace() : ""; + tracking.TryAdd(task, (Interlocked.Increment(ref trackingId), DateTime.UtcNow, stackTrace)); +#endif + } + + [Conditional("UNITY_EDITOR")] + public static void RemoveTracking(IUniTaskSource task) + { +#if UNITY_EDITOR + dirty = true; + if (!EditorEnableState.EnableTracking) return; + var success = tracking.TryRemove(task); +#endif + } + + static bool dirty; + + public static bool CheckAndResetDirty() + { + var current = dirty; + dirty = false; + return current; + } + + /// (trackingId, awaiterType, awaiterStatus, createdTime, stackTrace) + public static void ForEachActiveTask(Action action) + { + lock (listPool) + { + var count = tracking.ToList(ref listPool, clear: false); + try + { + for (int i = 0; i < count; i++) + { + string typeName = null; + var keyType = listPool[i].Key.GetType(); + if (keyType.IsNested) + { + typeName = keyType.DeclaringType.Name + "." + keyType.Name; + } + else + { + typeName = keyType.Name; + } + + action(listPool[i].Value.trackingId, typeName, listPool[i].Key.UnsafeGetStatus(), listPool[i].Value.addTime, listPool[i].Value.stackTrace); + listPool[i] = new KeyValuePair(null, (0, default(DateTime), null)); // clear + } + } + catch + { + listPool.Clear(); + throw; + } + } + } + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.Factory.cs b/Assets/UniRx.Async/UniTask.Factory.cs index 0150450..291ce5c 100644 --- a/Assets/UniRx.Async/UniTask.Factory.cs +++ b/Assets/UniRx.Async/UniTask.Factory.cs @@ -3,6 +3,7 @@ using System; using System.Threading; +using UnityEngine.Events; namespace UniRx.Async { @@ -86,6 +87,16 @@ namespace UniRx.Async asyncAction().Forget(); } + public static Action VoidAction(Func asyncAction) + { + return () => Void(asyncAction); + } + + public static UnityAction VoidUnityAction(Func asyncAction) + { + return () => Void(asyncAction); + } + /// /// helper of create add UniTaskVoid to delegate. /// For example: FooEvent += (sender, e) => UniTask.Void(async arg => { /* */ }, (sender, e)) diff --git a/Assets/UniRx.Async/UniTask.cs b/Assets/UniRx.Async/UniTask.cs index 7b80b45..72779bd 100644 --- a/Assets/UniRx.Async/UniTask.cs +++ b/Assets/UniRx.Async/UniTask.cs @@ -3,14 +3,628 @@ #pragma warning disable CS0436 using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.ExceptionServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using System.Threading.Tasks.Sources; using UniRx.Async.CompilerServices; using UniRx.Async.Internal; namespace UniRx.Async { + + + public partial struct UniTask2 + { + public static UniTask2 DelayFrame(int frameCount, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default) + { + return new UniTask2(DelayPromiseCore2.Create(frameCount, timing, cancellationToken, out var token), token); + + + //return new ValueTask(DelayPromiseCore2.Create(frameCount, timing, cancellationToken, out var token), token); + } + + } + + + public class DelayPromiseCore2 : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + int delayFrameCount; + CancellationToken cancellationToken; + + int currentFrameCount; + UniTaskCompletionSourceCore core; + + DelayPromiseCore2() + { + } + + public static IUniTaskSource Create(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new DelayPromiseCore2(); + + result.delayFrameCount = delayFrameCount; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + TaskTracker2.RemoveTracking(this); + core.SetCancellation(cancellationToken); + return false; + } + + if (currentFrameCount == delayFrameCount) + { + TaskTracker2.RemoveTracking(this); + core.SetResult(null); + return false; + } + + currentFrameCount++; + return true; + } + + public void Reset() + { + core.Reset(); + currentFrameCount = default; + delayFrameCount = default; + cancellationToken = default; + } + } + + + + + + + + + /// + /// Lightweight unity specified task-like object. + /// + [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder))] // TODO:AsyncUniTask2 + public partial struct UniTask2 + { + // static readonly UniTask DefaultAsyncUnitTask = new UniTask(AsyncUnit.Default); + + readonly IUniTaskSource awaiter; + readonly short token; + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public UniTask2(IUniTaskSource awaiter, short token) + { + this.awaiter = awaiter; + this.token = token; + } + + public AwaiterStatus Status + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return awaiter.GetStatus(token); + } + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Awaiter GetAwaiter() + { + return new Awaiter(this); + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void GetResult() + { + awaiter.GetResult(token); + } + + // TODO:can be suppress? + + ///// + ///// returns (bool IsCanceled) instead of throws OperationCanceledException. + ///// + //public UniTask SuppressCancellationThrow() + //{ + // var status = Status; + // if (status == AwaiterStatus.Succeeded) return CompletedTasks.False; + // if (status == AwaiterStatus.Canceled) return CompletedTasks.True; + // //return new UniTask(new IsCanceledAwaiter(awaiter)); + //} + + public override string ToString() + { + var status = this.awaiter.UnsafeGetStatus(); + return (status == AwaiterStatus.Succeeded) ? "()" : "(" + status + ")"; + } + + //public static implicit operator UniTask(UniTask2 task) + //{ + // // TODO: + // throw new NotImplementedException(); + + // //if (task.awaiter != null) + // //{ + // // if (task.awaiter.IsCompleted) + // // { + // // return DefaultAsyncUnitTask; + // // } + // // else + // // { + // // // UniTask -> UniTask is free but UniTask -> UniTask requires wrapping cost. + // // return new UniTask(new AsyncUnitAwaiter(task.awaiter)); + // // } + // //} + // //else + // //{ + // // return DefaultAsyncUnitTask; + // //} + //} + + //class AsyncUnitAwaiter : IAwaiter + //{ + // readonly IAwaiter2 awaiter; + + // public AsyncUnitAwaiter(IAwaiter2 awaiter) + // { + // this.awaiter = awaiter; + // } + + // public bool IsCompleted => awaiter.IsCompleted; + + // public AwaiterStatus Status => awaiter.Status; + + // public AsyncUnit GetResult() + // { + // awaiter.GetResult(); + // return AsyncUnit.Default; + // } + + // public void OnCompleted(Action continuation) + // { + // awaiter.OnCompleted(continuation); + // } + + // public void UnsafeOnCompleted(Action continuation) + // { + // awaiter.UnsafeOnCompleted(continuation); + // } + + // void IAwaiter.GetResult() + // { + // awaiter.GetResult(); + // } + //} + + class IsCanceledAwaiter : IUniTaskSource + { + readonly IUniTaskSource awaiter; + + public IsCanceledAwaiter(IUniTaskSource awaiter) + { + this.awaiter = awaiter; + } + + //public bool IsCompleted => awaiter.IsCompleted; + + //public AwaiterStatus Status => awaiter.Status; + + //public bool GetResult() + //{ + // if (awaiter.Status == AwaiterStatus.Canceled) + // { + // return true; + // } + // awaiter.GetResult(); + // return false; + //} + + //public void OnCompleted(Action continuation) + //{ + // awaiter.OnCompleted(continuation); + //} + + //public void UnsafeOnCompleted(Action continuation) + //{ + // awaiter.UnsafeOnCompleted(continuation); + //} + + //void IAwaiter.GetResult() + //{ + // awaiter.GetResult(); + //} + + public void GetResult(short token) + { + // TODO: bool + if (awaiter.GetStatus(token) == AwaiterStatus.Canceled) + { + //return true; + } + + awaiter.GetResult(token); + // return false + throw new NotImplementedException(); + } + + public AwaiterStatus GetStatus(short token) + { + return awaiter.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return awaiter.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + awaiter.OnCompleted(continuation, state, token); + } + } + + public readonly struct Awaiter : ICriticalNotifyCompletion + { + readonly UniTask2 task; + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Awaiter(in UniTask2 task) + { + this.task = task; + } + + public bool IsCompleted + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return task.Status.IsCompleted(); + } + } + + public AwaiterStatus Status + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return task.Status; + } + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void GetResult() + { + task.GetResult(); + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void OnCompleted(Action continuation) + { + task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void UnsafeOnCompleted(Action continuation) + { + task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } + } + } + + internal static class AwaiterActions + { + internal static readonly Action InvokeActionDelegate = InvokeAction; + + static void InvokeAction(object state) + { + ((Action)state).Invoke(); + } + } + + + + + /// + /// Lightweight unity specified task-like object. + /// + [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder))] // TODO:AsyncUniTask2~T + public struct UniTask2 + { + // static readonly UniTask DefaultAsyncUnitTask = new UniTask(AsyncUnit.Default); + + readonly IUniTaskSource awaiter; + readonly short token; + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public UniTask2(IUniTaskSource awaiter, short token) + { + this.awaiter = awaiter; + this.token = token; + } + + public AwaiterStatus Status + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return awaiter.GetStatus(token); + } + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Awaiter GetAwaiter() + { + return new Awaiter(this); + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + T GetResult() + { + return awaiter.GetResult(token); + } + + // TODO:can be suppress? + + ///// + ///// returns (bool IsCanceled) instead of throws OperationCanceledException. + ///// + //public UniTask SuppressCancellationThrow() + //{ + // var status = Status; + // if (status == AwaiterStatus.Succeeded) return CompletedTasks.False; + // if (status == AwaiterStatus.Canceled) return CompletedTasks.True; + // //return new UniTask(new IsCanceledAwaiter(awaiter)); + //} + + public override string ToString() + { + var status = this.awaiter.UnsafeGetStatus(); + return (status == AwaiterStatus.Succeeded) ? "()" : "(" + status + ")"; + } + + //public static implicit operator UniTask(UniTask2 task) + //{ + // // TODO: + // throw new NotImplementedException(); + + // //if (task.awaiter != null) + // //{ + // // if (task.awaiter.IsCompleted) + // // { + // // return DefaultAsyncUnitTask; + // // } + // // else + // // { + // // // UniTask -> UniTask is free but UniTask -> UniTask requires wrapping cost. + // // return new UniTask(new AsyncUnitAwaiter(task.awaiter)); + // // } + // //} + // //else + // //{ + // // return DefaultAsyncUnitTask; + // //} + //} + + //class AsyncUnitAwaiter : IAwaiter + //{ + // readonly IAwaiter2 awaiter; + + // public AsyncUnitAwaiter(IAwaiter2 awaiter) + // { + // this.awaiter = awaiter; + // } + + // public bool IsCompleted => awaiter.IsCompleted; + + // public AwaiterStatus Status => awaiter.Status; + + // public AsyncUnit GetResult() + // { + // awaiter.GetResult(); + // return AsyncUnit.Default; + // } + + // public void OnCompleted(Action continuation) + // { + // awaiter.OnCompleted(continuation); + // } + + // public void UnsafeOnCompleted(Action continuation) + // { + // awaiter.UnsafeOnCompleted(continuation); + // } + + // void IAwaiter.GetResult() + // { + // awaiter.GetResult(); + // } + //} + + class IsCanceledAwaiter : IUniTaskSource + { + readonly IUniTaskSource awaiter; + + public IsCanceledAwaiter(IUniTaskSource awaiter) + { + this.awaiter = awaiter; + } + + //public bool IsCompleted => awaiter.IsCompleted; + + //public AwaiterStatus Status => awaiter.Status; + + //public bool GetResult() + //{ + // if (awaiter.Status == AwaiterStatus.Canceled) + // { + // return true; + // } + // awaiter.GetResult(); + // return false; + //} + + //public void OnCompleted(Action continuation) + //{ + // awaiter.OnCompleted(continuation); + //} + + //public void UnsafeOnCompleted(Action continuation) + //{ + // awaiter.UnsafeOnCompleted(continuation); + //} + + //void IAwaiter.GetResult() + //{ + // awaiter.GetResult(); + //} + + public void GetResult(short token) + { + // TODO: bool + if (awaiter.GetStatus(token) == AwaiterStatus.Canceled) + { + //return true; + } + + awaiter.GetResult(token); + // return false + throw new NotImplementedException(); + } + + public AwaiterStatus GetStatus(short token) + { + return awaiter.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return awaiter.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + awaiter.OnCompleted(continuation, state, token); + } + } + + public readonly struct Awaiter : ICriticalNotifyCompletion + { + readonly UniTask2 task; + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Awaiter(in UniTask2 task) + { + this.task = task; + } + + public bool IsCompleted + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return task.Status.IsCompleted(); + } + } + + public AwaiterStatus Status + { + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return task.Status; + } + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public T GetResult() + { + return task.GetResult(); + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void OnCompleted(Action continuation) + { + task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void UnsafeOnCompleted(Action continuation) + { + task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } + } + } + + /// /// Lightweight unity specified task-like object. /// diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index c9a148d..9432666 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -6,11 +6,14 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; +using System.Runtime.InteropServices; using System.Threading; using UniRx.Async.Internal; namespace UniRx.Async { + // TODO: Remove all? + internal class ExceptionHolder { ExceptionDispatchInfo exception; @@ -408,6 +411,587 @@ namespace UniRx.Async ((ICriticalNotifyCompletion)this).UnsafeOnCompleted(continuation); } } + + [StructLayout(LayoutKind.Auto)] + public struct UniTaskCompletionSourceCore + { + // Struct Size: TResult + (8 + 2 + 1 + 1 + 8 + 8) + + TResult result; + object error; // Exception or OperationCanceledException + short version; + bool completed; + bool hasUnhandledError; + + Action continuation; + object continuationState; + + public void Reset() + { + ReportUnhandledError(); + + unchecked + { + version += 1; // incr version. + } + completed = false; + result = default; + error = null; + hasUnhandledError = false; + continuation = null; + continuationState = null; + } + + void ReportUnhandledError() + { + if (hasUnhandledError) + { + try + { + if (error is OperationCanceledException oc) + { + UniTaskScheduler.PublishUnobservedTaskException(oc); + } + else if (error is ExceptionDispatchInfo ei) + { + UniTaskScheduler.PublishUnobservedTaskException(ei.SourceException); + } + } + catch + { + } + } + } + + /// Completes with a successful result. + /// The result. + public void SetResult(TResult result) + { + this.result = result; + SignalCompletion(); + } + + /// Completes with an error. + /// The exception. + public void SetException(Exception error) + { + this.hasUnhandledError = true; + this.error = ExceptionDispatchInfo.Capture(error); + SignalCompletion(); + } + + public void SetCancellation(CancellationToken cancellationToken) + { + this.error = new OperationCanceledException(cancellationToken); + SignalCompletion(); + } + + /// Gets the operation version. + public short Version => version; + + /// Gets the status of the operation. + /// Opaque value that was provided to the 's constructor. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AwaiterStatus GetStatus(short token) + { + ValidateToken(token); + return (continuation == null || !completed) ? AwaiterStatus.Pending + : (error == null) ? AwaiterStatus.Succeeded + : (error is OperationCanceledException) ? AwaiterStatus.Canceled + : AwaiterStatus.Faulted; + } + + /// Gets the status of the operation without token validation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AwaiterStatus UnsafeGetStatus() + { + return (continuation == null || !completed) ? AwaiterStatus.Pending + : (error == null) ? AwaiterStatus.Succeeded + : (error is OperationCanceledException) ? AwaiterStatus.Canceled + : AwaiterStatus.Faulted; + } + + /// Gets the result of the operation. + /// Opaque value that was provided to the 's constructor. + // [StackTraceHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TResult GetResult(short token) + { + ValidateToken(token); + if (!completed) + { + throw new InvalidOperationException("not yet completed."); + } + + if (error != null) + { + hasUnhandledError = false; + if (error is OperationCanceledException oce) + { + throw oce; + } + else if (error is ExceptionDispatchInfo edi) + { + edi.Throw(); + } + + throw new InvalidOperationException("Critical: invalid exception type was held."); + } + + return result; + } + + /// Schedules the continuation action for this operation. + /// The continuation to invoke when the operation has completed. + /// The state object to pass to when it's invoked. + /// Opaque value that was provided to the 's constructor. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void OnCompleted(Action continuation, object state, short token /*, ValueTaskSourceOnCompletedFlags flags */) + { + if (continuation == null) + { + throw new ArgumentNullException(nameof(continuation)); + } + ValidateToken(token); + + /* no use ValueTaskSourceOnCOmpletedFlags, always no capture ExecutionContext and SynchronizationContext. */ + + object oldContinuation = this.continuation; + if (oldContinuation == null) + { + continuationState = state; + oldContinuation = Interlocked.CompareExchange(ref this.continuation, continuation, null); + } + + if (oldContinuation != null) + { + // Operation already completed, so we need to queue the supplied callback. + if (!ReferenceEquals(oldContinuation, UniTaskCompletionSourceCoreShared.s_sentinel)) + { + throw new InvalidOperationException("already completed."); + } + + continuation(state); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void ValidateToken(short token) + { + if (token != version) + { + throw new InvalidOperationException("token version is not matched."); + } + } + + /// Signals that the operation has completed. Invoked after the result or error has been set. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void SignalCompletion() + { + if (completed) + { + throw new InvalidOperationException(); + } + + completed = true; + + if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) + { + continuation(continuationState); + } + } + } + + public class UniTaskCompletionSource2 : IUniTaskSource + { + UniTaskCompletionSourceCore core; + bool handled = false; + + public UniTaskCompletionSource2() + { + TaskTracker2.TrackActiveTask(this, 2); + } + + [Conditional("UNITY_EDITOR")] + void MarkHandled() + { + if (!handled) + { + handled = true; + TaskTracker2.RemoveTracking(this); + } + } + + public UniTask2 Task + { + get + { + return new UniTask2(this, core.Version); + } + } + + public void Reset() + { + // Reset, re-active tracker + handled = false; + TaskTracker2.TrackActiveTask(this, 2); + core.Reset(); + } + + public void SetResult() + { + core.SetResult(AsyncUnit.Default); + } + + public void SetCancellation(CancellationToken cancellationToken) + { + core.SetCancellation(cancellationToken); + } + + public void SetException(Exception exception) + { + core.SetException(exception); + } + + public void GetResult(short token) + { + MarkHandled(); + core.GetResult(token); + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~UniTaskCompletionSource2() + { + // clear error information. + core.Reset(); + } + } + + public class AutoResetUniTaskCompletionSource : IUniTaskSource, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + UniTaskCompletionSourceCore core; + + AutoResetUniTaskCompletionSource() + { + } + + public static AutoResetUniTaskCompletionSource Create() + { + // TODO:Add TaskTracker + return pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); + } + + public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) + { + var source = Create(); + source.SetCancellation(cancellationToken); + token = source.core.Version; + return source; + } + + public static AutoResetUniTaskCompletionSource CreateFromException(Exception exception, out short token) + { + var source = Create(); + source.SetException(exception); + token = source.core.Version; + return source; + } + + public static AutoResetUniTaskCompletionSource CreateCompleted(out short token) + { + var source = Create(); + source.SetResult(); + token = source.core.Version; + return source; + } + + public UniTask2 Task + { + get + { + return new UniTask2(this, core.Version); + } + } + + public void SetResult() + { + core.SetResult(AsyncUnit.Default); + } + + public void SetCancellation(CancellationToken cancellationToken) + { + core.SetCancellation(cancellationToken); + } + + public void SetException(Exception exception) + { + core.SetException(exception); + } + + public void GetResult(short token) + { + try + { + // TODO:Remove TaskTracker + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + void IPromisePoolItem.Reset() + { + core.Reset(); + } + + ~AutoResetUniTaskCompletionSource() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + return; + } + } + } + + public class UniTaskCompletionSource2 : IUniTaskSource + { + UniTaskCompletionSourceCore core; + bool handled = false; + + public UniTaskCompletionSource2() + { + // TODO: TaskTracker.TrackActiveTask + } + + [Conditional("UNITY_EDITOR")] + void MarkHandled() + { + if (!handled) + { + handled = true; + // TODO: + // TaskTracker.RemoveTracking(this); + } + } + + public UniTask2 Task + { + get + { + return new UniTask2(this, core.Version); + } + } + + public void Reset() + { + // TODO:Reset, reactive tracker: TaskTracker.TrackActiveTask + handled = false; + core.Reset(); + } + + public void SetResult(T result) + { + core.SetResult(result); + } + + public void SetCancellation(CancellationToken cancellationToken) + { + core.SetCancellation(cancellationToken); + } + + public void SetException(Exception exception) + { + core.SetException(exception); + } + + public T GetResult(short token) + { + MarkHandled(); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~UniTaskCompletionSource2() + { + // clear error information. + core.Reset(); + } + } + + public class AutoResetUniTaskCompletionSource : IUniTaskSource, IPromisePoolItem + { + static readonly PromisePool> pool = new PromisePool>(); + + UniTaskCompletionSourceCore core; + + AutoResetUniTaskCompletionSource() + { + } + + public static AutoResetUniTaskCompletionSource Create() + { + // TODO:Add TaskTracker + return pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); + } + + public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) + { + var source = Create(); + source.SetCancellation(cancellationToken); + token = source.core.Version; + return source; + } + + public static AutoResetUniTaskCompletionSource CreateFromException(Exception exception, out short token) + { + var source = Create(); + source.SetException(exception); + token = source.core.Version; + return source; + } + + public static AutoResetUniTaskCompletionSource CreateFromResult(T result, out short token) + { + var source = Create(); + source.SetResult(result); + token = source.core.Version; + return source; + } + + public UniTask2 Task + { + get + { + return new UniTask2(this, core.Version); + } + } + + public void SetResult(T result) + { + core.SetResult(result); + } + + public void SetCancellation(CancellationToken cancellationToken) + { + core.SetCancellation(cancellationToken); + } + + public void SetException(Exception exception) + { + core.SetException(exception); + } + + public T GetResult(short token) + { + try + { + // TODO:Remove TaskTracker + return core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + void IPromisePoolItem.Reset() + { + core.Reset(); + } + + ~AutoResetUniTaskCompletionSource() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + return; + } + } + } + + internal static class UniTaskCompletionSourceCoreShared // separated out of generic to avoid unnecessary duplication + { + internal static readonly Action s_sentinel = CompletionSentinel; + + private static void CompletionSentinel(object _) // named method to aid debugging + { + throw new InvalidOperationException("The sentinel delegate should never be invoked."); + } + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTaskScheduler.cs b/Assets/UniRx.Async/UniTaskScheduler.cs index 9270445..e1d8fe1 100644 --- a/Assets/UniRx.Async/UniTaskScheduler.cs +++ b/Assets/UniRx.Async/UniTaskScheduler.cs @@ -19,12 +19,12 @@ namespace UniRx.Async public static bool PropagateOperationCanceledException = false; /// - /// Write log type when catch unobserved exception and not registered UnobservedTaskException. Default is Warning. + /// Write log type when catch unobserved exception and not registered UnobservedTaskException. Default is Error. /// - public static UnityEngine.LogType UnobservedExceptionWriteLogType = UnityEngine.LogType.Warning; + public static UnityEngine.LogType UnobservedExceptionWriteLogType = UnityEngine.LogType.Error; /// - /// Dispatch exception event to Unity MainThread. + /// Dispatch exception event to Unity MainThread. Default is true. /// public static bool DispatchUnityMainThread = true; @@ -42,7 +42,7 @@ namespace UniRx.Async if (UnobservedTaskException != null) { - if (Thread.CurrentThread.ManagedThreadId == PlayerLoopHelper.MainThreadId) + if (!DispatchUnityMainThread || Thread.CurrentThread.ManagedThreadId == PlayerLoopHelper.MainThreadId) { // allows inlining call. UnobservedTaskException.Invoke(ex); diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index 66ce02b..f14bbe5 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -491,6 +491,127 @@ namespace UniRx.Async } } + + + // TODO: try to check API. + class ResourceRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + ResourceRequest asyncOperation; + IProgress progress; + CancellationToken cancellationToken; + + UniTaskCompletionSourceCore core; + + ResourceRequestConfiguredSource() + { + + } + + public static IUniTaskSource Create(ResourceRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new ResourceRequestConfiguredSource(); + + result.asyncOperation = asyncOperation; + result.progress = progress; + result.cancellationToken = cancellationToken; + +#if UNITY_EDITOR + // TODO:capture??? + //var capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(2); + // TODO:Add ActiveTask? + // TaskTracker.TrackActiveTask( +#endif + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public UnityEngine.Object GetResult(short token) + { + try + { + return core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + // TODO:Remove Tracking + // TaskTracker.RemoveTracking(); + core.SetCancellation(cancellationToken); + return false; + } + + if (progress != null) + { + progress.Report(asyncOperation.progress); + } + + if (asyncOperation.isDone) + { + // TODO:Remove Tracking + // TaskTracker.RemoveTracking(); + core.SetResult(asyncOperation.asset); + return false; + } + + return true; + } + + public void Reset() + { + core.Reset(); + asyncOperation = default; + progress = default; + cancellationToken = default; + } + } + + + + + + + + + + + public struct AssetBundleRequestAwaiter : IAwaiter { AssetBundleRequest asyncOperation; diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index a4a08ca..4d57782 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -8,7 +8,7 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/SandboxMain.unity guid: 2cda990e2423bbf4892e6590ba056729 - - enabled: 1 - path: Assets/Scenes/NextScene.unity - guid: dfced9d8875377c44a1d53620d36f0d5 + - enabled: 0 + path: + guid: 00000000000000000000000000000000 m_configObjects: {} diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index f788aee..a94ae28 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -3,7 +3,7 @@ --- !u!129 &1 PlayerSettings: m_ObjectHideFlags: 0 - serializedVersion: 17 + serializedVersion: 20 productGUID: 904cd7a3163037f42a9204c0e2f2b7bd AndroidProfiler: 0 AndroidFilterTouchesWhenObscured: 0 @@ -52,8 +52,7 @@ PlayerSettings: m_StackTraceTypes: 010000000100000001000000010000000100000001000000 iosShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1 - iosAppInBackgroundBehavior: 0 - displayResolutionDialog: 0 + iosUseCustomAppBackgroundBehavior: 0 iosAllowHTTPDownload: 1 allowedAutorotateToPortrait: 1 allowedAutorotateToPortraitUpsideDown: 1 @@ -80,11 +79,11 @@ PlayerSettings: usePlayerLog: 1 bakeCollisionMeshes: 0 forceSingleInstance: 0 + useFlipModelSwapchain: 1 resizableWindow: 1 useMacAppStoreValidation: 0 macAppStoreCategory: public.app-category.games gpuSkinning: 0 - graphicsJobs: 0 xboxPIXTextureCapture: 0 xboxEnableAvatar: 0 xboxEnableKinect: 0 @@ -92,7 +91,6 @@ PlayerSettings: xboxEnableFitness: 0 visibleInBackground: 1 allowFullscreenSwitch: 1 - graphicsJobMode: 0 fullscreenMode: 3 xboxSpeechDB: 0 xboxEnableHeadOrientation: 0 @@ -105,6 +103,7 @@ PlayerSettings: xboxOneMonoLoggingLevel: 0 xboxOneLoggingLevel: 1 xboxOneDisableEsram: 0 + xboxOneEnableTypeOptimization: 0 xboxOnePresentImmediateThreshold: 0 switchQueueCommandMemory: 0 switchQueueControlMemory: 16384 @@ -112,6 +111,7 @@ PlayerSettings: switchNVNShaderPoolsGranularity: 33554432 switchNVNDefaultPoolsGranularity: 16777216 switchNVNOtherPoolsGranularity: 16777216 + vulkanNumSwapchainBuffers: 3 vulkanEnableSetSRGBWrite: 0 m_SupportedAspectRatios: 4:3: 1 @@ -150,11 +150,13 @@ PlayerSettings: sharedDepthBuffer: 1 dashSupport: 1 lowOverheadMode: 0 + protectedContext: 0 + v2Signing: 1 enable360StereoCapture: 0 isWsaHolographicRemotingEnabled: 0 - protectGraphicsMemory: 0 enableFrameTimingStats: 0 useHDRDisplay: 0 + D3DHDRBitDepth: 0 m_ColorGamuts: 00000000 targetPixelDensity: 30 resolutionScalingMode: 0 @@ -164,7 +166,7 @@ PlayerSettings: Standalone: com.Company.ProductName buildNumber: {} AndroidBundleVersionCode: 1 - AndroidMinSdkVersion: 16 + AndroidMinSdkVersion: 19 AndroidTargetSdkVersion: 0 AndroidPreferredInstallLocation: 1 aotOptions: @@ -179,10 +181,10 @@ PlayerSettings: StripUnusedMeshComponents: 1 VertexChannelCompressionMask: 4054 iPhoneSdkVersion: 988 - iOSTargetOSVersionString: 9.0 + iOSTargetOSVersionString: 10.0 tvOSSdkVersion: 0 tvOSRequireExtendedGameController: 0 - tvOSTargetOSVersionString: 9.0 + tvOSTargetOSVersionString: 10.0 uIPrerenderedIcon: 0 uIRequiresPersistentWiFi: 0 uIRequiresFullScreen: 1 @@ -272,16 +274,46 @@ PlayerSettings: androidGamepadSupportLevel: 0 AndroidValidateAppBundleSize: 1 AndroidAppBundleSizeToValidate: 100 - resolutionDialogBanner: {fileID: 0} m_BuildTargetIcons: [] m_BuildTargetPlatformIcons: [] m_BuildTargetBatching: [] + m_BuildTargetGraphicsJobs: + - m_BuildTarget: MacStandaloneSupport + m_GraphicsJobs: 0 + - m_BuildTarget: Switch + m_GraphicsJobs: 0 + - m_BuildTarget: MetroSupport + m_GraphicsJobs: 0 + - m_BuildTarget: AppleTVSupport + m_GraphicsJobs: 0 + - m_BuildTarget: BJMSupport + m_GraphicsJobs: 0 + - m_BuildTarget: LinuxStandaloneSupport + m_GraphicsJobs: 0 + - m_BuildTarget: PS4Player + m_GraphicsJobs: 0 + - m_BuildTarget: iOSSupport + m_GraphicsJobs: 0 + - m_BuildTarget: WindowsStandaloneSupport + m_GraphicsJobs: 0 + - m_BuildTarget: XboxOnePlayer + m_GraphicsJobs: 0 + - m_BuildTarget: LuminSupport + m_GraphicsJobs: 0 + - m_BuildTarget: AndroidPlayer + m_GraphicsJobs: 0 + - m_BuildTarget: WebGLSupport + m_GraphicsJobs: 0 + m_BuildTargetGraphicsJobMode: + - m_BuildTarget: PS4Player + m_GraphicsJobMode: 0 + - m_BuildTarget: XboxOnePlayer + m_GraphicsJobMode: 0 m_BuildTargetGraphicsAPIs: - m_BuildTarget: AndroidPlayer m_APIs: 150000000b000000 m_Automatic: 0 m_BuildTargetVRSettings: [] - m_BuildTargetEnableVuforiaSettings: [] openGLRequireES31: 0 openGLRequireES31AEP: 0 openGLRequireES32: 0 @@ -400,6 +432,7 @@ PlayerSettings: switchRatingsInt_9: 0 switchRatingsInt_10: 0 switchRatingsInt_11: 0 + switchRatingsInt_12: 0 switchLocalCommunicationIds_0: switchLocalCommunicationIds_1: switchLocalCommunicationIds_2: @@ -481,6 +514,7 @@ PlayerSettings: ps4UseResolutionFallback: 0 ps4ReprojectionSupport: 0 ps4UseAudio3dBackend: 0 + ps4UseLowGarlicFragmentationMode: 1 ps4SocialScreenEnabled: 0 ps4ScriptOptimizationLevel: 0 ps4Audio3dVirtualSpeakerCount: 14 @@ -499,6 +533,7 @@ PlayerSettings: ps4contentSearchFeaturesUsed: 0 ps4attribEyeToEyeDistanceSettingVR: 0 ps4IncludedModules: [] + ps4attribVROutputEnabled: 0 monoEnv: splashScreenBackgroundSourceLandscape: {fileID: 0} splashScreenBackgroundSourcePortrait: {fileID: 0} @@ -602,13 +637,6 @@ PlayerSettings: luminVersion: m_VersionCode: 1 m_VersionName: - facebookSdkVersion: 7.9.4 - facebookAppId: - facebookCookies: 1 - facebookLogging: 1 - facebookStatus: 1 - facebookXfbml: 0 - facebookFrictionlessRequests: 1 apiCompatibilityLevel: 6 cloudProjectId: framebufferDepthMemorylessMode: 0 diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset index c3ae9a0..fa0b146 100644 --- a/ProjectSettings/UnityConnectSettings.asset +++ b/ProjectSettings/UnityConnectSettings.asset @@ -4,7 +4,7 @@ UnityConnectSettings: m_ObjectHideFlags: 0 serializedVersion: 1 - m_Enabled: 1 + m_Enabled: 0 m_TestMode: 0 m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events m_EventUrl: https://cdp.cloud.unity3d.com/v1/events From b2d3423a335e9f701ac5567e4af7e54100e5e13a Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Sat, 18 Apr 2020 22:11:40 +0900 Subject: [PATCH 004/173] T | IUniTaskSource --- Assets/Scenes/SandboxMain.cs | 9 +- .../AsyncUniTaskMethodBuilder.cs | 48 +- Assets/UniRx.Async/UniTask.Factory.cs | 13 + Assets/UniRx.Async/UniTask.cs | 513 +++++++----------- Assets/UniRx.Async/UniTaskCompletionSource.cs | 21 +- 5 files changed, 275 insertions(+), 329 deletions(-) diff --git a/Assets/Scenes/SandboxMain.cs b/Assets/Scenes/SandboxMain.cs index f8c9e07..459aac0 100644 --- a/Assets/Scenes/SandboxMain.cs +++ b/Assets/Scenes/SandboxMain.cs @@ -40,10 +40,10 @@ public class SandboxMain : MonoBehaviour ucs = new UniTaskCompletionSource2(); - okButton.onClick.AddListener(UniTask.VoidUnityAction(async () => + okButton.onClick.AddListener(async () => { - await OuterAsync(true); - })); + await InnerAsync(false); + }); cancelButton.onClick.AddListener(async () => { @@ -84,7 +84,8 @@ public class SandboxMain : MonoBehaviour } else { - //UnityEngine.Debug.Log("Empty END"); + UnityEngine.Debug.Log("Empty END"); + throw new InvalidOperationException("FOOBARBAZ"); } } diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs index 1d15f0b..31f9d34 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs @@ -298,10 +298,17 @@ namespace UniRx.Async.CompilerServices [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (promise == null) + if (promise != null) { - promise = AutoResetUniTaskCompletionSource.Create(); + return promise.Task; } + + if (runner == null) + { + return UniTask2.CompletedTask; + } + + promise = AutoResetUniTaskCompletionSource.Create(); return promise.Task; } } @@ -317,11 +324,14 @@ namespace UniRx.Async.CompilerServices runner = null; } - if (promise == null) + if (promise != null) { - promise = AutoResetUniTaskCompletionSource.Create(); + promise.SetException(exception); + } + else + { + promise = AutoResetUniTaskCompletionSource.CreateFromException(exception, out _); } - promise.SetException(exception); } // 4. SetResult @@ -335,11 +345,10 @@ namespace UniRx.Async.CompilerServices runner = null; } - if (promise == null) + if (promise != null) { - promise = AutoResetUniTaskCompletionSource.Create(); + promise.SetResult(); } - promise.SetResult(); } // 5. AwaitOnCompleted @@ -401,6 +410,7 @@ namespace UniRx.Async.CompilerServices // cache items. AutoResetUniTaskCompletionSource promise; IMoveNextRunner runner; + T result; // 1. Static Create method. [DebuggerHidden] @@ -416,10 +426,17 @@ namespace UniRx.Async.CompilerServices { get { - if (promise == null) + if (promise != null) { - promise = AutoResetUniTaskCompletionSource.Create(); + return promise.Task; } + + if (runner == null) + { + return UniTask2.FromResult(result); + } + + promise = AutoResetUniTaskCompletionSource.Create(); return promise.Task; } } @@ -437,9 +454,12 @@ namespace UniRx.Async.CompilerServices if (promise == null) { - promise = AutoResetUniTaskCompletionSource.Create(); + promise = AutoResetUniTaskCompletionSource.CreateFromException(exception, out _); + } + else + { + promise.SetException(exception); } - promise.SetException(exception); } // 4. SetResult @@ -455,8 +475,10 @@ namespace UniRx.Async.CompilerServices if (promise == null) { - promise = AutoResetUniTaskCompletionSource.Create(); + this.result = result; + return; } + promise.SetResult(result); } diff --git a/Assets/UniRx.Async/UniTask.Factory.cs b/Assets/UniRx.Async/UniTask.Factory.cs index 291ce5c..5bc0b84 100644 --- a/Assets/UniRx.Async/UniTask.Factory.cs +++ b/Assets/UniRx.Async/UniTask.Factory.cs @@ -128,5 +128,18 @@ namespace UniRx.Async public static readonly UniTask MinusOne = UniTask.FromResult(-1); public static readonly UniTask One = UniTask.FromResult(1); } + + + + internal static class CompletedTasks2 + { + public static readonly UniTask2 Completed = new UniTask2(); + public static readonly UniTask2 AsyncUnit = UniTask2.FromResult(UniRx.Async.AsyncUnit.Default); + public static readonly UniTask2 True = UniTask2.FromResult(true); + public static readonly UniTask2 False = UniTask2.FromResult(false); + public static readonly UniTask2 Zero = UniTask2.FromResult(0); + public static readonly UniTask2 MinusOne = UniTask2.FromResult(-1); + public static readonly UniTask2 One = UniTask2.FromResult(1); + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.cs b/Assets/UniRx.Async/UniTask.cs index 72779bd..78cd6e2 100644 --- a/Assets/UniRx.Async/UniTask.cs +++ b/Assets/UniRx.Async/UniTask.cs @@ -29,9 +29,17 @@ namespace UniRx.Async //return new ValueTask(DelayPromiseCore2.Create(frameCount, timing, cancellationToken, out var token), token); } + public static readonly UniTask2 CompletedTask = new UniTask2(); + + public static UniTask2 FromResult(T result) + { + return new UniTask2(result); + } } + + public class DelayPromiseCore2 : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { static readonly PromisePool pool = new PromisePool(); @@ -70,6 +78,7 @@ namespace UniRx.Async { try { + TaskTracker2.RemoveTracking(this); core.GetResult(token); } finally @@ -97,14 +106,12 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - TaskTracker2.RemoveTracking(this); core.SetCancellation(cancellationToken); return false; } if (currentFrameCount == delayFrameCount) { - TaskTracker2.RemoveTracking(this); core.SetResult(null); return false; } @@ -126,25 +133,30 @@ namespace UniRx.Async + internal static class AwaiterActions + { + internal static readonly Action InvokeActionDelegate = InvokeAction; - + static void InvokeAction(object state) + { + ((Action)state).Invoke(); + } + } /// /// Lightweight unity specified task-like object. /// - [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder))] // TODO:AsyncUniTask2 - public partial struct UniTask2 + [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder))] + public readonly partial struct UniTask2 { - // static readonly UniTask DefaultAsyncUnitTask = new UniTask(AsyncUnit.Default); - - readonly IUniTaskSource awaiter; + readonly IUniTaskSource source; readonly short token; [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public UniTask2(IUniTaskSource awaiter, short token) + public UniTask2(IUniTaskSource source, short token) { - this.awaiter = awaiter; + this.source = source; this.token = token; } @@ -154,7 +166,8 @@ namespace UniRx.Async [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - return awaiter.GetStatus(token); + if (source == null) return AwaiterStatus.Succeeded; + return source.GetStatus(token); } } @@ -165,154 +178,112 @@ namespace UniRx.Async return new Awaiter(this); } - [DebuggerHidden] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - void GetResult() + /// + /// returns (bool IsCanceled) instead of throws OperationCanceledException. + /// + public UniTask2 SuppressCancellationThrow() { - awaiter.GetResult(token); + var status = Status; + if (status == AwaiterStatus.Succeeded) return CompletedTasks2.False; + if (status == AwaiterStatus.Canceled) return CompletedTasks2.True; + return new UniTask2(new IsCanceledSource(source), token); } - // TODO:can be suppress? - - ///// - ///// returns (bool IsCanceled) instead of throws OperationCanceledException. - ///// - //public UniTask SuppressCancellationThrow() - //{ - // var status = Status; - // if (status == AwaiterStatus.Succeeded) return CompletedTasks.False; - // if (status == AwaiterStatus.Canceled) return CompletedTasks.True; - // //return new UniTask(new IsCanceledAwaiter(awaiter)); - //} - public override string ToString() { - var status = this.awaiter.UnsafeGetStatus(); - return (status == AwaiterStatus.Succeeded) ? "()" : "(" + status + ")"; + if (source == null) return "()"; + return "(" + source.UnsafeGetStatus() + ")"; } - //public static implicit operator UniTask(UniTask2 task) - //{ - // // TODO: - // throw new NotImplementedException(); + // TODO:AsTask??? - // //if (task.awaiter != null) - // //{ - // // if (task.awaiter.IsCompleted) - // // { - // // return DefaultAsyncUnitTask; - // // } - // // else - // // { - // // // UniTask -> UniTask is free but UniTask -> UniTask requires wrapping cost. - // // return new UniTask(new AsyncUnitAwaiter(task.awaiter)); - // // } - // //} - // //else - // //{ - // // return DefaultAsyncUnitTask; - // //} - //} - - //class AsyncUnitAwaiter : IAwaiter - //{ - // readonly IAwaiter2 awaiter; - - // public AsyncUnitAwaiter(IAwaiter2 awaiter) - // { - // this.awaiter = awaiter; - // } - - // public bool IsCompleted => awaiter.IsCompleted; - - // public AwaiterStatus Status => awaiter.Status; - - // public AsyncUnit GetResult() - // { - // awaiter.GetResult(); - // return AsyncUnit.Default; - // } - - // public void OnCompleted(Action continuation) - // { - // awaiter.OnCompleted(continuation); - // } - - // public void UnsafeOnCompleted(Action continuation) - // { - // awaiter.UnsafeOnCompleted(continuation); - // } - - // void IAwaiter.GetResult() - // { - // awaiter.GetResult(); - // } - //} - - class IsCanceledAwaiter : IUniTaskSource + public static implicit operator UniTask2(UniTask2 task) { - readonly IUniTaskSource awaiter; + if (task.source == null) return CompletedTasks2.AsyncUnit; - public IsCanceledAwaiter(IUniTaskSource awaiter) + var status = task.source.GetStatus(task.token); + if (status.IsCompletedSuccessfully()) { - this.awaiter = awaiter; + return CompletedTasks2.AsyncUnit; } - //public bool IsCompleted => awaiter.IsCompleted; + return new UniTask2(new AsyncUnitSource(task.source), task.token); + } - //public AwaiterStatus Status => awaiter.Status; + class AsyncUnitSource : IUniTaskSource + { + readonly IUniTaskSource source; - //public bool GetResult() - //{ - // if (awaiter.Status == AwaiterStatus.Canceled) - // { - // return true; - // } - // awaiter.GetResult(); - // return false; - //} - - //public void OnCompleted(Action continuation) - //{ - // awaiter.OnCompleted(continuation); - //} - - //public void UnsafeOnCompleted(Action continuation) - //{ - // awaiter.UnsafeOnCompleted(continuation); - //} - - //void IAwaiter.GetResult() - //{ - // awaiter.GetResult(); - //} - - public void GetResult(short token) + public AsyncUnitSource(IUniTaskSource source) { - // TODO: bool - if (awaiter.GetStatus(token) == AwaiterStatus.Canceled) - { - //return true; - } + this.source = source; + } - awaiter.GetResult(token); - // return false - throw new NotImplementedException(); + public AsyncUnit GetResult(short token) + { + source.GetResult(token); + return AsyncUnit.Default; } public AwaiterStatus GetStatus(short token) { - return awaiter.GetStatus(token); - } - - public AwaiterStatus UnsafeGetStatus() - { - return awaiter.UnsafeGetStatus(); + return source.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { - awaiter.OnCompleted(continuation, state, token); + source.OnCompleted(continuation, state, token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return source.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + } + + class IsCanceledSource : IUniTaskSource + { + readonly IUniTaskSource source; + + public IsCanceledSource(IUniTaskSource source) + { + this.source = source; + } + + public bool GetResult(short token) + { + if (source.GetStatus(token) == AwaiterStatus.Canceled) + { + return true; + } + + source.GetResult(token); + return false; + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public AwaiterStatus GetStatus(short token) + { + return source.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return source.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + source.OnCompleted(continuation, state, token); } } @@ -337,69 +308,70 @@ namespace UniRx.Async } } - public AwaiterStatus Status - { - [DebuggerHidden] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return task.Status; - } - } - [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void GetResult() { - task.GetResult(); + if (task.source == null) return; + task.source.GetResult(task.token); } [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void OnCompleted(Action continuation) { - task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + if (task.source == null) + { + continuation(); + } + else + { + task.source.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } } [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void UnsafeOnCompleted(Action continuation) { - task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + if (task.source == null) + { + continuation(); + } + else + { + task.source.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } } } } - internal static class AwaiterActions - { - internal static readonly Action InvokeActionDelegate = InvokeAction; - - static void InvokeAction(object state) - { - ((Action)state).Invoke(); - } - } - - - - /// /// Lightweight unity specified task-like object. /// - [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder))] // TODO:AsyncUniTask2~T - public struct UniTask2 + [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder<>))] + public readonly struct UniTask2 { - // static readonly UniTask DefaultAsyncUnitTask = new UniTask(AsyncUnit.Default); - - readonly IUniTaskSource awaiter; + readonly IUniTaskSource source; + readonly T result; readonly short token; [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public UniTask2(IUniTaskSource awaiter, short token) + public UniTask2(T result) { - this.awaiter = awaiter; + this.source = default; + this.token = default; + this.result = result; + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public UniTask2(IUniTaskSource source, short token) + { + this.source = source; this.token = token; + this.result = default; } public AwaiterStatus Status @@ -408,7 +380,7 @@ namespace UniRx.Async [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - return awaiter.GetStatus(token); + return (source == null) ? AwaiterStatus.Succeeded : source.GetStatus(token); } } @@ -419,154 +391,77 @@ namespace UniRx.Async return new Awaiter(this); } - [DebuggerHidden] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - T GetResult() + // TODO:AsTask??? + + /// + /// returns (bool IsCanceled, T Result) instead of throws OperationCanceledException. + /// + public UniTask2<(bool IsCanceled, T Result)> SuppressCancellationThrow() { - return awaiter.GetResult(token); + if (source == null) + { + return new UniTask2<(bool IsCanceled, T Result)>((false, result)); + } + + return new UniTask2<(bool, T)>(new IsCanceledSource(source), token); } - // TODO:can be suppress? - - ///// - ///// returns (bool IsCanceled) instead of throws OperationCanceledException. - ///// - //public UniTask SuppressCancellationThrow() - //{ - // var status = Status; - // if (status == AwaiterStatus.Succeeded) return CompletedTasks.False; - // if (status == AwaiterStatus.Canceled) return CompletedTasks.True; - // //return new UniTask(new IsCanceledAwaiter(awaiter)); - //} - public override string ToString() { - var status = this.awaiter.UnsafeGetStatus(); - return (status == AwaiterStatus.Succeeded) ? "()" : "(" + status + ")"; + return (this.source == null) ? result?.ToString() + : "(" + this.source.UnsafeGetStatus() + ")"; } - //public static implicit operator UniTask(UniTask2 task) - //{ - // // TODO: - // throw new NotImplementedException(); - - // //if (task.awaiter != null) - // //{ - // // if (task.awaiter.IsCompleted) - // // { - // // return DefaultAsyncUnitTask; - // // } - // // else - // // { - // // // UniTask -> UniTask is free but UniTask -> UniTask requires wrapping cost. - // // return new UniTask(new AsyncUnitAwaiter(task.awaiter)); - // // } - // //} - // //else - // //{ - // // return DefaultAsyncUnitTask; - // //} - //} - - //class AsyncUnitAwaiter : IAwaiter - //{ - // readonly IAwaiter2 awaiter; - - // public AsyncUnitAwaiter(IAwaiter2 awaiter) - // { - // this.awaiter = awaiter; - // } - - // public bool IsCompleted => awaiter.IsCompleted; - - // public AwaiterStatus Status => awaiter.Status; - - // public AsyncUnit GetResult() - // { - // awaiter.GetResult(); - // return AsyncUnit.Default; - // } - - // public void OnCompleted(Action continuation) - // { - // awaiter.OnCompleted(continuation); - // } - - // public void UnsafeOnCompleted(Action continuation) - // { - // awaiter.UnsafeOnCompleted(continuation); - // } - - // void IAwaiter.GetResult() - // { - // awaiter.GetResult(); - // } - //} - - class IsCanceledAwaiter : IUniTaskSource + class IsCanceledSource : IUniTaskSource<(bool, T)> { - readonly IUniTaskSource awaiter; + readonly IUniTaskSource source; - public IsCanceledAwaiter(IUniTaskSource awaiter) + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IsCanceledSource(IUniTaskSource source) { - this.awaiter = awaiter; + this.source = source; } - //public bool IsCompleted => awaiter.IsCompleted; - - //public AwaiterStatus Status => awaiter.Status; - - //public bool GetResult() - //{ - // if (awaiter.Status == AwaiterStatus.Canceled) - // { - // return true; - // } - // awaiter.GetResult(); - // return false; - //} - - //public void OnCompleted(Action continuation) - //{ - // awaiter.OnCompleted(continuation); - //} - - //public void UnsafeOnCompleted(Action continuation) - //{ - // awaiter.UnsafeOnCompleted(continuation); - //} - - //void IAwaiter.GetResult() - //{ - // awaiter.GetResult(); - //} - - public void GetResult(short token) + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public (bool, T) GetResult(short token) { - // TODO: bool - if (awaiter.GetStatus(token) == AwaiterStatus.Canceled) + if (source.GetStatus(token) == AwaiterStatus.Canceled) { - //return true; + return (true, default); } - awaiter.GetResult(token); - // return false - throw new NotImplementedException(); + var result = source.GetResult(token); + return (false, result); } + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public AwaiterStatus GetStatus(short token) { - return awaiter.GetStatus(token); + return source.GetStatus(token); } + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public AwaiterStatus UnsafeGetStatus() { - return awaiter.UnsafeGetStatus(); + return source.UnsafeGetStatus(); } + [DebuggerHidden] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void OnCompleted(Action continuation, object state, short token) { - awaiter.OnCompleted(continuation, state, token); + source.OnCompleted(continuation, state, token); } } @@ -591,35 +486,49 @@ namespace UniRx.Async } } - public AwaiterStatus Status - { - [DebuggerHidden] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return task.Status; - } - } - [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] public T GetResult() { - return task.GetResult(); + var s = task.source; + if (s == null) + { + return task.result; + } + else + { + return s.GetResult(task.token); + } } [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void OnCompleted(Action continuation) { - task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + var s = task.source; + if (s == null) + { + continuation(); + } + else + { + s.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } } [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void UnsafeOnCompleted(Action continuation) { - task.awaiter.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + var s = task.source; + if (s == null) + { + continuation(); + } + else + { + s.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); + } } } } @@ -1045,7 +954,7 @@ namespace UniRx.Async readonly UniTask task; [DebuggerHidden] - public Awaiter(UniTask task) + public Awaiter(in UniTask task) { this.task = task; } diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index 9432666..aa42750 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -693,8 +693,9 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource Create() { - // TODO:Add TaskTracker - return pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); + var value = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); + TaskTracker2.TrackActiveTask(value, 2); + return value; } public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) @@ -748,7 +749,7 @@ namespace UniRx.Async { try { - // TODO:Remove TaskTracker + TaskTracker2.RemoveTracking(this); core.GetResult(token); } finally @@ -795,7 +796,7 @@ namespace UniRx.Async public UniTaskCompletionSource2() { - // TODO: TaskTracker.TrackActiveTask + TaskTracker2.TrackActiveTask(this, 2); } [Conditional("UNITY_EDITOR")] @@ -804,8 +805,7 @@ namespace UniRx.Async if (!handled) { handled = true; - // TODO: - // TaskTracker.RemoveTracking(this); + TaskTracker2.RemoveTracking(this); } } @@ -819,9 +819,9 @@ namespace UniRx.Async public void Reset() { - // TODO:Reset, reactive tracker: TaskTracker.TrackActiveTask handled = false; core.Reset(); + TaskTracker2.TrackActiveTask(this, 2); } public void SetResult(T result) @@ -884,8 +884,9 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource Create() { - // TODO:Add TaskTracker - return pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); + var result = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); + TaskTracker2.TrackActiveTask(result, 2); + return result; } public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) @@ -939,7 +940,7 @@ namespace UniRx.Async { try { - // TODO:Remove TaskTracker + TaskTracker2.RemoveTracking(this); return core.GetResult(token); } finally From 11bc28b33f3436232eaa3808bfaf0477cf2ca9f7 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Fri, 17 Apr 2020 11:31:27 +0900 Subject: [PATCH 005/173] Update config.yml --- .circleci/config.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 95e5eaf..58ead3b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -82,12 +82,6 @@ workflows: # - build-and-test: # unity_version: 2019.2.0b2 # unity_license: ${UNITY_LICENSE_2019_2} - - build-and-create-package: - unity_version: 2019.1.2f1 - unity_license: ${UNITY_LICENSE_2019_1} - filters: - tags: - only: /.*/ - build-and-test: unity_version: 2019.1.2f1 unity_license: ${UNITY_LICENSE_2019_1} @@ -102,7 +96,7 @@ workflows: # - build-and-test: # unity_version: 2018.3.12f1 # unity_license: ${UNITY_LICENSE_2018_3} - - build-and-create-package-release: + - build-and-create-package: unity_version: 2019.1.2f1 unity_license: ${UNITY_LICENSE_2019_1} filters: @@ -112,9 +106,9 @@ workflows: ignore: /.*/ - upload-github: requires: - - build-and-create-package-release + - build-and-create-package filters: tags: only: /^\d\.\d\.\d.*/ branches: - ignore: /.*/ \ No newline at end of file + ignore: /.*/ From ca58784c4ddd85f851d23f0826b4c071a8f8b78c Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Sun, 19 Apr 2020 02:55:44 +0900 Subject: [PATCH 006/173] complete delay and factory --- Assets/UniRx.Async/UniTask.Bridge.cs | 8 + Assets/UniRx.Async/UniTask.Delay.cs | 444 ++++++++++++++ Assets/UniRx.Async/UniTask.Factory.cs | 119 +++- Assets/UniRx.Async/UniTask.cs | 365 +++++++---- Assets/UniRx.Async/UniTaskCompletionSource.cs | 20 +- Assets/UniRx.Async/UniTaskExtensions.cs | 568 ++++++++++++++++++ Assets/UniRx.Async/UnityAsyncExtensions.cs | 2 +- 7 files changed, 1390 insertions(+), 136 deletions(-) diff --git a/Assets/UniRx.Async/UniTask.Bridge.cs b/Assets/UniRx.Async/UniTask.Bridge.cs index 814bd02..a9ecbf6 100644 --- a/Assets/UniRx.Async/UniTask.Bridge.cs +++ b/Assets/UniRx.Async/UniTask.Bridge.cs @@ -8,6 +8,14 @@ namespace UniRx.Async { // UnityEngine Bridges. + public partial struct UniTask2 + { + public static IEnumerator ToCoroutine(Func taskFactory) + { + return taskFactory().ToCoroutine(); + } + } + public partial struct UniTask { public static IEnumerator ToCoroutine(Func taskFactory) diff --git a/Assets/UniRx.Async/UniTask.Delay.cs b/Assets/UniRx.Async/UniTask.Delay.cs index d828358..25e8b5f 100644 --- a/Assets/UniRx.Async/UniTask.Delay.cs +++ b/Assets/UniRx.Async/UniTask.Delay.cs @@ -9,6 +9,449 @@ using UnityEngine; namespace UniRx.Async { + // TODO:rename + public partial struct UniTask2 + { + public static YieldAwaitable2 Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update) + { + // optimized for single continuation + return new YieldAwaitable2(timing); + } + + public static UniTask2 Yield(PlayerLoopTiming timing, CancellationToken cancellationToken) + { + return new UniTask2(YieldPromise.Create(timing, cancellationToken, out var token), token); + } + + public static UniTask2 DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + { + if (delayFrameCount < 0) + { + throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount); + } + + return new UniTask2(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, out var token), token); + } + + public static UniTask2 Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + { + var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay); + if (delayTimeSpan < TimeSpan.Zero) + { + throw new ArgumentOutOfRangeException("Delay does not allow minus millisecondsDelay. millisecondsDelay:" + millisecondsDelay); + } + + return (ignoreTimeScale) + ? new UniTask2(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token) + : new UniTask2(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token); + } + + public static UniTask2 Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + { + if (delayTimeSpan < TimeSpan.Zero) + { + throw new ArgumentOutOfRangeException("Delay does not allow minus delayTimeSpan. delayTimeSpan:" + delayTimeSpan); + } + + return (ignoreTimeScale) + ? new UniTask2(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token) + : new UniTask2(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token); + } + + class YieldPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + CancellationToken cancellationToken; + UniTaskCompletionSourceCore core; + + YieldPromise() + { + } + + public static IUniTaskSource Create(PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new YieldPromise(); + + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.SetCanceled(cancellationToken); + return false; + } + + core.SetResult(null); + return false; + } + + public void Reset() + { + core.Reset(); + cancellationToken = default; + } + } + + class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + int delayFrameCount; + CancellationToken cancellationToken; + + int currentFrameCount; + UniTaskCompletionSourceCore core; + + DelayFramePromise() + { + } + + public static IUniTaskSource Create(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new DelayFramePromise(); + + result.delayFrameCount = delayFrameCount; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.SetCanceled(cancellationToken); + return false; + } + + if (currentFrameCount == delayFrameCount) + { + core.SetResult(null); + return false; + } + + currentFrameCount++; + return true; + } + + public void Reset() + { + core.Reset(); + currentFrameCount = default; + delayFrameCount = default; + cancellationToken = default; + } + } + + class DelayPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + float delayFrameTimeSpan; + float elapsed; + CancellationToken cancellationToken; + + UniTaskCompletionSourceCore core; + + DelayPromise() + { + } + + public static IUniTaskSource Create(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new DelayPromise(); + + result.elapsed = 0.0f; + result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.SetCanceled(cancellationToken); + return false; + } + + elapsed += Time.deltaTime; + if (elapsed >= delayFrameTimeSpan) + { + core.SetResult(null); + return false; + } + + return true; + } + + public void Reset() + { + core.Reset(); + delayFrameTimeSpan = default; + elapsed = default; + cancellationToken = default; + } + } + + class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + float delayFrameTimeSpan; + float elapsed; + CancellationToken cancellationToken; + + UniTaskCompletionSourceCore core; + + DelayIgnoreTimeScalePromise() + { + } + + public static IUniTaskSource Create(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new DelayIgnoreTimeScalePromise(); + + result.elapsed = 0.0f; + result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + public AwaiterStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public AwaiterStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.SetCanceled(cancellationToken); + return false; + } + + elapsed += Time.unscaledDeltaTime; + if (elapsed >= delayFrameTimeSpan) + { + core.SetResult(null); + return false; + } + + return true; + } + + public void Reset() + { + core.Reset(); + delayFrameTimeSpan = default; + elapsed = default; + cancellationToken = default; + } + } + } + + // TODO:rename + public struct YieldAwaitable2 + { + readonly PlayerLoopTiming timing; + + public YieldAwaitable2(PlayerLoopTiming timing) + { + this.timing = timing; + } + + public Awaiter GetAwaiter() + { + return new Awaiter(timing); + } + + public UniTask2 ToUniTask() + { + return UniTask2.Yield(timing, CancellationToken.None); + } + + public struct Awaiter : ICriticalNotifyCompletion + { + readonly PlayerLoopTiming timing; + + public Awaiter(PlayerLoopTiming timing) + { + this.timing = timing; + } + + public bool IsCompleted => false; + + public void GetResult() { } + + public void OnCompleted(Action continuation) + { + PlayerLoopHelper.AddContinuation(timing, continuation); + } + + public void UnsafeOnCompleted(Action continuation) + { + PlayerLoopHelper.AddContinuation(timing, continuation); + } + } + } + + + // TODO:remove public partial struct UniTask { public static YieldAwaitable Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update) @@ -199,6 +642,7 @@ namespace UniRx.Async } } + // TODO:remove public struct YieldAwaitable { readonly PlayerLoopTiming timing; diff --git a/Assets/UniRx.Async/UniTask.Factory.cs b/Assets/UniRx.Async/UniTask.Factory.cs index 5bc0b84..9893ad2 100644 --- a/Assets/UniRx.Async/UniTask.Factory.cs +++ b/Assets/UniRx.Async/UniTask.Factory.cs @@ -7,6 +7,121 @@ using UnityEngine.Events; namespace UniRx.Async { + public partial struct UniTask2 + { + static readonly UniTask2 CanceledUniTask = new Func(() => + { + var promise = new UniTaskCompletionSource2(); + promise.SetCanceled(CancellationToken.None); + promise.MarkHandled(); + return promise.Task; + })(); + + static class CanceledUniTaskCache + { + public static readonly UniTask2 Task; + + static CanceledUniTaskCache() + { + var promise = new UniTaskCompletionSource2(); + promise.SetCanceled(CancellationToken.None); + promise.MarkHandled(); + Task = promise.Task; + } + } + + public static readonly UniTask2 CompletedTask = new UniTask2(); + + public static UniTask2 FromException(Exception ex) + { + var promise = new UniTaskCompletionSource2(); + promise.SetException(ex); + promise.MarkHandled(); + return promise.Task; + } + + public static UniTask2 FromException(Exception ex) + { + var promise = new UniTaskCompletionSource2(); + promise.SetException(ex); + promise.MarkHandled(); + return promise.Task; + } + + public static UniTask2 FromResult(T value) + { + return new UniTask2(value); + } + + public static UniTask2 FromCanceled(CancellationToken cancellationToken = default) + { + if (cancellationToken == CancellationToken.None) + { + return CanceledUniTask; + } + else + { + var promise = new UniTaskCompletionSource2(); + promise.SetCanceled(cancellationToken); + promise.MarkHandled(); + return promise.Task; + } + } + + public static UniTask2 FromCanceled(CancellationToken cancellationToken = default) + { + if (cancellationToken == CancellationToken.None) + { + return CanceledUniTaskCache.Task; + } + else + { + var promise = new UniTaskCompletionSource2(); + promise.SetCanceled(cancellationToken); + promise.MarkHandled(); + return promise.Task; + } + } + + // TODO:... + + /// shorthand of new UniTask[T](Func[UniTask[T]] factory) + public static UniTask Lazy(Func> factory) + { + return new UniTask(factory); + } + + /// + /// helper of create add UniTaskVoid to delegate. + /// For example: FooEvent += () => UniTask.Void(async () => { /* */ }) + /// + public static void Void(Func asyncAction) + { + asyncAction().Forget(); + } + + public static Action VoidAction(Func asyncAction) + { + return () => Void(asyncAction); + } + + public static UnityAction VoidUnityAction(Func asyncAction) + { + return () => Void(asyncAction); + } + + /// + /// helper of create add UniTaskVoid to delegate. + /// For example: FooEvent += (sender, e) => UniTask.Void(async arg => { /* */ }, (sender, e)) + /// + public static void Void(Func asyncAction, T state) + { + asyncAction(state).Forget(); + } + } + + + // TODO:remove public partial struct UniTask { static readonly UniTask CanceledUniTask = new Func(() => @@ -120,6 +235,8 @@ namespace UniRx.Async } } + + // TODO:remove internal static class CompletedTasks { public static readonly UniTask True = UniTask.FromResult(true); @@ -130,7 +247,7 @@ namespace UniRx.Async } - + // TODO:rename internal static class CompletedTasks2 { public static readonly UniTask2 Completed = new UniTask2(); diff --git a/Assets/UniRx.Async/UniTask.cs b/Assets/UniRx.Async/UniTask.cs index 78cd6e2..bf71764 100644 --- a/Assets/UniRx.Async/UniTask.cs +++ b/Assets/UniRx.Async/UniTask.cs @@ -3,136 +3,15 @@ #pragma warning disable CS0436 using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using System.Threading.Tasks.Sources; using UniRx.Async.CompilerServices; using UniRx.Async.Internal; namespace UniRx.Async { - - - public partial struct UniTask2 - { - public static UniTask2 DelayFrame(int frameCount, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default) - { - return new UniTask2(DelayPromiseCore2.Create(frameCount, timing, cancellationToken, out var token), token); - - - //return new ValueTask(DelayPromiseCore2.Create(frameCount, timing, cancellationToken, out var token), token); - } - - public static readonly UniTask2 CompletedTask = new UniTask2(); - - public static UniTask2 FromResult(T result) - { - return new UniTask2(result); - } - } - - - - - public class DelayPromiseCore2 : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem - { - static readonly PromisePool pool = new PromisePool(); - - int delayFrameCount; - CancellationToken cancellationToken; - - int currentFrameCount; - UniTaskCompletionSourceCore core; - - DelayPromiseCore2() - { - } - - public static IUniTaskSource Create(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) - { - if (cancellationToken.IsCancellationRequested) - { - return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); - } - - var result = pool.TryRent() ?? new DelayPromiseCore2(); - - result.delayFrameCount = delayFrameCount; - result.cancellationToken = cancellationToken; - - TaskTracker2.TrackActiveTask(result, 3); - - PlayerLoopHelper.AddAction(timing, result); - - token = result.core.Version; - return result; - } - - public void GetResult(short token) - { - try - { - TaskTracker2.RemoveTracking(this); - core.GetResult(token); - } - finally - { - pool.TryReturn(this); - } - } - - public AwaiterStatus GetStatus(short token) - { - return core.GetStatus(token); - } - - public AwaiterStatus UnsafeGetStatus() - { - return core.UnsafeGetStatus(); - } - - public void OnCompleted(Action continuation, object state, short token) - { - core.OnCompleted(continuation, state, token); - } - - public bool MoveNext() - { - if (cancellationToken.IsCancellationRequested) - { - core.SetCancellation(cancellationToken); - return false; - } - - if (currentFrameCount == delayFrameCount) - { - core.SetResult(null); - return false; - } - - currentFrameCount++; - return true; - } - - public void Reset() - { - core.Reset(); - currentFrameCount = default; - delayFrameCount = default; - cancellationToken = default; - } - } - - - - - internal static class AwaiterActions { internal static readonly Action InvokeActionDelegate = InvokeAction; @@ -195,7 +74,20 @@ namespace UniRx.Async return "(" + source.UnsafeGetStatus() + ")"; } - // TODO:AsTask??? + /// + /// Memoizing inner IValueTaskSource. The result UniTask can await multiple. + /// + public UniTask2 Preserve() + { + if (source == null) + { + return this; + } + else + { + return new UniTask2(new MemoizeSource(source), token); + } + } public static implicit operator UniTask2(UniTask2 task) { @@ -287,6 +179,86 @@ namespace UniRx.Async } } + class MemoizeSource : IUniTaskSource + { + IUniTaskSource source; + ExceptionDispatchInfo exception; + AwaiterStatus status; + + public MemoizeSource(IUniTaskSource source) + { + this.source = source; + } + + public void GetResult(short token) + { + if (source == null) + { + if (exception != null) + { + exception.Throw(); + } + } + else + { + try + { + source.GetResult(token); + status = AwaiterStatus.Succeeded; + } + catch (Exception ex) + { + exception = ExceptionDispatchInfo.Capture(ex); + if (ex is OperationCanceledException) + { + status = AwaiterStatus.Canceled; + } + else + { + status = AwaiterStatus.Faulted; + } + throw; + } + finally + { + source = null; + } + } + } + + public AwaiterStatus GetStatus(short token) + { + if (source == null) + { + return status; + } + + return source.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + if (source == null) + { + continuation(state); + } + else + { + source.OnCompleted(continuation, state, token); + } + } + + public AwaiterStatus UnsafeGetStatus() + { + if (source == null) + { + return status; + } + + return source.UnsafeGetStatus(); + } + } + public readonly struct Awaiter : ICriticalNotifyCompletion { readonly UniTask2 task; @@ -343,6 +315,21 @@ namespace UniRx.Async task.source.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); } } + + /// + /// If register manually continuation, you can use it instead of for compiler OnCompleted methods. + /// + public void SourceOnCompleted(Action continuation, object state) + { + if (task.source == null) + { + continuation(state); + } + else + { + task.source.OnCompleted(continuation, state, task.token); + } + } } } @@ -391,7 +378,33 @@ namespace UniRx.Async return new Awaiter(this); } - // TODO:AsTask??? + /// + /// Memoizing inner IValueTaskSource. The result UniTask can await multiple. + /// + public UniTask2 Preserve() + { + if (source == null) + { + return this; + } + else + { + return new UniTask2(new MemoizeSource(source), token); + } + } + + public static implicit operator UniTask2(UniTask2 task) + { + if (task.source == null) return UniTask2.CompletedTask; + + var status = task.source.GetStatus(task.token); + if (status.IsCompletedSuccessfully()) + { + return UniTask2.CompletedTask; + } + + return new UniTask2(task.source, task.token); + } /// /// returns (bool IsCanceled, T Result) instead of throws OperationCanceledException. @@ -465,6 +478,94 @@ namespace UniRx.Async } } + class MemoizeSource : IUniTaskSource + { + IUniTaskSource source; + T result; + ExceptionDispatchInfo exception; + AwaiterStatus status; + + public MemoizeSource(IUniTaskSource source) + { + this.source = source; + } + + public T GetResult(short token) + { + if (source == null) + { + if (exception != null) + { + exception.Throw(); + } + return result; + } + else + { + try + { + result = source.GetResult(token); + status = AwaiterStatus.Succeeded; + return result; + } + catch (Exception ex) + { + exception = ExceptionDispatchInfo.Capture(ex); + if (ex is OperationCanceledException) + { + status = AwaiterStatus.Canceled; + } + else + { + status = AwaiterStatus.Faulted; + } + throw; + } + finally + { + source = null; + } + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public AwaiterStatus GetStatus(short token) + { + if (source == null) + { + return status; + } + + return source.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + if (source == null) + { + continuation(state); + } + else + { + source.OnCompleted(continuation, state, token); + } + } + + public AwaiterStatus UnsafeGetStatus() + { + if (source == null) + { + return status; + } + + return source.UnsafeGetStatus(); + } + } + public readonly struct Awaiter : ICriticalNotifyCompletion { readonly UniTask2 task; @@ -530,6 +631,22 @@ namespace UniRx.Async s.OnCompleted(AwaiterActions.InvokeActionDelegate, continuation, task.token); } } + + /// + /// If register manually continuation, you can use it instead of for compiler OnCompleted methods. + /// + public void SourceOnCompleted(Action continuation, object state) + { + var s = task.source; + if (s == null) + { + continuation(state); + } + else + { + s.OnCompleted(continuation, state, task.token); + } + } } } @@ -1000,4 +1117,4 @@ namespace UniRx.Async } } -#endif \ No newline at end of file +#endif diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index aa42750..27355a4 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -480,7 +480,7 @@ namespace UniRx.Async SignalCompletion(); } - public void SetCancellation(CancellationToken cancellationToken) + public void SetCanceled(CancellationToken cancellationToken = default) { this.error = new OperationCanceledException(cancellationToken); SignalCompletion(); @@ -613,7 +613,7 @@ namespace UniRx.Async } [Conditional("UNITY_EDITOR")] - void MarkHandled() + internal void MarkHandled() { if (!handled) { @@ -643,9 +643,9 @@ namespace UniRx.Async core.SetResult(AsyncUnit.Default); } - public void SetCancellation(CancellationToken cancellationToken) + public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCancellation(cancellationToken); + core.SetCanceled(cancellationToken); } public void SetException(Exception exception) @@ -701,7 +701,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) { var source = Create(); - source.SetCancellation(cancellationToken); + source.SetCanceled(cancellationToken); token = source.core.Version; return source; } @@ -735,7 +735,7 @@ namespace UniRx.Async core.SetResult(AsyncUnit.Default); } - public void SetCancellation(CancellationToken cancellationToken) + public void SetCanceled(CancellationToken cancellationToken = default) { core.SetCancellation(cancellationToken); } @@ -800,7 +800,7 @@ namespace UniRx.Async } [Conditional("UNITY_EDITOR")] - void MarkHandled() + internal void MarkHandled() { if (!handled) { @@ -829,7 +829,7 @@ namespace UniRx.Async core.SetResult(result); } - public void SetCancellation(CancellationToken cancellationToken) + public void SetCanceled(CancellationToken cancellationToken = default) { core.SetCancellation(cancellationToken); } @@ -884,7 +884,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource Create() { - var result = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); + var result = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); TaskTracker2.TrackActiveTask(result, 2); return result; } @@ -926,7 +926,7 @@ namespace UniRx.Async core.SetResult(result); } - public void SetCancellation(CancellationToken cancellationToken) + public void SetCanceled(CancellationToken cancellationToken = default) { core.SetCancellation(cancellationToken); } diff --git a/Assets/UniRx.Async/UniTaskExtensions.cs b/Assets/UniRx.Async/UniTaskExtensions.cs index 06642df..6cdfaf8 100644 --- a/Assets/UniRx.Async/UniTaskExtensions.cs +++ b/Assets/UniRx.Async/UniTaskExtensions.cs @@ -10,6 +10,574 @@ using UniRx.Async.Internal; namespace UniRx.Async { + public static partial class UniTaskExtensions2 + { + /// + /// Convert UniTask -> UniTask[AsyncUnit]. + /// + public static UniTask2 AsAsyncUnitUniTask(this UniTask2 task) + { + // use implicit conversion + return task; + } + + /// + /// Convert UniTask[T] -> UniTask. + /// + public static UniTask2 AsUniTask(this UniTask2 task) + { + // use implicit conversion + return task; + } + + /// + /// Convert Task[T] -> UniTask[T]. + /// + public static UniTask2 AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) + { + var promise = new UniTaskCompletionSource2(); + + task.ContinueWith((x, state) => + { + var p = (UniTaskCompletionSource2)state; + + switch (x.Status) + { + case TaskStatus.Canceled: + p.SetCanceled(); + break; + case TaskStatus.Faulted: + p.SetException(x.Exception); + break; + case TaskStatus.RanToCompletion: + p.SetResult(x.Result); + break; + default: + throw new NotSupportedException(); + } + }, promise, useCurrentSynchronizationContext ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Current); + + return promise.Task; + } + + /// + /// Convert Task -> UniTask. + /// + public static UniTask2 AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) + { + var promise = new UniTaskCompletionSource2(); + + task.ContinueWith((x, state) => + { + var p = (UniTaskCompletionSource2)state; + + switch (x.Status) + { + case TaskStatus.Canceled: + p.SetCanceled(); + break; + case TaskStatus.Faulted: + p.SetException(x.Exception); + break; + case TaskStatus.RanToCompletion: + p.SetResult(); + break; + default: + throw new NotSupportedException(); + } + }, promise, useCurrentSynchronizationContext ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Current); + + return promise.Task; + } + + public static Task AsTask(this UniTask2 task) + { + try + { + var awaiter = task.GetAwaiter(); + if (awaiter.IsCompleted) + { + try + { + var result = awaiter.GetResult(); + return Task.FromResult(result); + } + catch (Exception ex) + { + return Task.FromException(ex); + } + } + + var tcs = new TaskCompletionSource(); + + awaiter.SourceOnCompleted(state => + { + var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask2.Awaiter))state; + try + { + var result = inAwaiter.GetResult(); + inTcs.SetResult(result); + } + catch (Exception ex) + { + inTcs.SetException(ex); + } + }, (tcs, awaiter)); + + return tcs.Task; + } + catch (Exception ex) + { + return Task.FromException(ex); + } + } + + public static Task AsTask(this UniTask2 task) + { + try + { + var awaiter = task.GetAwaiter(); + if (awaiter.IsCompleted) + { + try + { + awaiter.GetResult(); // check token valid on Succeeded + return Task.CompletedTask; + } + catch (Exception ex) + { + return Task.FromException(ex); + } + } + + var tcs = new TaskCompletionSource(); + + awaiter.SourceOnCompleted(state => + { + var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask2.Awaiter))state; + try + { + inAwaiter.GetResult(); + inTcs.SetResult(null); + } + catch (Exception ex) + { + inTcs.SetException(ex); + } + }, (tcs, awaiter)); + + return tcs.Task; + } + catch (Exception ex) + { + return Task.FromException(ex); + } + } + + public static IEnumerator ToCoroutine(this UniTask2 task, Action resultHandler = null, Action exceptionHandler = null) + { + return new ToCoroutineEnumerator(task, resultHandler, exceptionHandler); + } + + public static IEnumerator ToCoroutine(this UniTask2 task, Action exceptionHandler = null) + { + return new ToCoroutineEnumerator(task, exceptionHandler); + } + + public static UniTask Timeout(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + { + return Timeout(task.AsAsyncUnitUniTask(), timeout, ignoreTimeScale, timeoutCheckTiming, taskCancellationTokenSource); + } + + // TODO: require UniTask2.Delay, WhenAny, etc... + + public static async UniTask Timeout(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + { + // left, right both suppress operation canceled exception. + + var delayCancellationTokenSource = new CancellationTokenSource(); + var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); + + var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + + if (!hasValue) + { + if (taskCancellationTokenSource != null) + { + taskCancellationTokenSource.Cancel(); + taskCancellationTokenSource.Dispose(); + } + + throw new TimeoutException("Exceed Timeout:" + timeout); + } + else + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + } + + if (value.IsCanceled) + { + Error.ThrowOperationCanceledException(); + } + + return value.Result; + } + + /// + /// Timeout with suppress OperationCanceledException. Returns (bool, IsCacneled). + /// + public static async UniTask2 TimeoutWithoutException(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + { + var v = await TimeoutWithoutException(task.AsAsyncUnitUniTask(), timeout, ignoreTimeScale, timeoutCheckTiming, taskCancellationTokenSource); + return v.IsTimeout; + } + + + /// + /// Timeout with suppress OperationCanceledException. Returns (bool IsTimeout, T Result). + /// + public static async UniTask2<(bool IsTimeout, T Result)> TimeoutWithoutException(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + { + // left, right both suppress operation canceled exception. + + var delayCancellationTokenSource = new CancellationTokenSource(); + var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); + + var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + + if (!hasValue) + { + if (taskCancellationTokenSource != null) + { + taskCancellationTokenSource.Cancel(); + taskCancellationTokenSource.Dispose(); + } + + return (true, default(T)); + } + else + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + } + + if (value.IsCanceled) + { + Error.ThrowOperationCanceledException(); + } + + return (false, value.Result); + } + + public static void Forget(this UniTask2 task) + { + ForgetCore(task).Forget(); + } + + public static void Forget(this UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread = true) + { + if (exceptionHandler == null) + { + ForgetCore(task).Forget(); + } + else + { + ForgetCoreWithCatch(task, exceptionHandler, handleExceptionOnMainThread).Forget(); + } + } + + // UniTask to UniTaskVoid + static async UniTaskVoid ForgetCore(UniTask2 task) + { + await task; + } + + static async UniTaskVoid ForgetCoreWithCatch(UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread) + { + try + { + await task; + } + catch (Exception ex) + { + try + { + if (handleExceptionOnMainThread) + { + await UniTask2.SwitchToMainThread(); + } + exceptionHandler(ex); + } + catch (Exception ex2) + { + UniTaskScheduler.PublishUnobservedTaskException(ex2); + } + } + } + + public static void Forget(this UniTask2 task) + { + ForgetCore(task).Forget(); + } + + public static void Forget(this UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread = true) + { + if (exceptionHandler == null) + { + ForgetCore(task).Forget(); + } + else + { + ForgetCoreWithCatch(task, exceptionHandler, handleExceptionOnMainThread).Forget(); + } + } + + // UniTask to UniTaskVoid + static async UniTaskVoid ForgetCore(UniTask2 task) + { + await task; + } + + static async UniTaskVoid ForgetCoreWithCatch(UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread) + { + try + { + await task; + } + catch (Exception ex) + { + try + { + if (handleExceptionOnMainThread) + { + await UniTask.SwitchToMainThread(); + } + exceptionHandler(ex); + } + catch (Exception ex2) + { + UniTaskScheduler.PublishUnobservedTaskException(ex2); + } + } + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Action continuationFunction) + { + continuationFunction(await task); + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) + { + await continuationFunction(await task); + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) + { + return continuationFunction(await task); + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Func> continuationFunction) + { + return await continuationFunction(await task); + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Action continuationFunction) + { + await task; + continuationFunction(); + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) + { + await task; + await continuationFunction(); + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) + { + await task; + return continuationFunction(); + } + + public static async UniTask2 ContinueWith(this UniTask2 task, Func> continuationFunction) + { + await task; + return await continuationFunction(); + } + + public static async UniTask2 ConfigureAwait(this Task task, PlayerLoopTiming timing) + { + await task.ConfigureAwait(false); + await UniTask2.Yield(timing); + } + + public static async UniTask2 ConfigureAwait(this Task task, PlayerLoopTiming timing) + { + var v = await task.ConfigureAwait(false); + await UniTask2.Yield(timing); + return v; + } + + public static async UniTask2 ConfigureAwait(this UniTask2 task, PlayerLoopTiming timing) + { + await task; + await UniTask2.Yield(timing); + } + + public static async UniTask2 ConfigureAwait(this UniTask2 task, PlayerLoopTiming timing) + { + var v = await task; + await UniTask2.Yield(timing); + return v; + } + + public static async UniTask2 Unwrap(this UniTask2> task) + { + return await await task; + } + + public static async UniTask2 Unwrap(this UniTask2 task) + { + await await task; + } + + class ToCoroutineEnumerator : IEnumerator + { + bool completed; + UniTask2 task; + Action exceptionHandler = null; + bool isStarted = false; + ExceptionDispatchInfo exception; + + public ToCoroutineEnumerator(UniTask2 task, Action exceptionHandler) + { + completed = false; + this.exceptionHandler = exceptionHandler; + this.task = task; + } + + async UniTaskVoid RunTask(UniTask2 task) + { + try + { + await task; + } + catch (Exception ex) + { + if (exceptionHandler != null) + { + exceptionHandler(ex); + } + else + { + this.exception = ExceptionDispatchInfo.Capture(ex); + } + } + finally + { + completed = true; + } + } + + public object Current => null; + + public bool MoveNext() + { + if (!isStarted) + { + isStarted = true; + RunTask(task).Forget(); + } + + if (exception != null) + { + // throw exception on iterator (main)thread. + // unfortunately unity test-runner can not handle throw exception on hand-write IEnumerator.MoveNext. + UnityEngine.Debug.LogException(exception.SourceException); + } + + return !completed; + } + + public void Reset() + { + } + } + + class ToCoroutineEnumerator : IEnumerator + { + bool completed; + Action resultHandler = null; + Action exceptionHandler = null; + bool isStarted = false; + UniTask2 task; + object current = null; + ExceptionDispatchInfo exception; + + public ToCoroutineEnumerator(UniTask2 task, Action resultHandler, Action exceptionHandler) + { + completed = false; + this.task = task; + this.resultHandler = resultHandler; + this.exceptionHandler = exceptionHandler; + } + + async UniTaskVoid RunTask(UniTask2 task) + { + try + { + var value = await task; + current = value; // boxed if T is struct... + if (resultHandler != null) + { + resultHandler(value); + } + } + catch (Exception ex) + { + if (exceptionHandler != null) + { + exceptionHandler(ex); + } + else + { + this.exception = ExceptionDispatchInfo.Capture(ex); + } + } + finally + { + completed = true; + } + } + + public object Current => current; + + public bool MoveNext() + { + if (!isStarted) + { + isStarted = true; + RunTask(task).Forget(); + } + + if (exception != null) + { + // throw exception on iterator (main)thread. + // unfortunately unity test-runner can not handle throw exception on hand-write IEnumerator.MoveNext. + UnityEngine.Debug.LogException(exception.SourceException); + } + + return !completed; + } + + public void Reset() + { + } + } + } + + // TODO:remove public static partial class UniTaskExtensions { /// diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index f14bbe5..47314cb 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -573,7 +573,7 @@ namespace UniRx.Async { // TODO:Remove Tracking // TaskTracker.RemoveTracking(); - core.SetCancellation(cancellationToken); + core.SetCanceled(cancellationToken); return false; } From 86fa93451060431716f69863b1d1a6c78cd2fcf9 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Sun, 19 Apr 2020 03:00:47 +0900 Subject: [PATCH 007/173] diagnosticsext move to internal --- Assets/UniRx.Async/{ => Internal}/DiagnosticsExtensions.cs | 5 ++--- .../UniRx.Async/{ => Internal}/DiagnosticsExtensions.cs.meta | 0 2 files changed, 2 insertions(+), 3 deletions(-) rename Assets/UniRx.Async/{ => Internal}/DiagnosticsExtensions.cs (98%) rename Assets/UniRx.Async/{ => Internal}/DiagnosticsExtensions.cs.meta (100%) diff --git a/Assets/UniRx.Async/DiagnosticsExtensions.cs b/Assets/UniRx.Async/Internal/DiagnosticsExtensions.cs similarity index 98% rename from Assets/UniRx.Async/DiagnosticsExtensions.cs rename to Assets/UniRx.Async/Internal/DiagnosticsExtensions.cs index d0dfd33..77fd2e1 100644 --- a/Assets/UniRx.Async/DiagnosticsExtensions.cs +++ b/Assets/UniRx.Async/Internal/DiagnosticsExtensions.cs @@ -15,10 +15,9 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using UnityEngine; -namespace UniRx.Async +namespace UniRx.Async.Internal { - // TODO: Internal. - public static class DiagnosticsExtensions + internal static class DiagnosticsExtensions { static bool displayFilenames = true; diff --git a/Assets/UniRx.Async/DiagnosticsExtensions.cs.meta b/Assets/UniRx.Async/Internal/DiagnosticsExtensions.cs.meta similarity index 100% rename from Assets/UniRx.Async/DiagnosticsExtensions.cs.meta rename to Assets/UniRx.Async/Internal/DiagnosticsExtensions.cs.meta From ef248e2e0a0490ee33c610a7ce22e748dcceaadd Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Sun, 19 Apr 2020 03:24:53 +0900 Subject: [PATCH 008/173] remove legacy UniTask(occurs many compile error) --- Assets/Scenes/SandboxMain.cs | 12 +- .../AsyncUniTaskMethodBuilder.cs | 290 +--------- .../AsyncUniTaskVoidMethodBuilder.cs | 4 +- .../CompilerServices/MoveNextRunner.cs | 23 +- Assets/UniRx.Async/UniTask.Bridge.cs | 8 - Assets/UniRx.Async/UniTask.Delay.cs | 265 +-------- Assets/UniRx.Async/UniTask.Factory.cs | 164 +----- Assets/UniRx.Async/UniTask.cs | 526 +----------------- Assets/UniRx.Async/UniTaskCompletionSource.cs | 441 ++------------- Assets/UniRx.Async/UniTaskExtensions.cs | 505 +---------------- 10 files changed, 136 insertions(+), 2102 deletions(-) diff --git a/Assets/Scenes/SandboxMain.cs b/Assets/Scenes/SandboxMain.cs index 459aac0..528040e 100644 --- a/Assets/Scenes/SandboxMain.cs +++ b/Assets/Scenes/SandboxMain.cs @@ -17,7 +17,7 @@ public class SandboxMain : MonoBehaviour CancellationTokenSource cts; - UniTaskCompletionSource2 ucs; + UniTaskCompletionSource ucs; void Start() { @@ -38,7 +38,7 @@ public class SandboxMain : MonoBehaviour Application.logMessageReceived += Application_logMessageReceived; - ucs = new UniTaskCompletionSource2(); + ucs = new UniTaskCompletionSource(); okButton.onClick.AddListener(async () => { @@ -60,7 +60,7 @@ public class SandboxMain : MonoBehaviour text.text += "\n" + condition; } - async UniTask2 OuterAsync(bool b) + async UniTask OuterAsync(bool b) { UnityEngine.Debug.Log("START OUTER"); @@ -72,14 +72,14 @@ public class SandboxMain : MonoBehaviour // throw new InvalidOperationException("NAZO ERROR!?"); // error!? } - async UniTask2 InnerAsync(bool b) + async UniTask InnerAsync(bool b) { if (b) { UnityEngine.Debug.Log("Start delay:" + Time.frameCount); - await UniTask2.DelayFrame(60); + await UniTask.DelayFrame(60); UnityEngine.Debug.Log("End delay:" + Time.frameCount); - await UniTask2.DelayFrame(60); + await UniTask.DelayFrame(60); UnityEngine.Debug.Log("Onemore end delay:" + Time.frameCount); } else diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs index 31f9d34..e53f0f2 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs @@ -10,274 +10,8 @@ using System.Security; namespace UniRx.Async.CompilerServices { - // TODO:Remove - public struct AsyncUniTaskMethodBuilder - { - UniTaskCompletionSource promise; - Action moveNext; - - // 1. Static Create method. - [DebuggerHidden] - public static AsyncUniTaskMethodBuilder Create() - { - var builder = new AsyncUniTaskMethodBuilder(); - return builder; - } - - // 2. TaskLike Task property. - [DebuggerHidden] - public UniTask Task - { - get - { - if (promise != null) - { - return promise.Task; - } - - if (moveNext == null) - { - return UniTask.CompletedTask; - } - else - { - promise = new UniTaskCompletionSource(); - return promise.Task; - } - } - } - - // 3. SetException - [DebuggerHidden] - public void SetException(Exception exception) - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); - } - if (exception is OperationCanceledException ex) - { - promise.TrySetCanceled(ex); - } - else - { - promise.TrySetException(exception); - } - } - - // 4. SetResult - [DebuggerHidden] - public void SetResult() - { - if (moveNext == null) - { - } - else - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); - } - promise.TrySetResult(); - } - } - - // 5. AwaitOnCompleted - [DebuggerHidden] - public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : INotifyCompletion - where TStateMachine : IAsyncStateMachine - { - if (moveNext == null) - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); // built future. - } - - var runner = new MoveNextRunner(); - moveNext = runner.Run; - runner.StateMachine = stateMachine; // set after create delegate. - } - - awaiter.OnCompleted(moveNext); - } - - // 6. AwaitUnsafeOnCompleted - [DebuggerHidden] - [SecuritySafeCritical] - public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : ICriticalNotifyCompletion - where TStateMachine : IAsyncStateMachine - { - if (moveNext == null) - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); // built future. - } - - var runner = new MoveNextRunner(); - moveNext = runner.Run; - runner.StateMachine = stateMachine; // set after create delegate. - } - - awaiter.UnsafeOnCompleted(moveNext); - } - - // 7. Start - [DebuggerHidden] - public void Start(ref TStateMachine stateMachine) - where TStateMachine : IAsyncStateMachine - { - stateMachine.MoveNext(); - } - - // 8. SetStateMachine - [DebuggerHidden] - public void SetStateMachine(IAsyncStateMachine stateMachine) - { - } - } - - // TODO:Remove - public struct AsyncUniTaskMethodBuilder - { - T result; - UniTaskCompletionSource promise; - Action moveNext; - - // 1. Static Create method. - [DebuggerHidden] - public static AsyncUniTaskMethodBuilder Create() - { - var builder = new AsyncUniTaskMethodBuilder(); - return builder; - } - - // 2. TaskLike Task property. - [DebuggerHidden] - public UniTask Task - { - get - { - if (promise != null) - { - return new UniTask(promise); - } - - if (moveNext == null) - { - return new UniTask(result); - } - else - { - promise = new UniTaskCompletionSource(); - return new UniTask(promise); - } - } - } - - // 3. SetException - [DebuggerHidden] - public void SetException(Exception exception) - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); - } - if (exception is OperationCanceledException ex) - { - promise.TrySetCanceled(ex); - } - else - { - promise.TrySetException(exception); - } - } - - // 4. SetResult - [DebuggerHidden] - public void SetResult(T result) - { - if (moveNext == null) - { - this.result = result; - } - else - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); - } - promise.TrySetResult(result); - } - } - - // 5. AwaitOnCompleted - [DebuggerHidden] - public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : INotifyCompletion - where TStateMachine : IAsyncStateMachine - { - if (moveNext == null) - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); // built future. - } - - var runner = new MoveNextRunner(); - moveNext = runner.Run; - runner.StateMachine = stateMachine; // set after create delegate. - } - - awaiter.OnCompleted(moveNext); - } - - // 6. AwaitUnsafeOnCompleted - [DebuggerHidden] - [SecuritySafeCritical] - public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : ICriticalNotifyCompletion - where TStateMachine : IAsyncStateMachine - { - if (moveNext == null) - { - if (promise == null) - { - promise = new UniTaskCompletionSource(); // built future. - } - - var runner = new MoveNextRunner(); - moveNext = runner.Run; - runner.StateMachine = stateMachine; // set after create delegate. - } - - awaiter.UnsafeOnCompleted(moveNext); - } - - // 7. Start - [DebuggerHidden] - public void Start(ref TStateMachine stateMachine) - where TStateMachine : IAsyncStateMachine - { - stateMachine.MoveNext(); - } - - // 8. SetStateMachine - [DebuggerHidden] - public void SetStateMachine(IAsyncStateMachine stateMachine) - { - } - } - - - - - [StructLayout(LayoutKind.Auto)] - public struct AsyncUniTask2MethodBuilder + public struct AsyncUniTaskMethodBuilder { // cache items. AutoResetUniTaskCompletionSource promise; @@ -286,13 +20,13 @@ namespace UniRx.Async.CompilerServices // 1. Static Create method. [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsyncUniTask2MethodBuilder Create() + public static AsyncUniTaskMethodBuilder Create() { return default; } // 2. TaskLike Task property. - public UniTask2 Task + public UniTask Task { [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -305,7 +39,7 @@ namespace UniRx.Async.CompilerServices if (runner == null) { - return UniTask2.CompletedTask; + return UniTask.CompletedTask; } promise = AutoResetUniTaskCompletionSource.Create(); @@ -363,7 +97,7 @@ namespace UniRx.Async.CompilerServices } if (runner == null) { - runner = MoveNextRunner2.Create(ref stateMachine); + runner = MoveNextRunner.Create(ref stateMachine); } awaiter.OnCompleted(runner.CallMoveNext); @@ -382,7 +116,7 @@ namespace UniRx.Async.CompilerServices } if (runner == null) { - runner = MoveNextRunner2.Create(ref stateMachine); + runner = MoveNextRunner.Create(ref stateMachine); } awaiter.OnCompleted(runner.CallMoveNext); @@ -405,7 +139,7 @@ namespace UniRx.Async.CompilerServices } [StructLayout(LayoutKind.Auto)] - public struct AsyncUniTask2MethodBuilder + public struct AsyncUniTaskMethodBuilder { // cache items. AutoResetUniTaskCompletionSource promise; @@ -415,14 +149,14 @@ namespace UniRx.Async.CompilerServices // 1. Static Create method. [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsyncUniTask2MethodBuilder Create() + public static AsyncUniTaskMethodBuilder Create() { return default; } // 2. TaskLike Task property. [DebuggerHidden] - public UniTask2 Task + public UniTask Task { get { @@ -433,7 +167,7 @@ namespace UniRx.Async.CompilerServices if (runner == null) { - return UniTask2.FromResult(result); + return UniTask.FromResult(result); } promise = AutoResetUniTaskCompletionSource.Create(); @@ -494,7 +228,7 @@ namespace UniRx.Async.CompilerServices } if (runner == null) { - runner = MoveNextRunner2.Create(ref stateMachine); + runner = MoveNextRunner.Create(ref stateMachine); } awaiter.OnCompleted(runner.CallMoveNext); @@ -513,7 +247,7 @@ namespace UniRx.Async.CompilerServices } if (runner == null) { - runner = MoveNextRunner2.Create(ref stateMachine); + runner = MoveNextRunner.Create(ref stateMachine); } awaiter.OnCompleted(runner.CallMoveNext); diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs index 9fad249..2a3b43f 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs @@ -66,7 +66,7 @@ namespace UniRx.Async.CompilerServices { if (runner == null) { - runner = MoveNextRunner2.Create(ref stateMachine); + runner = MoveNextRunner.Create(ref stateMachine); } awaiter.OnCompleted(runner.CallMoveNext); @@ -81,7 +81,7 @@ namespace UniRx.Async.CompilerServices { if (runner == null) { - runner = MoveNextRunner2.Create(ref stateMachine); + runner = MoveNextRunner.Create(ref stateMachine); } awaiter.OnCompleted(runner.CallMoveNext); diff --git a/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs b/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs index 7c7155f..365ca79 100644 --- a/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs +++ b/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs @@ -9,43 +9,30 @@ using UniRx.Async.Internal; namespace UniRx.Async.CompilerServices { - // TODO: Remove it. - internal class MoveNextRunner - where TStateMachine : IAsyncStateMachine - { - public TStateMachine StateMachine; - - [DebuggerHidden] - public void Run() - { - StateMachine.MoveNext(); - } - } - internal interface IMoveNextRunner { Action CallMoveNext { get; } void Return(); } - internal class MoveNextRunner2 : IMoveNextRunner, IPromisePoolItem + internal class MoveNextRunner : IMoveNextRunner, IPromisePoolItem where TStateMachine : IAsyncStateMachine { - static PromisePool> pool = new PromisePool>(); + static PromisePool> pool = new PromisePool>(); TStateMachine stateMachine; internal readonly Action callMoveNext; public Action CallMoveNext => callMoveNext; - MoveNextRunner2() + MoveNextRunner() { callMoveNext = MoveNext; } - public static MoveNextRunner2 Create(ref TStateMachine stateMachine) + public static MoveNextRunner Create(ref TStateMachine stateMachine) { - var result = pool.TryRent() ?? new MoveNextRunner2(); + var result = pool.TryRent() ?? new MoveNextRunner(); result.stateMachine = stateMachine; return result; } diff --git a/Assets/UniRx.Async/UniTask.Bridge.cs b/Assets/UniRx.Async/UniTask.Bridge.cs index a9ecbf6..814bd02 100644 --- a/Assets/UniRx.Async/UniTask.Bridge.cs +++ b/Assets/UniRx.Async/UniTask.Bridge.cs @@ -8,14 +8,6 @@ namespace UniRx.Async { // UnityEngine Bridges. - public partial struct UniTask2 - { - public static IEnumerator ToCoroutine(Func taskFactory) - { - return taskFactory().ToCoroutine(); - } - } - public partial struct UniTask { public static IEnumerator ToCoroutine(Func taskFactory) diff --git a/Assets/UniRx.Async/UniTask.Delay.cs b/Assets/UniRx.Async/UniTask.Delay.cs index 25e8b5f..0ab0fb2 100644 --- a/Assets/UniRx.Async/UniTask.Delay.cs +++ b/Assets/UniRx.Async/UniTask.Delay.cs @@ -9,31 +9,30 @@ using UnityEngine; namespace UniRx.Async { - // TODO:rename - public partial struct UniTask2 + public partial struct UniTask { - public static YieldAwaitable2 Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update) + public static YieldAwaitable Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update) { // optimized for single continuation - return new YieldAwaitable2(timing); + return new YieldAwaitable(timing); } - public static UniTask2 Yield(PlayerLoopTiming timing, CancellationToken cancellationToken) + public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken) { - return new UniTask2(YieldPromise.Create(timing, cancellationToken, out var token), token); + return new UniTask(YieldPromise.Create(timing, cancellationToken, out var token), token); } - public static UniTask2 DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { if (delayFrameCount < 0) { throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount); } - return new UniTask2(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, out var token), token); + return new UniTask(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, out var token), token); } - public static UniTask2 Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay); if (delayTimeSpan < TimeSpan.Zero) @@ -42,11 +41,11 @@ namespace UniRx.Async } return (ignoreTimeScale) - ? new UniTask2(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token) - : new UniTask2(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token); + ? new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token) + : new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token); } - public static UniTask2 Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { if (delayTimeSpan < TimeSpan.Zero) { @@ -54,8 +53,8 @@ namespace UniRx.Async } return (ignoreTimeScale) - ? new UniTask2(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token) - : new UniTask2(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token); + ? new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token) + : new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token); } class YieldPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem @@ -405,244 +404,6 @@ namespace UniRx.Async } } - // TODO:rename - public struct YieldAwaitable2 - { - readonly PlayerLoopTiming timing; - - public YieldAwaitable2(PlayerLoopTiming timing) - { - this.timing = timing; - } - - public Awaiter GetAwaiter() - { - return new Awaiter(timing); - } - - public UniTask2 ToUniTask() - { - return UniTask2.Yield(timing, CancellationToken.None); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - readonly PlayerLoopTiming timing; - - public Awaiter(PlayerLoopTiming timing) - { - this.timing = timing; - } - - public bool IsCompleted => false; - - public void GetResult() { } - - public void OnCompleted(Action continuation) - { - PlayerLoopHelper.AddContinuation(timing, continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - PlayerLoopHelper.AddContinuation(timing, continuation); - } - } - } - - - // TODO:remove - public partial struct UniTask - { - public static YieldAwaitable Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update) - { - // optimized for single continuation - return new YieldAwaitable(timing); - } - - public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken) - { - return new UniTask(new YieldPromise(timing, cancellationToken)); - } - - public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) - { - if (delayFrameCount < 0) - { - throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount); - } - - var source = new DelayFramePromise(delayFrameCount, delayTiming, cancellationToken); - return source.Task; - } - - public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) - { - var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay); - if (delayTimeSpan < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayTimeSpan:" + delayTimeSpan); - } - - return (ignoreTimeScale) - ? new DelayIgnoreTimeScalePromise(delayTimeSpan, delayTiming, cancellationToken).Task - : new DelayPromise(delayTimeSpan, delayTiming, cancellationToken).Task; - } - - public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) - { - if (delayTimeSpan < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayTimeSpan:" + delayTimeSpan); - } - - return (ignoreTimeScale) - ? new DelayIgnoreTimeScalePromise(delayTimeSpan, delayTiming, cancellationToken).Task - : new DelayPromise(delayTimeSpan, delayTiming, cancellationToken).Task; - } - - class YieldPromise : PlayerLoopReusablePromiseBase - { - public YieldPromise(PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 2) - { - } - - protected override void OnRunningStart() - { - } - - public override bool MoveNext() - { - Complete(); - if (cancellationToken.IsCancellationRequested) - { - TrySetCanceled(); - } - else - { - TrySetResult(); - } - - return false; - } - } - - class DelayFramePromise : PlayerLoopReusablePromiseBase - { - readonly int delayFrameCount; - int currentFrameCount; - - public DelayFramePromise(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 2) - { - this.delayFrameCount = delayFrameCount; - this.currentFrameCount = 0; - } - - protected override void OnRunningStart() - { - currentFrameCount = 0; - } - - public override bool MoveNext() - { - if (cancellationToken.IsCancellationRequested) - { - Complete(); - TrySetCanceled(); - return false; - } - - if (currentFrameCount == delayFrameCount) - { - Complete(); - TrySetResult(currentFrameCount); - return false; - } - - currentFrameCount++; - return true; - } - } - - class DelayPromise : PlayerLoopReusablePromiseBase - { - readonly float delayFrameTimeSpan; - float elapsed; - - public DelayPromise(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 2) - { - this.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; - } - - protected override void OnRunningStart() - { - this.elapsed = 0.0f; - } - - public override bool MoveNext() - { - if (cancellationToken.IsCancellationRequested) - { - Complete(); - TrySetCanceled(); - return false; - } - - elapsed += Time.deltaTime; - if (elapsed >= delayFrameTimeSpan) - { - Complete(); - TrySetResult(); - return false; - } - - return true; - } - } - - class DelayIgnoreTimeScalePromise : PlayerLoopReusablePromiseBase - { - readonly float delayFrameTimeSpan; - float elapsed; - - public DelayIgnoreTimeScalePromise(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 2) - { - this.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; - } - - protected override void OnRunningStart() - { - this.elapsed = 0.0f; - } - - public override bool MoveNext() - { - if (cancellationToken.IsCancellationRequested) - { - Complete(); - TrySetCanceled(); - return false; - } - - elapsed += Time.unscaledDeltaTime; - - if (elapsed >= delayFrameTimeSpan) - { - Complete(); - TrySetResult(); - return false; - } - - return true; - } - } - } - - // TODO:remove public struct YieldAwaitable { readonly PlayerLoopTiming timing; diff --git a/Assets/UniRx.Async/UniTask.Factory.cs b/Assets/UniRx.Async/UniTask.Factory.cs index 9893ad2..e97d36e 100644 --- a/Assets/UniRx.Async/UniTask.Factory.cs +++ b/Assets/UniRx.Async/UniTask.Factory.cs @@ -7,11 +7,11 @@ using UnityEngine.Events; namespace UniRx.Async { - public partial struct UniTask2 + public partial struct UniTask { - static readonly UniTask2 CanceledUniTask = new Func(() => + static readonly UniTask CanceledUniTask = new Func(() => { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); promise.SetCanceled(CancellationToken.None); promise.MarkHandled(); return promise.Task; @@ -19,41 +19,41 @@ namespace UniRx.Async static class CanceledUniTaskCache { - public static readonly UniTask2 Task; + public static readonly UniTask Task; static CanceledUniTaskCache() { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); promise.SetCanceled(CancellationToken.None); promise.MarkHandled(); Task = promise.Task; } } - public static readonly UniTask2 CompletedTask = new UniTask2(); + public static readonly UniTask CompletedTask = new UniTask(); - public static UniTask2 FromException(Exception ex) + public static UniTask FromException(Exception ex) { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); promise.SetException(ex); promise.MarkHandled(); return promise.Task; } - public static UniTask2 FromException(Exception ex) + public static UniTask FromException(Exception ex) { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); promise.SetException(ex); promise.MarkHandled(); return promise.Task; } - public static UniTask2 FromResult(T value) + public static UniTask FromResult(T value) { - return new UniTask2(value); + return new UniTask(value); } - public static UniTask2 FromCanceled(CancellationToken cancellationToken = default) + public static UniTask FromCanceled(CancellationToken cancellationToken = default) { if (cancellationToken == CancellationToken.None) { @@ -61,14 +61,14 @@ namespace UniRx.Async } else { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); promise.SetCanceled(cancellationToken); promise.MarkHandled(); return promise.Task; } } - public static UniTask2 FromCanceled(CancellationToken cancellationToken = default) + public static UniTask FromCanceled(CancellationToken cancellationToken = default) { if (cancellationToken == CancellationToken.None) { @@ -76,7 +76,7 @@ namespace UniRx.Async } else { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); promise.SetCanceled(cancellationToken); promise.MarkHandled(); return promise.Task; @@ -120,143 +120,15 @@ namespace UniRx.Async } } - - // TODO:remove - public partial struct UniTask - { - static readonly UniTask CanceledUniTask = new Func(() => - { - var promise = new UniTaskCompletionSource(); - promise.TrySetCanceled(); - promise.MarkHandled(); - return new UniTask(promise); - })(); - - public static UniTask CompletedTask - { - get - { - return new UniTask(); - } - } - - public static UniTask FromException(Exception ex) - { - var promise = new UniTaskCompletionSource(); - promise.TrySetException(ex); - promise.MarkHandled(); - return new UniTask(promise); - } - - public static UniTask FromException(Exception ex) - { - var promise = new UniTaskCompletionSource(); - promise.TrySetException(ex); - promise.MarkHandled(); - return new UniTask(promise); - } - - public static UniTask FromResult(T value) - { - return new UniTask(value); - } - - public static UniTask FromCanceled() - { - return CanceledUniTask; - } - - public static UniTask FromCanceled() - { - return CanceledUniTaskCache.Task; - } - - public static UniTask FromCanceled(CancellationToken token) - { - var promise = new UniTaskCompletionSource(); - promise.TrySetException(new OperationCanceledException(token)); - promise.MarkHandled(); - return new UniTask(promise); - } - - public static UniTask FromCanceled(CancellationToken token) - { - var promise = new UniTaskCompletionSource(); - promise.TrySetException(new OperationCanceledException(token)); - promise.MarkHandled(); - return new UniTask(promise); - } - - /// shorthand of new UniTask[T](Func[UniTask[T]] factory) - public static UniTask Lazy(Func> factory) - { - return new UniTask(factory); - } - - /// - /// helper of create add UniTaskVoid to delegate. - /// For example: FooEvent += () => UniTask.Void(async () => { /* */ }) - /// - public static void Void(Func asyncAction) - { - asyncAction().Forget(); - } - - public static Action VoidAction(Func asyncAction) - { - return () => Void(asyncAction); - } - - public static UnityAction VoidUnityAction(Func asyncAction) - { - return () => Void(asyncAction); - } - - /// - /// helper of create add UniTaskVoid to delegate. - /// For example: FooEvent += (sender, e) => UniTask.Void(async arg => { /* */ }, (sender, e)) - /// - public static void Void(Func asyncAction, T state) - { - asyncAction(state).Forget(); - } - - static class CanceledUniTaskCache - { - public static readonly UniTask Task; - - static CanceledUniTaskCache() - { - var promise = new UniTaskCompletionSource(); - promise.TrySetCanceled(); - promise.MarkHandled(); - Task = new UniTask(promise); - } - } - } - - - // TODO:remove internal static class CompletedTasks { + public static readonly UniTask Completed = new UniTask(); + public static readonly UniTask AsyncUnit = UniTask.FromResult(UniRx.Async.AsyncUnit.Default); public static readonly UniTask True = UniTask.FromResult(true); public static readonly UniTask False = UniTask.FromResult(false); public static readonly UniTask Zero = UniTask.FromResult(0); public static readonly UniTask MinusOne = UniTask.FromResult(-1); public static readonly UniTask One = UniTask.FromResult(1); } - - - // TODO:rename - internal static class CompletedTasks2 - { - public static readonly UniTask2 Completed = new UniTask2(); - public static readonly UniTask2 AsyncUnit = UniTask2.FromResult(UniRx.Async.AsyncUnit.Default); - public static readonly UniTask2 True = UniTask2.FromResult(true); - public static readonly UniTask2 False = UniTask2.FromResult(false); - public static readonly UniTask2 Zero = UniTask2.FromResult(0); - public static readonly UniTask2 MinusOne = UniTask2.FromResult(-1); - public static readonly UniTask2 One = UniTask2.FromResult(1); - } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.cs b/Assets/UniRx.Async/UniTask.cs index bf71764..1b97d18 100644 --- a/Assets/UniRx.Async/UniTask.cs +++ b/Assets/UniRx.Async/UniTask.cs @@ -25,15 +25,15 @@ namespace UniRx.Async /// /// Lightweight unity specified task-like object. /// - [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder))] - public readonly partial struct UniTask2 + [AsyncMethodBuilder(typeof(AsyncUniTaskMethodBuilder))] + public readonly partial struct UniTask { readonly IUniTaskSource source; readonly short token; [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public UniTask2(IUniTaskSource source, short token) + public UniTask(IUniTaskSource source, short token) { this.source = source; this.token = token; @@ -60,12 +60,12 @@ namespace UniRx.Async /// /// returns (bool IsCanceled) instead of throws OperationCanceledException. /// - public UniTask2 SuppressCancellationThrow() + public UniTask SuppressCancellationThrow() { var status = Status; - if (status == AwaiterStatus.Succeeded) return CompletedTasks2.False; - if (status == AwaiterStatus.Canceled) return CompletedTasks2.True; - return new UniTask2(new IsCanceledSource(source), token); + if (status == AwaiterStatus.Succeeded) return CompletedTasks.False; + if (status == AwaiterStatus.Canceled) return CompletedTasks.True; + return new UniTask(new IsCanceledSource(source), token); } public override string ToString() @@ -77,7 +77,7 @@ namespace UniRx.Async /// /// Memoizing inner IValueTaskSource. The result UniTask can await multiple. /// - public UniTask2 Preserve() + public UniTask Preserve() { if (source == null) { @@ -85,21 +85,21 @@ namespace UniRx.Async } else { - return new UniTask2(new MemoizeSource(source), token); + return new UniTask(new MemoizeSource(source), token); } } - public static implicit operator UniTask2(UniTask2 task) + public static implicit operator UniTask(UniTask task) { - if (task.source == null) return CompletedTasks2.AsyncUnit; + if (task.source == null) return CompletedTasks.AsyncUnit; var status = task.source.GetStatus(task.token); if (status.IsCompletedSuccessfully()) { - return CompletedTasks2.AsyncUnit; + return CompletedTasks.AsyncUnit; } - return new UniTask2(new AsyncUnitSource(task.source), task.token); + return new UniTask(new AsyncUnitSource(task.source), task.token); } class AsyncUnitSource : IUniTaskSource @@ -261,11 +261,11 @@ namespace UniRx.Async public readonly struct Awaiter : ICriticalNotifyCompletion { - readonly UniTask2 task; + readonly UniTask task; [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Awaiter(in UniTask2 task) + public Awaiter(in UniTask task) { this.task = task; } @@ -336,8 +336,8 @@ namespace UniRx.Async /// /// Lightweight unity specified task-like object. /// - [AsyncMethodBuilder(typeof(AsyncUniTask2MethodBuilder<>))] - public readonly struct UniTask2 + [AsyncMethodBuilder(typeof(AsyncUniTaskMethodBuilder<>))] + public readonly struct UniTask { readonly IUniTaskSource source; readonly T result; @@ -345,7 +345,7 @@ namespace UniRx.Async [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public UniTask2(T result) + public UniTask(T result) { this.source = default; this.token = default; @@ -354,7 +354,7 @@ namespace UniRx.Async [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public UniTask2(IUniTaskSource source, short token) + public UniTask(IUniTaskSource source, short token) { this.source = source; this.token = token; @@ -381,7 +381,7 @@ namespace UniRx.Async /// /// Memoizing inner IValueTaskSource. The result UniTask can await multiple. /// - public UniTask2 Preserve() + public UniTask Preserve() { if (source == null) { @@ -389,34 +389,34 @@ namespace UniRx.Async } else { - return new UniTask2(new MemoizeSource(source), token); + return new UniTask(new MemoizeSource(source), token); } } - public static implicit operator UniTask2(UniTask2 task) + public static implicit operator UniTask(UniTask task) { - if (task.source == null) return UniTask2.CompletedTask; + if (task.source == null) return UniTask.CompletedTask; var status = task.source.GetStatus(task.token); if (status.IsCompletedSuccessfully()) { - return UniTask2.CompletedTask; + return UniTask.CompletedTask; } - return new UniTask2(task.source, task.token); + return new UniTask(task.source, task.token); } /// /// returns (bool IsCanceled, T Result) instead of throws OperationCanceledException. /// - public UniTask2<(bool IsCanceled, T Result)> SuppressCancellationThrow() + public UniTask<(bool IsCanceled, T Result)> SuppressCancellationThrow() { if (source == null) { - return new UniTask2<(bool IsCanceled, T Result)>((false, result)); + return new UniTask<(bool IsCanceled, T Result)>((false, result)); } - return new UniTask2<(bool, T)>(new IsCanceledSource(source), token); + return new UniTask<(bool, T)>(new IsCanceledSource(source), token); } public override string ToString() @@ -568,11 +568,11 @@ namespace UniRx.Async public readonly struct Awaiter : ICriticalNotifyCompletion { - readonly UniTask2 task; + readonly UniTask task; [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Awaiter(in UniTask2 task) + public Awaiter(in UniTask task) { this.task = task; } @@ -649,472 +649,6 @@ namespace UniRx.Async } } } - - - /// - /// Lightweight unity specified task-like object. - /// - [AsyncMethodBuilder(typeof(AsyncUniTaskMethodBuilder))] - public partial struct UniTask : IEquatable - { - static readonly UniTask DefaultAsyncUnitTask = new UniTask(AsyncUnit.Default); - - readonly IAwaiter awaiter; - - [DebuggerHidden] - public UniTask(IAwaiter awaiter) - { - this.awaiter = awaiter; - } - - [DebuggerHidden] - public UniTask(Func factory) - { - this.awaiter = new LazyPromise(factory); - } - - [DebuggerHidden] - public AwaiterStatus Status - { - get - { - return awaiter == null ? AwaiterStatus.Succeeded : awaiter.Status; - } - } - - [DebuggerHidden] - public bool IsCompleted - { - get - { - return awaiter == null ? true : awaiter.IsCompleted; - } - } - - [DebuggerHidden] - public void GetResult() - { - if (awaiter != null) - { - awaiter.GetResult(); - } - } - - [DebuggerHidden] - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - /// - /// returns (bool IsCanceled) instead of throws OperationCanceledException. - /// - public UniTask SuppressCancellationThrow() - { - var status = Status; - if (status == AwaiterStatus.Succeeded) return CompletedTasks.False; - if (status == AwaiterStatus.Canceled) return CompletedTasks.True; - return new UniTask(new IsCanceledAwaiter(awaiter)); - } - - public bool Equals(UniTask other) - { - if (this.awaiter == null && other.awaiter == null) - { - return true; - } - else if (this.awaiter != null && other.awaiter != null) - { - return this.awaiter == other.awaiter; - } - else - { - return false; - } - } - - public override int GetHashCode() - { - if (this.awaiter == null) - { - return 0; - } - else - { - return this.awaiter.GetHashCode(); - } - } - - public override string ToString() - { - return (this.awaiter == null) ? "()" - : (this.awaiter.Status == AwaiterStatus.Succeeded) ? "()" - : "(" + this.awaiter.Status + ")"; - } - - public static implicit operator UniTask(UniTask task) - { - if (task.awaiter != null) - { - if (task.awaiter.IsCompleted) - { - return DefaultAsyncUnitTask; - } - else - { - // UniTask -> UniTask is free but UniTask -> UniTask requires wrapping cost. - return new UniTask(new AsyncUnitAwaiter(task.awaiter)); - } - } - else - { - return DefaultAsyncUnitTask; - } - } - - class AsyncUnitAwaiter : IAwaiter - { - readonly IAwaiter awaiter; - - public AsyncUnitAwaiter(IAwaiter awaiter) - { - this.awaiter = awaiter; - } - - public bool IsCompleted => awaiter.IsCompleted; - - public AwaiterStatus Status => awaiter.Status; - - public AsyncUnit GetResult() - { - awaiter.GetResult(); - return AsyncUnit.Default; - } - - public void OnCompleted(Action continuation) - { - awaiter.OnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - awaiter.UnsafeOnCompleted(continuation); - } - - void IAwaiter.GetResult() - { - awaiter.GetResult(); - } - } - - class IsCanceledAwaiter : IAwaiter - { - readonly IAwaiter awaiter; - - public IsCanceledAwaiter(IAwaiter awaiter) - { - this.awaiter = awaiter; - } - - public bool IsCompleted => awaiter.IsCompleted; - - public AwaiterStatus Status => awaiter.Status; - - public bool GetResult() - { - if (awaiter.Status == AwaiterStatus.Canceled) - { - return true; - } - awaiter.GetResult(); - return false; - } - - public void OnCompleted(Action continuation) - { - awaiter.OnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - awaiter.UnsafeOnCompleted(continuation); - } - - void IAwaiter.GetResult() - { - awaiter.GetResult(); - } - } - - public struct Awaiter : IAwaiter - { - readonly UniTask task; - - [DebuggerHidden] - public Awaiter(UniTask task) - { - this.task = task; - } - - [DebuggerHidden] - public bool IsCompleted => task.IsCompleted; - - [DebuggerHidden] - public AwaiterStatus Status => task.Status; - - [DebuggerHidden] - public void GetResult() => task.GetResult(); - - [DebuggerHidden] - public void OnCompleted(Action continuation) - { - if (task.awaiter != null) - { - task.awaiter.OnCompleted(continuation); - } - else - { - continuation(); - } - } - - [DebuggerHidden] - public void UnsafeOnCompleted(Action continuation) - { - if (task.awaiter != null) - { - task.awaiter.UnsafeOnCompleted(continuation); - } - else - { - continuation(); - } - } - } - } - - /// - /// Lightweight unity specified task-like object. - /// - [AsyncMethodBuilder(typeof(AsyncUniTaskMethodBuilder<>))] - public struct UniTask : IEquatable> - { - readonly T result; - readonly IAwaiter awaiter; - - [DebuggerHidden] - public UniTask(T result) - { - this.result = result; - this.awaiter = null; - } - - [DebuggerHidden] - public UniTask(IAwaiter awaiter) - { - this.result = default(T); - this.awaiter = awaiter; - } - - [DebuggerHidden] - public UniTask(Func> factory) - { - this.result = default(T); - this.awaiter = new LazyPromise(factory); - } - - [DebuggerHidden] - public AwaiterStatus Status - { - get - { - return awaiter == null ? AwaiterStatus.Succeeded : awaiter.Status; - } - } - - [DebuggerHidden] - public bool IsCompleted - { - get - { - return awaiter == null ? true : awaiter.IsCompleted; - } - } - - [DebuggerHidden] - public T Result - { - get - { - if (awaiter == null) - { - return result; - } - else - { - return awaiter.GetResult(); - } - } - } - - [DebuggerHidden] - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - /// - /// returns (bool IsCanceled, T Result) instead of throws OperationCanceledException. - /// - public UniTask<(bool IsCanceled, T Result)> SuppressCancellationThrow() - { - var status = Status; - if (status == AwaiterStatus.Succeeded) - { - return new UniTask<(bool, T)>((false, Result)); - } - else if (status == AwaiterStatus.Canceled) - { - return new UniTask<(bool, T)>((true, default(T))); - } - return new UniTask<(bool, T)>(new IsCanceledAwaiter(awaiter)); - } - - public bool Equals(UniTask other) - { - if (this.awaiter == null && other.awaiter == null) - { - return EqualityComparer.Default.Equals(this.result, other.result); - } - else if (this.awaiter != null && other.awaiter != null) - { - return this.awaiter == other.awaiter; - } - else - { - return false; - } - } - - public override int GetHashCode() - { - if (this.awaiter == null) - { - if (result == null) return 0; - return result.GetHashCode(); - } - else - { - return this.awaiter.GetHashCode(); - } - } - - public override string ToString() - { - return (this.awaiter == null) ? result.ToString() - : (this.awaiter.Status == AwaiterStatus.Succeeded) ? this.awaiter.GetResult().ToString() - : "(" + this.awaiter.Status + ")"; - } - - public static implicit operator UniTask(UniTask task) - { - if (task.awaiter != null) - { - return new UniTask(task.awaiter); - } - else - { - return new UniTask(); - } - } - - class IsCanceledAwaiter : IAwaiter<(bool, T)> - { - readonly IAwaiter awaiter; - - public IsCanceledAwaiter(IAwaiter awaiter) - { - this.awaiter = awaiter; - } - - public bool IsCompleted => awaiter.IsCompleted; - - public AwaiterStatus Status => awaiter.Status; - - public (bool, T) GetResult() - { - if (awaiter.Status == AwaiterStatus.Canceled) - { - return (true, default(T)); - } - return (false, awaiter.GetResult()); - } - - public void OnCompleted(Action continuation) - { - awaiter.OnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - awaiter.UnsafeOnCompleted(continuation); - } - - void IAwaiter.GetResult() - { - awaiter.GetResult(); - } - } - - public struct Awaiter : IAwaiter - { - readonly UniTask task; - - [DebuggerHidden] - public Awaiter(in UniTask task) - { - this.task = task; - } - - [DebuggerHidden] - public bool IsCompleted => task.IsCompleted; - - [DebuggerHidden] - public AwaiterStatus Status => task.Status; - - [DebuggerHidden] - void IAwaiter.GetResult() => GetResult(); - - [DebuggerHidden] - public T GetResult() => task.Result; - - [DebuggerHidden] - public void OnCompleted(Action continuation) - { - if (task.awaiter != null) - { - task.awaiter.OnCompleted(continuation); - } - else - { - continuation(); - } - } - - [DebuggerHidden] - public void UnsafeOnCompleted(Action continuation) - { - if (task.awaiter != null) - { - task.awaiter.UnsafeOnCompleted(continuation); - } - else - { - continuation(); - } - } - } - } } #endif diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index 27355a4..73427f8 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -2,7 +2,6 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; -using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; @@ -12,52 +11,24 @@ using UniRx.Async.Internal; namespace UniRx.Async { - // TODO: Remove all? - - internal class ExceptionHolder - { - ExceptionDispatchInfo exception; - bool calledGet = false; - - public ExceptionHolder(ExceptionDispatchInfo exception) - { - this.exception = exception; - } - - public ExceptionDispatchInfo GetException() - { - if (!calledGet) - { - calledGet = true; - GC.SuppressFinalize(this); - } - return exception; - } - - ~ExceptionHolder() - { - UniTaskScheduler.PublishUnobservedTaskException(exception.SourceException); - } - } - public interface IResolvePromise { - bool TrySetResult(); + void SetResult(); } public interface IResolvePromise { - bool TrySetResult(T value); + void SetResult(T value); } public interface IRejectPromise { - bool TrySetException(Exception exception); + void SetException(Exception exception); } public interface ICancelPromise { - bool TrySetCanceled(); + void SetCanceled(CancellationToken cancellationToken = default); } public interface IPromise : IResolvePromise, IRejectPromise, ICancelPromise @@ -68,350 +39,6 @@ namespace UniRx.Async { } - public class UniTaskCompletionSource : IAwaiter, IPromise - { - // State(= AwaiterStatus) - const int Pending = 0; - const int Succeeded = 1; - const int Faulted = 2; - const int Canceled = 3; - - int state = 0; - bool handled = false; - ExceptionHolder exception; - object continuation; // action or list - - AwaiterStatus IAwaiter.Status => (AwaiterStatus)state; - - bool IAwaiter.IsCompleted => state != Pending; - - public UniTask Task => new UniTask(this); - - public UniTaskCompletionSource() - { - TaskTracker.TrackActiveTask(this, 2); - } - - [Conditional("UNITY_EDITOR")] - internal void MarkHandled() - { - if (!handled) - { - handled = true; - TaskTracker.RemoveTracking(this); - } - } - - void IAwaiter.GetResult() - { - MarkHandled(); - - if (state == Succeeded) - { - return; - } - else if (state == Faulted) - { - exception.GetException().Throw(); - } - else if (state == Canceled) - { - if (exception != null) - { - exception.GetException().Throw(); // guranteed operation canceled exception. - } - - throw new OperationCanceledException(); - } - else // Pending - { - throw new NotSupportedException("UniTask does not allow call GetResult directly when task not completed. Please use 'await'."); - } - } - - void ICriticalNotifyCompletion.UnsafeOnCompleted(Action action) - { - if (Interlocked.CompareExchange(ref continuation, (object)action, null) == null) - { - if (state != Pending) - { - TryInvokeContinuation(); - } - } - else - { - var c = continuation; - if (c is Action) - { - var list = new List(); - list.Add((Action)c); - list.Add(action); - if (Interlocked.CompareExchange(ref continuation, list, c) == c) - { - goto TRYINVOKE; - } - } - - var l = (List)continuation; - lock (l) - { - l.Add(action); - } - - TRYINVOKE: - if (state != Pending) - { - TryInvokeContinuation(); - } - } - } - - void TryInvokeContinuation() - { - var c = Interlocked.Exchange(ref continuation, null); - if (c != null) - { - if (c is Action) - { - ((Action)c).Invoke(); - } - else - { - var l = (List)c; - var cnt = l.Count; - for (int i = 0; i < cnt; i++) - { - l[i].Invoke(); - } - } - } - } - - public bool TrySetResult() - { - if (Interlocked.CompareExchange(ref state, Succeeded, Pending) == Pending) - { - TryInvokeContinuation(); - return true; - } - return false; - } - - public bool TrySetException(Exception exception) - { - if (Interlocked.CompareExchange(ref state, Faulted, Pending) == Pending) - { - this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception)); - TryInvokeContinuation(); - return true; - } - return false; - } - - public bool TrySetCanceled() - { - if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending) - { - TryInvokeContinuation(); - return true; - } - return false; - } - - public bool TrySetCanceled(OperationCanceledException exception) - { - if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending) - { - this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception)); - TryInvokeContinuation(); - return true; - } - return false; - } - - void INotifyCompletion.OnCompleted(Action continuation) - { - ((ICriticalNotifyCompletion)this).UnsafeOnCompleted(continuation); - } - } - - public class UniTaskCompletionSource : IAwaiter, IPromise - { - // State(= AwaiterStatus) - const int Pending = 0; - const int Succeeded = 1; - const int Faulted = 2; - const int Canceled = 3; - - int state = 0; - T value; - bool handled = false; - ExceptionHolder exception; - object continuation; // action or list - - bool IAwaiter.IsCompleted => state != Pending; - - public UniTask Task => new UniTask(this); - public UniTask UnitTask => new UniTask(this); - - AwaiterStatus IAwaiter.Status => (AwaiterStatus)state; - - public UniTaskCompletionSource() - { - TaskTracker.TrackActiveTask(this, 2); - } - - [Conditional("UNITY_EDITOR")] - internal void MarkHandled() - { - if (!handled) - { - handled = true; - TaskTracker.RemoveTracking(this); - } - } - - T IAwaiter.GetResult() - { - MarkHandled(); - - if (state == Succeeded) - { - return value; - } - else if (state == Faulted) - { - exception.GetException().Throw(); - } - else if (state == Canceled) - { - if (exception != null) - { - exception.GetException().Throw(); // guranteed operation canceled exception. - } - - throw new OperationCanceledException(); - } - else // Pending - { - throw new NotSupportedException("UniTask does not allow call GetResult directly when task not completed. Please use 'await'."); - } - - return default(T); - } - - void ICriticalNotifyCompletion.UnsafeOnCompleted(Action action) - { - if (Interlocked.CompareExchange(ref continuation, (object)action, null) == null) - { - if (state != Pending) - { - TryInvokeContinuation(); - } - } - else - { - var c = continuation; - if (c is Action) - { - var list = new List(); - list.Add((Action)c); - list.Add(action); - if (Interlocked.CompareExchange(ref continuation, list, c) == c) - { - goto TRYINVOKE; - } - } - - var l = (List)continuation; - lock (l) - { - l.Add(action); - } - - TRYINVOKE: - if (state != Pending) - { - TryInvokeContinuation(); - } - } - } - - void TryInvokeContinuation() - { - var c = Interlocked.Exchange(ref continuation, null); - if (c != null) - { - if (c is Action) - { - ((Action)c).Invoke(); - } - else - { - var l = (List)c; - var cnt = l.Count; - for (int i = 0; i < cnt; i++) - { - l[i].Invoke(); - } - } - } - } - - public bool TrySetResult(T value) - { - if (Interlocked.CompareExchange(ref state, Succeeded, Pending) == Pending) - { - this.value = value; - TryInvokeContinuation(); - return true; - } - return false; - } - - public bool TrySetException(Exception exception) - { - if (Interlocked.CompareExchange(ref state, Faulted, Pending) == Pending) - { - this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception)); - TryInvokeContinuation(); - return true; - } - return false; - } - - public bool TrySetCanceled() - { - if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending) - { - TryInvokeContinuation(); - return true; - } - return false; - } - - public bool TrySetCanceled(OperationCanceledException exception) - { - if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending) - { - this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception)); - TryInvokeContinuation(); - return true; - } - return false; - } - - void IAwaiter.GetResult() - { - ((IAwaiter)this).GetResult(); - } - - void INotifyCompletion.OnCompleted(Action continuation) - { - ((ICriticalNotifyCompletion)this).UnsafeOnCompleted(continuation); - } - } - [StructLayout(LayoutKind.Auto)] public struct UniTaskCompletionSourceCore { @@ -602,12 +229,22 @@ namespace UniRx.Async } } - public class UniTaskCompletionSource2 : IUniTaskSource + internal static class UniTaskCompletionSourceCoreShared // separated out of generic to avoid unnecessary duplication + { + internal static readonly Action s_sentinel = CompletionSentinel; + + private static void CompletionSentinel(object _) // named method to aid debugging + { + throw new InvalidOperationException("The sentinel delegate should never be invoked."); + } + } + + public class UniTaskCompletionSource : IUniTaskSource, IPromise { UniTaskCompletionSourceCore core; bool handled = false; - public UniTaskCompletionSource2() + public UniTaskCompletionSource() { TaskTracker2.TrackActiveTask(this, 2); } @@ -622,11 +259,11 @@ namespace UniRx.Async } } - public UniTask2 Task + public UniTask Task { get { - return new UniTask2(this, core.Version); + return new UniTask(this, core.Version); } } @@ -674,14 +311,14 @@ namespace UniRx.Async core.OnCompleted(continuation, state, token); } - ~UniTaskCompletionSource2() + ~UniTaskCompletionSource() { // clear error information. core.Reset(); } } - public class AutoResetUniTaskCompletionSource : IUniTaskSource, IPromisePoolItem + public class AutoResetUniTaskCompletionSource : IUniTaskSource, IPromisePoolItem, IPromise { static readonly PromisePool pool = new PromisePool(); @@ -722,11 +359,11 @@ namespace UniRx.Async return source; } - public UniTask2 Task + public UniTask Task { get { - return new UniTask2(this, core.Version); + return new UniTask(this, core.Version); } } @@ -737,7 +374,7 @@ namespace UniRx.Async public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCancellation(cancellationToken); + core.SetCanceled(cancellationToken); } public void SetException(Exception exception) @@ -789,12 +426,12 @@ namespace UniRx.Async } } - public class UniTaskCompletionSource2 : IUniTaskSource + public class UniTaskCompletionSource : IUniTaskSource, IPromise { UniTaskCompletionSourceCore core; bool handled = false; - public UniTaskCompletionSource2() + public UniTaskCompletionSource() { TaskTracker2.TrackActiveTask(this, 2); } @@ -809,11 +446,11 @@ namespace UniRx.Async } } - public UniTask2 Task + public UniTask Task { get { - return new UniTask2(this, core.Version); + return new UniTask(this, core.Version); } } @@ -831,7 +468,7 @@ namespace UniRx.Async public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCancellation(cancellationToken); + core.SetCanceled(cancellationToken); } public void SetException(Exception exception) @@ -865,14 +502,14 @@ namespace UniRx.Async core.OnCompleted(continuation, state, token); } - ~UniTaskCompletionSource2() + ~UniTaskCompletionSource() { // clear error information. core.Reset(); } } - public class AutoResetUniTaskCompletionSource : IUniTaskSource, IPromisePoolItem + public class AutoResetUniTaskCompletionSource : IUniTaskSource, IPromisePoolItem, IPromise { static readonly PromisePool> pool = new PromisePool>(); @@ -892,7 +529,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) { var source = Create(); - source.SetCancellation(cancellationToken); + source.SetCanceled(cancellationToken); token = source.core.Version; return source; } @@ -913,11 +550,11 @@ namespace UniRx.Async return source; } - public UniTask2 Task + public UniTask Task { get { - return new UniTask2(this, core.Version); + return new UniTask(this, core.Version); } } @@ -928,7 +565,7 @@ namespace UniRx.Async public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCancellation(cancellationToken); + core.SetCanceled(cancellationToken); } public void SetException(Exception exception) @@ -983,16 +620,6 @@ namespace UniRx.Async } } } - - internal static class UniTaskCompletionSourceCoreShared // separated out of generic to avoid unnecessary duplication - { - internal static readonly Action s_sentinel = CompletionSentinel; - - private static void CompletionSentinel(object _) // named method to aid debugging - { - throw new InvalidOperationException("The sentinel delegate should never be invoked."); - } - } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTaskExtensions.cs b/Assets/UniRx.Async/UniTaskExtensions.cs index 6cdfaf8..64c0f9b 100644 --- a/Assets/UniRx.Async/UniTaskExtensions.cs +++ b/Assets/UniRx.Async/UniTaskExtensions.cs @@ -10,12 +10,12 @@ using UniRx.Async.Internal; namespace UniRx.Async { - public static partial class UniTaskExtensions2 + public static partial class UniTaskExtensions { /// /// Convert UniTask -> UniTask[AsyncUnit]. /// - public static UniTask2 AsAsyncUnitUniTask(this UniTask2 task) + public static UniTask AsAsyncUnitUniTask(this UniTask task) { // use implicit conversion return task; @@ -24,7 +24,7 @@ namespace UniRx.Async /// /// Convert UniTask[T] -> UniTask. /// - public static UniTask2 AsUniTask(this UniTask2 task) + public static UniTask AsUniTask(this UniTask task) { // use implicit conversion return task; @@ -33,13 +33,13 @@ namespace UniRx.Async /// /// Convert Task[T] -> UniTask[T]. /// - public static UniTask2 AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) + public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); task.ContinueWith((x, state) => { - var p = (UniTaskCompletionSource2)state; + var p = (UniTaskCompletionSource)state; switch (x.Status) { @@ -63,13 +63,13 @@ namespace UniRx.Async /// /// Convert Task -> UniTask. /// - public static UniTask2 AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) + public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) { - var promise = new UniTaskCompletionSource2(); + var promise = new UniTaskCompletionSource(); task.ContinueWith((x, state) => { - var p = (UniTaskCompletionSource2)state; + var p = (UniTaskCompletionSource)state; switch (x.Status) { @@ -90,7 +90,7 @@ namespace UniRx.Async return promise.Task; } - public static Task AsTask(this UniTask2 task) + public static Task AsTask(this UniTask task) { try { @@ -112,7 +112,7 @@ namespace UniRx.Async awaiter.SourceOnCompleted(state => { - var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask2.Awaiter))state; + var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask.Awaiter))state; try { var result = inAwaiter.GetResult(); @@ -132,7 +132,7 @@ namespace UniRx.Async } } - public static Task AsTask(this UniTask2 task) + public static Task AsTask(this UniTask task) { try { @@ -154,7 +154,7 @@ namespace UniRx.Async awaiter.SourceOnCompleted(state => { - var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask2.Awaiter))state; + var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask.Awaiter))state; try { inAwaiter.GetResult(); @@ -174,481 +174,6 @@ namespace UniRx.Async } } - public static IEnumerator ToCoroutine(this UniTask2 task, Action resultHandler = null, Action exceptionHandler = null) - { - return new ToCoroutineEnumerator(task, resultHandler, exceptionHandler); - } - - public static IEnumerator ToCoroutine(this UniTask2 task, Action exceptionHandler = null) - { - return new ToCoroutineEnumerator(task, exceptionHandler); - } - - public static UniTask Timeout(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) - { - return Timeout(task.AsAsyncUnitUniTask(), timeout, ignoreTimeScale, timeoutCheckTiming, taskCancellationTokenSource); - } - - // TODO: require UniTask2.Delay, WhenAny, etc... - - public static async UniTask Timeout(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) - { - // left, right both suppress operation canceled exception. - - var delayCancellationTokenSource = new CancellationTokenSource(); - var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); - - var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); - - if (!hasValue) - { - if (taskCancellationTokenSource != null) - { - taskCancellationTokenSource.Cancel(); - taskCancellationTokenSource.Dispose(); - } - - throw new TimeoutException("Exceed Timeout:" + timeout); - } - else - { - delayCancellationTokenSource.Cancel(); - delayCancellationTokenSource.Dispose(); - } - - if (value.IsCanceled) - { - Error.ThrowOperationCanceledException(); - } - - return value.Result; - } - - /// - /// Timeout with suppress OperationCanceledException. Returns (bool, IsCacneled). - /// - public static async UniTask2 TimeoutWithoutException(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) - { - var v = await TimeoutWithoutException(task.AsAsyncUnitUniTask(), timeout, ignoreTimeScale, timeoutCheckTiming, taskCancellationTokenSource); - return v.IsTimeout; - } - - - /// - /// Timeout with suppress OperationCanceledException. Returns (bool IsTimeout, T Result). - /// - public static async UniTask2<(bool IsTimeout, T Result)> TimeoutWithoutException(this UniTask2 task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) - { - // left, right both suppress operation canceled exception. - - var delayCancellationTokenSource = new CancellationTokenSource(); - var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); - - var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); - - if (!hasValue) - { - if (taskCancellationTokenSource != null) - { - taskCancellationTokenSource.Cancel(); - taskCancellationTokenSource.Dispose(); - } - - return (true, default(T)); - } - else - { - delayCancellationTokenSource.Cancel(); - delayCancellationTokenSource.Dispose(); - } - - if (value.IsCanceled) - { - Error.ThrowOperationCanceledException(); - } - - return (false, value.Result); - } - - public static void Forget(this UniTask2 task) - { - ForgetCore(task).Forget(); - } - - public static void Forget(this UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread = true) - { - if (exceptionHandler == null) - { - ForgetCore(task).Forget(); - } - else - { - ForgetCoreWithCatch(task, exceptionHandler, handleExceptionOnMainThread).Forget(); - } - } - - // UniTask to UniTaskVoid - static async UniTaskVoid ForgetCore(UniTask2 task) - { - await task; - } - - static async UniTaskVoid ForgetCoreWithCatch(UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread) - { - try - { - await task; - } - catch (Exception ex) - { - try - { - if (handleExceptionOnMainThread) - { - await UniTask2.SwitchToMainThread(); - } - exceptionHandler(ex); - } - catch (Exception ex2) - { - UniTaskScheduler.PublishUnobservedTaskException(ex2); - } - } - } - - public static void Forget(this UniTask2 task) - { - ForgetCore(task).Forget(); - } - - public static void Forget(this UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread = true) - { - if (exceptionHandler == null) - { - ForgetCore(task).Forget(); - } - else - { - ForgetCoreWithCatch(task, exceptionHandler, handleExceptionOnMainThread).Forget(); - } - } - - // UniTask to UniTaskVoid - static async UniTaskVoid ForgetCore(UniTask2 task) - { - await task; - } - - static async UniTaskVoid ForgetCoreWithCatch(UniTask2 task, Action exceptionHandler, bool handleExceptionOnMainThread) - { - try - { - await task; - } - catch (Exception ex) - { - try - { - if (handleExceptionOnMainThread) - { - await UniTask.SwitchToMainThread(); - } - exceptionHandler(ex); - } - catch (Exception ex2) - { - UniTaskScheduler.PublishUnobservedTaskException(ex2); - } - } - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Action continuationFunction) - { - continuationFunction(await task); - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) - { - await continuationFunction(await task); - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) - { - return continuationFunction(await task); - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Func> continuationFunction) - { - return await continuationFunction(await task); - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Action continuationFunction) - { - await task; - continuationFunction(); - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) - { - await task; - await continuationFunction(); - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Func continuationFunction) - { - await task; - return continuationFunction(); - } - - public static async UniTask2 ContinueWith(this UniTask2 task, Func> continuationFunction) - { - await task; - return await continuationFunction(); - } - - public static async UniTask2 ConfigureAwait(this Task task, PlayerLoopTiming timing) - { - await task.ConfigureAwait(false); - await UniTask2.Yield(timing); - } - - public static async UniTask2 ConfigureAwait(this Task task, PlayerLoopTiming timing) - { - var v = await task.ConfigureAwait(false); - await UniTask2.Yield(timing); - return v; - } - - public static async UniTask2 ConfigureAwait(this UniTask2 task, PlayerLoopTiming timing) - { - await task; - await UniTask2.Yield(timing); - } - - public static async UniTask2 ConfigureAwait(this UniTask2 task, PlayerLoopTiming timing) - { - var v = await task; - await UniTask2.Yield(timing); - return v; - } - - public static async UniTask2 Unwrap(this UniTask2> task) - { - return await await task; - } - - public static async UniTask2 Unwrap(this UniTask2 task) - { - await await task; - } - - class ToCoroutineEnumerator : IEnumerator - { - bool completed; - UniTask2 task; - Action exceptionHandler = null; - bool isStarted = false; - ExceptionDispatchInfo exception; - - public ToCoroutineEnumerator(UniTask2 task, Action exceptionHandler) - { - completed = false; - this.exceptionHandler = exceptionHandler; - this.task = task; - } - - async UniTaskVoid RunTask(UniTask2 task) - { - try - { - await task; - } - catch (Exception ex) - { - if (exceptionHandler != null) - { - exceptionHandler(ex); - } - else - { - this.exception = ExceptionDispatchInfo.Capture(ex); - } - } - finally - { - completed = true; - } - } - - public object Current => null; - - public bool MoveNext() - { - if (!isStarted) - { - isStarted = true; - RunTask(task).Forget(); - } - - if (exception != null) - { - // throw exception on iterator (main)thread. - // unfortunately unity test-runner can not handle throw exception on hand-write IEnumerator.MoveNext. - UnityEngine.Debug.LogException(exception.SourceException); - } - - return !completed; - } - - public void Reset() - { - } - } - - class ToCoroutineEnumerator : IEnumerator - { - bool completed; - Action resultHandler = null; - Action exceptionHandler = null; - bool isStarted = false; - UniTask2 task; - object current = null; - ExceptionDispatchInfo exception; - - public ToCoroutineEnumerator(UniTask2 task, Action resultHandler, Action exceptionHandler) - { - completed = false; - this.task = task; - this.resultHandler = resultHandler; - this.exceptionHandler = exceptionHandler; - } - - async UniTaskVoid RunTask(UniTask2 task) - { - try - { - var value = await task; - current = value; // boxed if T is struct... - if (resultHandler != null) - { - resultHandler(value); - } - } - catch (Exception ex) - { - if (exceptionHandler != null) - { - exceptionHandler(ex); - } - else - { - this.exception = ExceptionDispatchInfo.Capture(ex); - } - } - finally - { - completed = true; - } - } - - public object Current => current; - - public bool MoveNext() - { - if (!isStarted) - { - isStarted = true; - RunTask(task).Forget(); - } - - if (exception != null) - { - // throw exception on iterator (main)thread. - // unfortunately unity test-runner can not handle throw exception on hand-write IEnumerator.MoveNext. - UnityEngine.Debug.LogException(exception.SourceException); - } - - return !completed; - } - - public void Reset() - { - } - } - } - - // TODO:remove - public static partial class UniTaskExtensions - { - /// - /// Convert UniTask -> UniTask[AsyncUnit]. - /// - public static UniTask AsAsyncUnitUniTask(this UniTask task) - { - // use implicit conversion - return task; - } - - /// - /// Convert Task[T] -> UniTask[T]. - /// - public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) - { - var promise = new UniTaskCompletionSource(); - - task.ContinueWith((x, state) => - { - var p = (UniTaskCompletionSource)state; - - switch (x.Status) - { - case TaskStatus.Canceled: - p.TrySetCanceled(); - break; - case TaskStatus.Faulted: - p.TrySetException(x.Exception); - break; - case TaskStatus.RanToCompletion: - p.TrySetResult(x.Result); - break; - default: - throw new NotSupportedException(); - } - }, promise, useCurrentSynchronizationContext ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Current); - - return new UniTask(promise); - } - - /// - /// Convert Task -> UniTask. - /// - public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationContext = true) - { - var promise = new UniTaskCompletionSource(); - - task.ContinueWith((x, state) => - { - var p = (UniTaskCompletionSource)state; - - switch (x.Status) - { - case TaskStatus.Canceled: - p.TrySetCanceled(); - break; - case TaskStatus.Faulted: - p.TrySetException(x.Exception); - break; - case TaskStatus.RanToCompletion: - p.TrySetResult(default(AsyncUnit)); - break; - default: - throw new NotSupportedException(); - } - }, promise, useCurrentSynchronizationContext ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Current); - - return new UniTask(promise); - } - public static IEnumerator ToCoroutine(this UniTask task, Action resultHandler = null, Action exceptionHandler = null) { return new ToCoroutineEnumerator(task, resultHandler, exceptionHandler); @@ -664,6 +189,8 @@ namespace UniRx.Async return Timeout(task.AsAsyncUnitUniTask(), timeout, ignoreTimeScale, timeoutCheckTiming, taskCancellationTokenSource); } + // TODO: require UniTask2.Delay, WhenAny, etc... + public static async UniTask Timeout(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) { // left, right both suppress operation canceled exception. @@ -1001,7 +528,7 @@ namespace UniRx.Async try { var value = await task; - current = value; + current = value; // boxed if T is struct... if (resultHandler != null) { resultHandler(value); From fbec6e9a58e1aaeffb0a2a3ab2967593815e96d6 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Sun, 19 Apr 2020 03:38:30 +0900 Subject: [PATCH 009/173] check playerloop --- Assets/Scenes/SandboxMain.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Assets/Scenes/SandboxMain.cs b/Assets/Scenes/SandboxMain.cs index 528040e..6417aa3 100644 --- a/Assets/Scenes/SandboxMain.cs +++ b/Assets/Scenes/SandboxMain.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Text; using System.Threading; using System.Threading.Tasks; using UniRx.Async; @@ -122,3 +123,26 @@ public class SandboxMain : MonoBehaviour } } +public class ShowPlayerLoop +{ + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] + static void Init() + { + var playerLoop = UnityEngine.LowLevel.PlayerLoop.GetDefaultPlayerLoop(); + + var sb = new StringBuilder(); + sb.AppendLine("Default Playerloop List"); + foreach (var header in playerLoop.subSystemList) + { + sb.AppendFormat("------{0}------", header.type.Name); + sb.AppendLine(); + foreach (var subSystem in header.subSystemList) + { + sb.AppendFormat("{0}.{1}", header.type.Name, subSystem.type.Name); + sb.AppendLine(); + } + } + + UnityEngine.Debug.Log(sb.ToString()); + } +} \ No newline at end of file From 082f3e7335dd6a7ff5df1dfb1ff762dd1d63015c Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Mon, 20 Apr 2020 08:35:06 +0900 Subject: [PATCH 010/173] more more --- Assets/UniRx.Async/AsyncLazy.cs | 65 +++ .../CancellationTokenExtensions.cs | 6 +- .../CompilerServices/MoveNextRunner.cs | 2 +- .../UniRx.Async/EnumeratorAsyncExtensions.cs | 137 +++--- .../{IAwaiter.cs => IUniTaskSource.cs} | 41 +- ...Awaiter.cs.meta => IUniTaskSource.cs.meta} | 0 Assets/UniRx.Async/Internal/LazyPromise.cs | 4 +- .../UniRx.Async/Internal/ReusablePromise.cs | 395 ------------------ .../Internal/ReusablePromise.cs.meta | 11 - Assets/UniRx.Async/Internal/StatePool.cs | 57 +++ Assets/UniRx.Async/Internal/TaskTracker.cs | 4 +- .../UniRx.Async/Triggers/AsyncTriggerBase.cs | 6 +- Assets/UniRx.Async/UniTask.Delay.cs | 30 +- Assets/UniRx.Async/UniTask.Factory.cs | 18 +- Assets/UniRx.Async/UniTask.WhenAll.cs | 8 +- Assets/UniRx.Async/UniTask.cs | 78 ++-- Assets/UniRx.Async/UniTaskCompletionSource.cs | 38 +- Assets/UniRx.Async/UniTaskExtensions.cs | 64 ++- .../UniRx.Async/UnityAsyncExtensions.Jobs.cs | 22 +- Assets/UniRx.Async/UnityAsyncExtensions.cs | 184 ++++---- .../UniRx.Async/UnityAsyncExtensions.uGUI.cs | 4 +- 21 files changed, 425 insertions(+), 749 deletions(-) create mode 100644 Assets/UniRx.Async/AsyncLazy.cs rename Assets/UniRx.Async/{IAwaiter.cs => IUniTaskSource.cs} (59%) rename Assets/UniRx.Async/{IAwaiter.cs.meta => IUniTaskSource.cs.meta} (100%) delete mode 100644 Assets/UniRx.Async/Internal/ReusablePromise.cs delete mode 100644 Assets/UniRx.Async/Internal/ReusablePromise.cs.meta create mode 100644 Assets/UniRx.Async/Internal/StatePool.cs diff --git a/Assets/UniRx.Async/AsyncLazy.cs b/Assets/UniRx.Async/AsyncLazy.cs new file mode 100644 index 0000000..1969f61 --- /dev/null +++ b/Assets/UniRx.Async/AsyncLazy.cs @@ -0,0 +1,65 @@ +#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +using System; +using System.Threading; + +namespace UniRx.Async +{ + public class AsyncLazy + { + Func> valueFactory; + UniTask target; + object syncLock; + bool initialized; + + public AsyncLazy(Func> valueFactory) + { + this.valueFactory = valueFactory; + this.target = default; + this.syncLock = new object(); + this.initialized = false; + } + + internal AsyncLazy(UniTask value) + { + this.valueFactory = null; + this.target = value; + this.syncLock = null; + this.initialized = true; + } + + public UniTask Task => EnsureInitialized(); + + public UniTask.Awaiter GetAwaiter() => EnsureInitialized().GetAwaiter(); + + UniTask EnsureInitialized() + { + if (Volatile.Read(ref initialized)) + { + return target; + } + + return EnsureInitializedCore(); + } + + UniTask EnsureInitializedCore() + { + lock (syncLock) + { + if (!Volatile.Read(ref initialized)) + { + var f = Interlocked.Exchange(ref valueFactory, null); + if (f != null) + { + target = f().Preserve(); // with preserve(allow multiple await). + Volatile.Write(ref initialized, true); + } + } + } + + return target; + } + } +} +#endif \ No newline at end of file diff --git a/Assets/UniRx.Async/CancellationTokenExtensions.cs b/Assets/UniRx.Async/CancellationTokenExtensions.cs index 8bfe4be..3f9a89b 100644 --- a/Assets/UniRx.Async/CancellationTokenExtensions.cs +++ b/Assets/UniRx.Async/CancellationTokenExtensions.cs @@ -17,14 +17,14 @@ namespace UniRx.Async return (UniTask.FromCanceled(cts), default(CancellationTokenRegistration)); } - var promise = new UniTaskCompletionSource(); + var promise = new UniTaskCompletionSource(); return (promise.Task, cts.RegisterWithoutCaptureExecutionContext(cancellationTokenCallback, promise)); } static void Callback(object state) { - var promise = (UniTaskCompletionSource)state; - promise.TrySetResult(AsyncUnit.Default); + var promise = (UniTaskCompletionSource)state; + promise.SetResult(); } public static CancellationTokenRegistration RegisterWithoutCaptureExecutionContext(this CancellationToken cancellationToken, Action callback) diff --git a/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs b/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs index 365ca79..89f03a8 100644 --- a/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs +++ b/Assets/UniRx.Async/CompilerServices/MoveNextRunner.cs @@ -15,7 +15,7 @@ namespace UniRx.Async.CompilerServices void Return(); } - internal class MoveNextRunner : IMoveNextRunner, IPromisePoolItem + internal sealed class MoveNextRunner : IMoveNextRunner, IPromisePoolItem where TStateMachine : IAsyncStateMachine { static PromisePool> pool = new PromisePool>(); diff --git a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs index 0f6c5a6..d31388d 100644 --- a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs +++ b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs @@ -13,136 +13,117 @@ namespace UniRx.Async { public static class EnumeratorAsyncExtensions { - public static IAwaiter GetAwaiter(this IEnumerator enumerator) + public static UniTask.Awaiter GetAwaiter(this IEnumerator enumerator) { - var awaiter = new EnumeratorAwaiter(enumerator, CancellationToken.None); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - } - return awaiter; + return new UniTask(EnumeratorPromise.Create(enumerator, PlayerLoopTiming.Update, CancellationToken.None, out var token), token).GetAwaiter(); } public static UniTask ToUniTask(this IEnumerator enumerator) { - var awaiter = new EnumeratorAwaiter(enumerator, CancellationToken.None); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - } - return new UniTask(awaiter); + return new UniTask(EnumeratorPromise.Create(enumerator, PlayerLoopTiming.Update, CancellationToken.None, out var token), token); } public static UniTask ConfigureAwait(this IEnumerator enumerator, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { - var awaiter = new EnumeratorAwaiter(enumerator, cancellationToken); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(timing, awaiter); - } - return new UniTask(awaiter); + return new UniTask(EnumeratorPromise.Create(enumerator, timing, cancellationToken, out var token), token); } - class EnumeratorAwaiter : IAwaiter, IPlayerLoopItem + class EnumeratorPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { + static readonly PromisePool pool = new PromisePool(); + IEnumerator innerEnumerator; CancellationToken cancellationToken; + Action continuation; - AwaiterStatus status; ExceptionDispatchInfo exception; - public EnumeratorAwaiter(IEnumerator innerEnumerator, CancellationToken cancellationToken) + UniTaskCompletionSourceCore core; + + EnumeratorPromise() + { + } + + public static IUniTaskSource Create(IEnumerator innerEnumerator, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) { if (cancellationToken.IsCancellationRequested) { - status = AwaiterStatus.Canceled; - return; + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); } - this.innerEnumerator = ConsumeEnumerator(innerEnumerator); - this.status = AwaiterStatus.Pending; - this.cancellationToken = cancellationToken; - this.continuation = null; + var result = pool.TryRent() ?? new EnumeratorPromise(); - TaskTracker.TrackActiveTask(this, 2); + result.innerEnumerator = ConsumeEnumerator(innerEnumerator); + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; } - public bool IsCompleted => status.IsCompleted(); - - public AwaiterStatus Status => status; - - public void GetResult() + public void GetResult(short token) { - switch (status) + try { - case AwaiterStatus.Succeeded: - break; - case AwaiterStatus.Pending: - Error.ThrowNotYetCompleted(); - break; - case AwaiterStatus.Faulted: - exception.Throw(); - break; - case AwaiterStatus.Canceled: - Error.ThrowOperationCanceledException(); - break; - default: - break; + TaskTracker2.RemoveTracking(this); + core.GetResult(token); } + finally + { + pool.TryReturn(this); + } + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(AwaiterStatus.Canceled); + core.SetCanceled(cancellationToken); return false; } - var success = false; try { if (innerEnumerator.MoveNext()) { return true; } - else - { - success = true; - } } catch (Exception ex) { - exception = ExceptionDispatchInfo.Capture(ex); + core.SetException(ex); + return false; } - InvokeContinuation(success ? AwaiterStatus.Succeeded : AwaiterStatus.Faulted); + core.SetResult(null); return false; } - void InvokeContinuation(AwaiterStatus status) + public void Reset() { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.innerEnumerator = null; - - if (cont != null) cont.Invoke(); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; + core.Reset(); + innerEnumerator = default; + cancellationToken = default; + continuation = default; + exception = default; } // Unwrap YieldInstructions diff --git a/Assets/UniRx.Async/IAwaiter.cs b/Assets/UniRx.Async/IUniTaskSource.cs similarity index 59% rename from Assets/UniRx.Async/IAwaiter.cs rename to Assets/UniRx.Async/IUniTaskSource.cs index 46708d1..2aa12a4 100644 --- a/Assets/UniRx.Async/IAwaiter.cs +++ b/Assets/UniRx.Async/IUniTaskSource.cs @@ -6,9 +6,7 @@ using System.Runtime.CompilerServices; namespace UniRx.Async { - // TODO:rename to UniTaskStatus - - public enum AwaiterStatus + public enum UniTaskStatus { /// The operation has not yet completed. Pending = 0, @@ -20,16 +18,14 @@ namespace UniRx.Async Canceled = 3 } - - // similar as IValueTaskSource public interface IUniTaskSource { - AwaiterStatus GetStatus(short token); + UniTaskStatus GetStatus(short token); void OnCompleted(Action continuation, object state, short token); void GetResult(short token); - AwaiterStatus UnsafeGetStatus(); // only for debug use. + UniTaskStatus UnsafeGetStatus(); // only for debug use. } public interface IUniTaskSource : IUniTaskSource @@ -37,47 +33,34 @@ namespace UniRx.Async new T GetResult(short token); } - - public interface IAwaiter : ICriticalNotifyCompletion - { - AwaiterStatus Status { get; } - bool IsCompleted { get; } - void GetResult(); - } - - public interface IAwaiter : IAwaiter - { - new T GetResult(); - } - - public static class AwaiterStatusExtensions + public static class UniTaskStatusExtensions { /// != Pending. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsCompleted(this AwaiterStatus status) + public static bool IsCompleted(this UniTaskStatus status) { - return status != AwaiterStatus.Pending; + return status != UniTaskStatus.Pending; } /// == Succeeded. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsCompletedSuccessfully(this AwaiterStatus status) + public static bool IsCompletedSuccessfully(this UniTaskStatus status) { - return status == AwaiterStatus.Succeeded; + return status == UniTaskStatus.Succeeded; } /// == Canceled. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsCanceled(this AwaiterStatus status) + public static bool IsCanceled(this UniTaskStatus status) { - return status == AwaiterStatus.Canceled; + return status == UniTaskStatus.Canceled; } /// == Faulted. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsFaulted(this AwaiterStatus status) + public static bool IsFaulted(this UniTaskStatus status) { - return status == AwaiterStatus.Faulted; + return status == UniTaskStatus.Faulted; } } } diff --git a/Assets/UniRx.Async/IAwaiter.cs.meta b/Assets/UniRx.Async/IUniTaskSource.cs.meta similarity index 100% rename from Assets/UniRx.Async/IAwaiter.cs.meta rename to Assets/UniRx.Async/IUniTaskSource.cs.meta diff --git a/Assets/UniRx.Async/Internal/LazyPromise.cs b/Assets/UniRx.Async/Internal/LazyPromise.cs index e62fd59..dfea432 100644 --- a/Assets/UniRx.Async/Internal/LazyPromise.cs +++ b/Assets/UniRx.Async/Internal/LazyPromise.cs @@ -34,7 +34,7 @@ namespace UniRx.Async.Internal } } - public AwaiterStatus Status + public UniTaskStatus Status { get { @@ -94,7 +94,7 @@ namespace UniRx.Async.Internal } } - public AwaiterStatus Status + public UniTaskStatus Status { get { diff --git a/Assets/UniRx.Async/Internal/ReusablePromise.cs b/Assets/UniRx.Async/Internal/ReusablePromise.cs deleted file mode 100644 index 68ade0a..0000000 --- a/Assets/UniRx.Async/Internal/ReusablePromise.cs +++ /dev/null @@ -1,395 +0,0 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System; -using System.Diagnostics; -using System.Runtime.ExceptionServices; -using System.Threading; - -namespace UniRx.Async.Internal -{ - // public for some types uses it. - - public abstract class ReusablePromise : IAwaiter - { - ExceptionDispatchInfo exception; - object continuation; // Action or Queue - AwaiterStatus status; - - public UniTask Task => new UniTask(this); - - // can override for control 'start/reset' timing. - public virtual bool IsCompleted => status.IsCompleted(); - - public virtual void GetResult() - { - switch (status) - { - case AwaiterStatus.Succeeded: - return; - case AwaiterStatus.Faulted: - exception.Throw(); - break; - case AwaiterStatus.Canceled: - throw new OperationCanceledException(); - default: - break; - } - - throw new InvalidOperationException("Invalid Status:" + status); - } - - public AwaiterStatus Status => status; - - void IAwaiter.GetResult() - { - GetResult(); - } - - public void ResetStatus(bool forceReset) - { - if (forceReset) - { - status = AwaiterStatus.Pending; - } - else if (status == AwaiterStatus.Succeeded) - { - status = AwaiterStatus.Pending; - } - } - - public virtual bool TrySetCanceled() - { - if (status == AwaiterStatus.Pending) - { - status = AwaiterStatus.Canceled; - TryInvokeContinuation(); - return true; - } - return false; - } - - public virtual bool TrySetException(Exception ex) - { - if (status == AwaiterStatus.Pending) - { - status = AwaiterStatus.Faulted; - exception = ExceptionDispatchInfo.Capture(ex); - TryInvokeContinuation(); - return true; - } - return false; - } - - public virtual bool TrySetResult() - { - if (status == AwaiterStatus.Pending) - { - status = AwaiterStatus.Succeeded; - TryInvokeContinuation(); - return true; - } - return false; - } - - void TryInvokeContinuation() - { - if (continuation == null) return; - - if (continuation is Action act) - { - continuation = null; - act(); - } - else - { - // reuse Queue(don't null clear) - var q = (MinimumQueue)continuation; - var size = q.Count; - for (int i = 0; i < size; i++) - { - q.Dequeue().Invoke(); - } - } - } - - public void OnCompleted(Action action) - { - UnsafeOnCompleted(action); - } - - public void UnsafeOnCompleted(Action action) - { - if (continuation == null) - { - continuation = action; - return; - } - else - { - if (continuation is Action act) - { - var q = new MinimumQueue(4); - q.Enqueue(act); - q.Enqueue(action); - continuation = q; - return; - } - else - { - ((MinimumQueue)continuation).Enqueue(action); - } - } - } - } - - public abstract class ReusablePromise : IAwaiter - { - T result; - ExceptionDispatchInfo exception; - object continuation; // Action or Queue - AwaiterStatus status; - - public UniTask Task => new UniTask(this); - - // can override for control 'start/reset' timing. - public virtual bool IsCompleted => status.IsCompleted(); - - protected T RawResult => result; - - protected void ForceSetResult(T result) - { - this.result = result; - } - - public virtual T GetResult() - { - switch (status) - { - case AwaiterStatus.Succeeded: - return result; - case AwaiterStatus.Faulted: - exception.Throw(); - break; - case AwaiterStatus.Canceled: - throw new OperationCanceledException(); - default: - break; - } - - throw new InvalidOperationException("Invalid Status:" + status); - } - - public AwaiterStatus Status => status; - - void IAwaiter.GetResult() - { - GetResult(); - } - - public void ResetStatus(bool forceReset) - { - if (forceReset) - { - status = AwaiterStatus.Pending; - } - else if (status == AwaiterStatus.Succeeded) - { - status = AwaiterStatus.Pending; - } - } - - public virtual bool TrySetCanceled() - { - if (status == AwaiterStatus.Pending) - { - status = AwaiterStatus.Canceled; - TryInvokeContinuation(); - return true; - } - return false; - } - - public virtual bool TrySetException(Exception ex) - { - if (status == AwaiterStatus.Pending) - { - status = AwaiterStatus.Faulted; - exception = ExceptionDispatchInfo.Capture(ex); - TryInvokeContinuation(); - return true; - } - return false; - } - - public virtual bool TrySetResult(T result) - { - if (status == AwaiterStatus.Pending) - { - status = AwaiterStatus.Succeeded; - this.result = result; - TryInvokeContinuation(); - return true; - } - return false; - } - - protected void TryInvokeContinuation() - { - if (continuation == null) return; - - if (continuation is Action act) - { - continuation = null; - act(); - } - else - { - // reuse Queue(don't null clear) - var q = (MinimumQueue)continuation; - var size = q.Count; - for (int i = 0; i < size; i++) - { - q.Dequeue().Invoke(); - } - } - } - - public void OnCompleted(Action action) - { - UnsafeOnCompleted(action); - } - - public void UnsafeOnCompleted(Action action) - { - if (continuation == null) - { - continuation = action; - return; - } - else - { - if (continuation is Action act) - { - var q = new MinimumQueue(4); - q.Enqueue(act); - q.Enqueue(action); - continuation = q; - return; - } - else - { - ((MinimumQueue)continuation).Enqueue(action); - } - } - } - } - - public abstract class PlayerLoopReusablePromiseBase : ReusablePromise, IPlayerLoopItem - { - readonly PlayerLoopTiming timing; - protected readonly CancellationToken cancellationToken; - bool isRunning = false; - -#if UNITY_EDITOR - string capturedStackTraceForDebugging; -#endif - - public PlayerLoopReusablePromiseBase(PlayerLoopTiming timing, CancellationToken cancellationToken, int skipTrackFrameCountAdditive) - { - this.timing = timing; - this.cancellationToken = cancellationToken; - -#if UNITY_EDITOR - this.capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(skipTrackFrameCountAdditive + 1); // 1 is self, -#endif - } - - public override bool IsCompleted - { - get - { - if (Status == AwaiterStatus.Canceled || Status == AwaiterStatus.Faulted) return true; - - if (!isRunning) - { - isRunning = true; - ResetStatus(false); - OnRunningStart(); -#if UNITY_EDITOR - TaskTracker.TrackActiveTask(this, capturedStackTraceForDebugging); -#endif - PlayerLoopHelper.AddAction(timing, this); - } - return false; - } - } - - protected abstract void OnRunningStart(); - - protected void Complete() - { - isRunning = false; -#if UNITY_EDITOR - TaskTracker.RemoveTracking(this); -#endif - } - - public abstract bool MoveNext(); - } - - public abstract class PlayerLoopReusablePromiseBase : ReusablePromise, IPlayerLoopItem - { - readonly PlayerLoopTiming timing; - protected readonly CancellationToken cancellationToken; - bool isRunning = false; - -#if UNITY_EDITOR - string capturedStackTraceForDebugging; -#endif - - public PlayerLoopReusablePromiseBase(PlayerLoopTiming timing, CancellationToken cancellationToken, int skipTrackFrameCountAdditive) - { - this.timing = timing; - this.cancellationToken = cancellationToken; - -#if UNITY_EDITOR - this.capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(skipTrackFrameCountAdditive + 1); // 1 is self, -#endif - } - - public override bool IsCompleted - { - get - { - if (Status == AwaiterStatus.Canceled || Status == AwaiterStatus.Faulted) return true; - - if (!isRunning) - { - isRunning = true; - ResetStatus(false); - OnRunningStart(); -#if UNITY_EDITOR - TaskTracker.TrackActiveTask(this, capturedStackTraceForDebugging); -#endif - PlayerLoopHelper.AddAction(timing, this); - } - return false; - } - } - - protected abstract void OnRunningStart(); - - protected void Complete() - { - isRunning = false; -#if UNITY_EDITOR - TaskTracker.RemoveTracking(this); -#endif - } - - public abstract bool MoveNext(); - } - -} -#endif diff --git a/Assets/UniRx.Async/Internal/ReusablePromise.cs.meta b/Assets/UniRx.Async/Internal/ReusablePromise.cs.meta deleted file mode 100644 index d86918f..0000000 --- a/Assets/UniRx.Async/Internal/ReusablePromise.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a8cfc99b5928c0242919aac2121b02bb -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Internal/StatePool.cs b/Assets/UniRx.Async/Internal/StatePool.cs new file mode 100644 index 0000000..b46f07b --- /dev/null +++ b/Assets/UniRx.Async/Internal/StatePool.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Concurrent; +using System.Runtime.CompilerServices; + +namespace UniRx.Async.Internal +{ + internal static class StateTuple + { + public static StateTuple Create(T1 item1, T2 item2) + { + return StatePool.Create(item1, item2); + } + } + + internal class StateTuple : IDisposable + { + public T1 Item1; + public T2 Item2; + + public void Deconstruct(out T1 item1, out T2 item2) + { + item1 = this.Item1; + item2 = this.Item2; + } + + public void Dispose() + { + StatePool.Return(this); + } + } + + internal static class StatePool + { + static readonly ConcurrentQueue> queue = new ConcurrentQueue>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static StateTuple Create(T1 item1, T2 item2) + { + if (queue.TryDequeue(out var value)) + { + value.Item1 = item1; + value.Item2 = item2; + return value; + } + + return new StateTuple { Item1 = item1, Item2 = item2 }; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Return(StateTuple tuple) + { + tuple.Item1 = default; + tuple.Item2 = default; + queue.Enqueue(tuple); + } + } +} diff --git a/Assets/UniRx.Async/Internal/TaskTracker.cs b/Assets/UniRx.Async/Internal/TaskTracker.cs index a1d2ae6..e69df26 100644 --- a/Assets/UniRx.Async/Internal/TaskTracker.cs +++ b/Assets/UniRx.Async/Internal/TaskTracker.cs @@ -116,7 +116,7 @@ namespace UniRx.Async.Internal } /// (trackingId, awaiterType, awaiterStatus, createdTime, stackTrace) - public static void ForEachActiveTask(Action action) + public static void ForEachActiveTask(Action action) { lock (listPool) { @@ -233,7 +233,7 @@ namespace UniRx.Async.Internal } /// (trackingId, awaiterType, awaiterStatus, createdTime, stackTrace) - public static void ForEachActiveTask(Action action) + public static void ForEachActiveTask(Action action) { lock (listPool) { diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs index ceb4f7f..b0ffa57 100644 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs +++ b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs @@ -32,13 +32,13 @@ namespace UniRx.Async.Triggers public override T GetResult() { - if (Status == AwaiterStatus.Pending) return RawResult; + if (Status == UniTaskStatus.Pending) return RawResult; return base.GetResult(); } public override bool TrySetResult(T result) { - if (Status == AwaiterStatus.Pending) + if (Status == UniTaskStatus.Pending) { // keep status as Pending. this.ForceSetResult(result); @@ -50,7 +50,7 @@ namespace UniRx.Async.Triggers public override bool TrySetCanceled() { - if (Status == AwaiterStatus.Canceled) return false; + if (Status == UniTaskStatus.Canceled) return false; TaskTracker.RemoveTracking(this); return base.TrySetCanceled(); } diff --git a/Assets/UniRx.Async/UniTask.Delay.cs b/Assets/UniRx.Async/UniTask.Delay.cs index 0ab0fb2..feb8074 100644 --- a/Assets/UniRx.Async/UniTask.Delay.cs +++ b/Assets/UniRx.Async/UniTask.Delay.cs @@ -24,6 +24,8 @@ namespace UniRx.Async public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { + PlayerLoopHelper.Initialize( + if (delayFrameCount < 0) { throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount); @@ -57,7 +59,7 @@ namespace UniRx.Async : new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token); } - class YieldPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + sealed class YieldPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { static readonly PromisePool pool = new PromisePool(); @@ -100,12 +102,12 @@ namespace UniRx.Async } } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -134,7 +136,7 @@ namespace UniRx.Async } } - class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { static readonly PromisePool pool = new PromisePool(); @@ -181,12 +183,12 @@ namespace UniRx.Async } } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -223,7 +225,7 @@ namespace UniRx.Async } } - class DelayPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + sealed class DelayPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { static readonly PromisePool pool = new PromisePool(); @@ -271,12 +273,12 @@ namespace UniRx.Async } } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -313,7 +315,7 @@ namespace UniRx.Async } } - class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + sealed class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { static readonly PromisePool pool = new PromisePool(); @@ -361,12 +363,12 @@ namespace UniRx.Async } } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -404,7 +406,7 @@ namespace UniRx.Async } } - public struct YieldAwaitable + public readonly struct YieldAwaitable { readonly PlayerLoopTiming timing; @@ -423,7 +425,7 @@ namespace UniRx.Async return UniTask.Yield(timing, CancellationToken.None); } - public struct Awaiter : ICriticalNotifyCompletion + public readonly struct Awaiter : ICriticalNotifyCompletion { readonly PlayerLoopTiming timing; diff --git a/Assets/UniRx.Async/UniTask.Factory.cs b/Assets/UniRx.Async/UniTask.Factory.cs index e97d36e..5878d91 100644 --- a/Assets/UniRx.Async/UniTask.Factory.cs +++ b/Assets/UniRx.Async/UniTask.Factory.cs @@ -83,12 +83,19 @@ namespace UniRx.Async } } - // TODO:... - - /// shorthand of new UniTask[T](Func[UniTask[T]] factory) - public static UniTask Lazy(Func> factory) + public static UniTask Create(Func factory) { - return new UniTask(factory); + return factory(); + } + + public static UniTask Create(Func> factory) + { + return factory(); + } + + public static AsyncLazy Lazy(Func> factory) + { + return new AsyncLazy(factory); } /// @@ -122,7 +129,6 @@ namespace UniRx.Async internal static class CompletedTasks { - public static readonly UniTask Completed = new UniTask(); public static readonly UniTask AsyncUnit = UniTask.FromResult(UniRx.Async.AsyncUnit.Default); public static readonly UniTask True = UniTask.FromResult(true); public static readonly UniTask False = UniTask.FromResult(false); diff --git a/Assets/UniRx.Async/UniTask.WhenAll.cs b/Assets/UniRx.Async/UniTask.WhenAll.cs index 715e55b..7b087d4 100644 --- a/Assets/UniRx.Async/UniTask.WhenAll.cs +++ b/Assets/UniRx.Async/UniTask.WhenAll.cs @@ -62,12 +62,12 @@ namespace UniRx.Async for (int i = 0; i < tasksLength; i++) { - if (tasks[i].IsCompleted) + if (tasks[i].Status.IsCompleted()) { T value = default(T); try { - value = tasks[i].Result; + value = tasks[i].GetAwaiter().GetResult(); } catch (Exception ex) { @@ -189,11 +189,11 @@ namespace UniRx.Async for (int i = 0; i < tasksLength; i++) { - if (tasks[i].IsCompleted) + if (tasks[i].Status.IsCompleted()) { try { - tasks[i].GetResult(); + tasks[i].GetAwaiter().GetResult(); } catch (Exception ex) { diff --git a/Assets/UniRx.Async/UniTask.cs b/Assets/UniRx.Async/UniTask.cs index 1b97d18..5a372a7 100644 --- a/Assets/UniRx.Async/UniTask.cs +++ b/Assets/UniRx.Async/UniTask.cs @@ -39,13 +39,13 @@ namespace UniRx.Async this.token = token; } - public AwaiterStatus Status + public UniTaskStatus Status { [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (source == null) return AwaiterStatus.Succeeded; + if (source == null) return UniTaskStatus.Succeeded; return source.GetStatus(token); } } @@ -63,8 +63,8 @@ namespace UniRx.Async public UniTask SuppressCancellationThrow() { var status = Status; - if (status == AwaiterStatus.Succeeded) return CompletedTasks.False; - if (status == AwaiterStatus.Canceled) return CompletedTasks.True; + if (status == UniTaskStatus.Succeeded) return CompletedTasks.False; + if (status == UniTaskStatus.Canceled) return CompletedTasks.True; return new UniTask(new IsCanceledSource(source), token); } @@ -89,20 +89,20 @@ namespace UniRx.Async } } - public static implicit operator UniTask(UniTask task) + public UniTask AsAsyncUnitUniTask() { - if (task.source == null) return CompletedTasks.AsyncUnit; + if (this.source == null) return CompletedTasks.AsyncUnit; - var status = task.source.GetStatus(task.token); + var status = this.source.GetStatus(this.token); if (status.IsCompletedSuccessfully()) { return CompletedTasks.AsyncUnit; } - return new UniTask(new AsyncUnitSource(task.source), task.token); + return new UniTask(new AsyncUnitSource(this.source), this.token); } - class AsyncUnitSource : IUniTaskSource + sealed class AsyncUnitSource : IUniTaskSource { readonly IUniTaskSource source; @@ -117,7 +117,7 @@ namespace UniRx.Async return AsyncUnit.Default; } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return source.GetStatus(token); } @@ -127,7 +127,7 @@ namespace UniRx.Async source.OnCompleted(continuation, state, token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return source.UnsafeGetStatus(); } @@ -138,7 +138,7 @@ namespace UniRx.Async } } - class IsCanceledSource : IUniTaskSource + sealed class IsCanceledSource : IUniTaskSource { readonly IUniTaskSource source; @@ -149,7 +149,7 @@ namespace UniRx.Async public bool GetResult(short token) { - if (source.GetStatus(token) == AwaiterStatus.Canceled) + if (source.GetStatus(token) == UniTaskStatus.Canceled) { return true; } @@ -163,12 +163,12 @@ namespace UniRx.Async GetResult(token); } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return source.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return source.UnsafeGetStatus(); } @@ -179,11 +179,11 @@ namespace UniRx.Async } } - class MemoizeSource : IUniTaskSource + sealed class MemoizeSource : IUniTaskSource { IUniTaskSource source; ExceptionDispatchInfo exception; - AwaiterStatus status; + UniTaskStatus status; public MemoizeSource(IUniTaskSource source) { @@ -204,18 +204,18 @@ namespace UniRx.Async try { source.GetResult(token); - status = AwaiterStatus.Succeeded; + status = UniTaskStatus.Succeeded; } catch (Exception ex) { exception = ExceptionDispatchInfo.Capture(ex); if (ex is OperationCanceledException) { - status = AwaiterStatus.Canceled; + status = UniTaskStatus.Canceled; } else { - status = AwaiterStatus.Faulted; + status = UniTaskStatus.Faulted; } throw; } @@ -226,7 +226,7 @@ namespace UniRx.Async } } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { if (source == null) { @@ -248,7 +248,7 @@ namespace UniRx.Async } } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { if (source == null) { @@ -361,13 +361,13 @@ namespace UniRx.Async this.result = default; } - public AwaiterStatus Status + public UniTaskStatus Status { [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - return (source == null) ? AwaiterStatus.Succeeded : source.GetStatus(token); + return (source == null) ? UniTaskStatus.Succeeded : source.GetStatus(token); } } @@ -393,17 +393,17 @@ namespace UniRx.Async } } - public static implicit operator UniTask(UniTask task) + public UniTask AsUniTask() { - if (task.source == null) return UniTask.CompletedTask; + if (this.source == null) return UniTask.CompletedTask; - var status = task.source.GetStatus(task.token); + var status = this.source.GetStatus(this.token); if (status.IsCompletedSuccessfully()) { return UniTask.CompletedTask; } - return new UniTask(task.source, task.token); + return new UniTask(this.source, this.token); } /// @@ -425,7 +425,7 @@ namespace UniRx.Async : "(" + this.source.UnsafeGetStatus() + ")"; } - class IsCanceledSource : IUniTaskSource<(bool, T)> + sealed class IsCanceledSource : IUniTaskSource<(bool, T)> { readonly IUniTaskSource source; @@ -440,7 +440,7 @@ namespace UniRx.Async [MethodImpl(MethodImplOptions.AggressiveInlining)] public (bool, T) GetResult(short token) { - if (source.GetStatus(token) == AwaiterStatus.Canceled) + if (source.GetStatus(token) == UniTaskStatus.Canceled) { return (true, default); } @@ -458,14 +458,14 @@ namespace UniRx.Async [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return source.GetStatus(token); } [DebuggerHidden] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return source.UnsafeGetStatus(); } @@ -478,12 +478,12 @@ namespace UniRx.Async } } - class MemoizeSource : IUniTaskSource + sealed class MemoizeSource : IUniTaskSource { IUniTaskSource source; T result; ExceptionDispatchInfo exception; - AwaiterStatus status; + UniTaskStatus status; public MemoizeSource(IUniTaskSource source) { @@ -505,7 +505,7 @@ namespace UniRx.Async try { result = source.GetResult(token); - status = AwaiterStatus.Succeeded; + status = UniTaskStatus.Succeeded; return result; } catch (Exception ex) @@ -513,11 +513,11 @@ namespace UniRx.Async exception = ExceptionDispatchInfo.Capture(ex); if (ex is OperationCanceledException) { - status = AwaiterStatus.Canceled; + status = UniTaskStatus.Canceled; } else { - status = AwaiterStatus.Faulted; + status = UniTaskStatus.Faulted; } throw; } @@ -533,7 +533,7 @@ namespace UniRx.Async GetResult(token); } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { if (source == null) { @@ -555,7 +555,7 @@ namespace UniRx.Async } } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { if (source == null) { diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index 73427f8..0ef9906 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -45,7 +45,7 @@ namespace UniRx.Async // Struct Size: TResult + (8 + 2 + 1 + 1 + 8 + 8) TResult result; - object error; // Exception or OperationCanceledException + object error; // ExceptionDispatchInfo or OperationCanceledException short version; bool completed; bool hasUnhandledError; @@ -119,23 +119,23 @@ namespace UniRx.Async /// Gets the status of the operation. /// Opaque value that was provided to the 's constructor. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { ValidateToken(token); - return (continuation == null || !completed) ? AwaiterStatus.Pending - : (error == null) ? AwaiterStatus.Succeeded - : (error is OperationCanceledException) ? AwaiterStatus.Canceled - : AwaiterStatus.Faulted; + return (continuation == null || !completed) ? UniTaskStatus.Pending + : (error == null) ? UniTaskStatus.Succeeded + : (error is OperationCanceledException) ? UniTaskStatus.Canceled + : UniTaskStatus.Faulted; } /// Gets the status of the operation without token validation. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { - return (continuation == null || !completed) ? AwaiterStatus.Pending - : (error == null) ? AwaiterStatus.Succeeded - : (error is OperationCanceledException) ? AwaiterStatus.Canceled - : AwaiterStatus.Faulted; + return (continuation == null || !completed) ? UniTaskStatus.Pending + : (error == null) ? UniTaskStatus.Succeeded + : (error is OperationCanceledException) ? UniTaskStatus.Canceled + : UniTaskStatus.Faulted; } /// Gets the result of the operation. @@ -296,12 +296,12 @@ namespace UniRx.Async core.GetResult(token); } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -396,12 +396,12 @@ namespace UniRx.Async } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -487,12 +487,12 @@ namespace UniRx.Async GetResult(token); } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -591,12 +591,12 @@ namespace UniRx.Async GetResult(token); } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } diff --git a/Assets/UniRx.Async/UniTaskExtensions.cs b/Assets/UniRx.Async/UniTaskExtensions.cs index 64c0f9b..d643bc3 100644 --- a/Assets/UniRx.Async/UniTaskExtensions.cs +++ b/Assets/UniRx.Async/UniTaskExtensions.cs @@ -12,24 +12,6 @@ namespace UniRx.Async { public static partial class UniTaskExtensions { - /// - /// Convert UniTask -> UniTask[AsyncUnit]. - /// - public static UniTask AsAsyncUnitUniTask(this UniTask task) - { - // use implicit conversion - return task; - } - - /// - /// Convert UniTask[T] -> UniTask. - /// - public static UniTask AsUniTask(this UniTask task) - { - // use implicit conversion - return task; - } - /// /// Convert Task[T] -> UniTask[T]. /// @@ -112,17 +94,20 @@ namespace UniRx.Async awaiter.SourceOnCompleted(state => { - var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask.Awaiter))state; - try + using (var tuple = (StateTuple, UniTask.Awaiter>)state) { - var result = inAwaiter.GetResult(); - inTcs.SetResult(result); + var (inTcs, inAwaiter) = tuple; + try + { + var result = inAwaiter.GetResult(); + inTcs.SetResult(result); + } + catch (Exception ex) + { + inTcs.SetException(ex); + } } - catch (Exception ex) - { - inTcs.SetException(ex); - } - }, (tcs, awaiter)); + }, StateTuple.Create(tcs, awaiter)); return tcs.Task; } @@ -154,17 +139,20 @@ namespace UniRx.Async awaiter.SourceOnCompleted(state => { - var (inTcs, inAwaiter) = ((TaskCompletionSource, UniTask.Awaiter))state; - try + using (var tuple = (StateTuple, UniTask.Awaiter>)state) { - inAwaiter.GetResult(); - inTcs.SetResult(null); + var (inTcs, inAwaiter) = tuple; + try + { + inAwaiter.GetResult(); + inTcs.SetResult(null); + } + catch (Exception ex) + { + inTcs.SetException(ex); + } } - catch (Exception ex) - { - inTcs.SetException(ex); - } - }, (tcs, awaiter)); + }, StateTuple.Create(tcs, awaiter)); return tcs.Task; } @@ -196,7 +184,7 @@ namespace UniRx.Async // left, right both suppress operation canceled exception. var delayCancellationTokenSource = new CancellationTokenSource(); - var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); + var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); @@ -242,7 +230,7 @@ namespace UniRx.Async // left, right both suppress operation canceled exception. var delayCancellationTokenSource = new CancellationTokenSource(); - var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); + var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs b/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs index 01185e3..2e958d6 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs @@ -52,20 +52,20 @@ namespace UniRx.Async { JobHandle jobHandle; CancellationToken cancellationToken; - AwaiterStatus status; + UniTaskStatus status; Action continuation; public JobHandleAwaiter(JobHandle jobHandle, CancellationToken cancellationToken, int skipFrame = 2) { - this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled - : jobHandle.IsCompleted ? AwaiterStatus.Succeeded - : AwaiterStatus.Pending; + this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled + : jobHandle.IsCompleted ? UniTaskStatus.Succeeded + : UniTaskStatus.Pending; if (this.status.IsCompleted()) return; this.jobHandle = jobHandle; this.cancellationToken = cancellationToken; - this.status = AwaiterStatus.Pending; + this.status = UniTaskStatus.Pending; this.continuation = null; TaskTracker.TrackActiveTask(this, skipFrame); @@ -73,15 +73,15 @@ namespace UniRx.Async public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public void GetResult() { - if (status == AwaiterStatus.Succeeded) + if (status == UniTaskStatus.Succeeded) { return; } - else if (status == AwaiterStatus.Canceled) + else if (status == UniTaskStatus.Canceled) { Error.ThrowOperationCanceledException(); } @@ -95,21 +95,21 @@ namespace UniRx.Async { // Call jobHandle.Complete after finished. PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, new JobHandleAwaiter(jobHandle, CancellationToken.None, 1)); - InvokeContinuation(AwaiterStatus.Canceled); + InvokeContinuation(UniTaskStatus.Canceled); return false; } if (jobHandle.IsCompleted) { jobHandle.Complete(); - InvokeContinuation(AwaiterStatus.Succeeded); + InvokeContinuation(UniTaskStatus.Succeeded); return false; } return true; } - void InvokeContinuation(AwaiterStatus status) + void InvokeContinuation(UniTaskStatus status) { this.status = status; var cont = this.continuation; diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index 47314cb..9bf78bb 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -187,28 +187,28 @@ namespace UniRx.Async { AsyncOperation asyncOperation; Action continuationAction; - AwaiterStatus status; + UniTaskStatus status; public AsyncOperationAwaiter(AsyncOperation asyncOperation) { - this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending; + this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; this.continuationAction = null; } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public void GetResult() { - if (status == AwaiterStatus.Succeeded) return; + if (status == UniTaskStatus.Succeeded) return; - if (status == AwaiterStatus.Pending) + if (status == UniTaskStatus.Pending) { // first timing of call if (asyncOperation.isDone) { - status = AwaiterStatus.Succeeded; + status = UniTaskStatus.Succeeded; } else { @@ -246,14 +246,14 @@ namespace UniRx.Async AsyncOperation asyncOperation; IProgress progress; CancellationToken cancellationToken; - AwaiterStatus status; + UniTaskStatus status; Action continuation; public AsyncOperationConfiguredAwaiter(AsyncOperation asyncOperation, IProgress progress, CancellationToken cancellationToken) { - this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled - : asyncOperation.isDone ? AwaiterStatus.Succeeded - : AwaiterStatus.Pending; + this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled + : asyncOperation.isDone ? UniTaskStatus.Succeeded + : UniTaskStatus.Pending; if (this.status.IsCompleted()) return; @@ -266,15 +266,15 @@ namespace UniRx.Async } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public void GetResult() { - if (status == AwaiterStatus.Succeeded) + if (status == UniTaskStatus.Succeeded) { return; } - else if (status == AwaiterStatus.Canceled) + else if (status == UniTaskStatus.Canceled) { Error.ThrowOperationCanceledException(); } @@ -286,7 +286,7 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(AwaiterStatus.Canceled); + InvokeContinuation(UniTaskStatus.Canceled); return false; } @@ -297,14 +297,14 @@ namespace UniRx.Async if (asyncOperation.isDone) { - InvokeContinuation(AwaiterStatus.Succeeded); + InvokeContinuation(UniTaskStatus.Succeeded); return false; } return true; } - void InvokeContinuation(AwaiterStatus status) + void InvokeContinuation(UniTaskStatus status) { this.status = status; var cont = this.continuation; @@ -335,30 +335,30 @@ namespace UniRx.Async { ResourceRequest asyncOperation; Action continuationAction; - AwaiterStatus status; + UniTaskStatus status; UnityEngine.Object result; public ResourceRequestAwaiter(ResourceRequest asyncOperation) { - this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending; + this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null; this.continuationAction = null; } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public UnityEngine.Object GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Pending) + if (status == UniTaskStatus.Pending) { // first timing of call if (asyncOperation.isDone) { - status = AwaiterStatus.Succeeded; + status = UniTaskStatus.Succeeded; } else { @@ -402,15 +402,15 @@ namespace UniRx.Async ResourceRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; - AwaiterStatus status; + UniTaskStatus status; Action continuation; UnityEngine.Object result; public ResourceRequestConfiguredAwaiter(ResourceRequest asyncOperation, IProgress progress, CancellationToken cancellationToken) { - this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled - : asyncOperation.isDone ? AwaiterStatus.Succeeded - : AwaiterStatus.Pending; + this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled + : asyncOperation.isDone ? UniTaskStatus.Succeeded + : UniTaskStatus.Pending; if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset; if (this.status.IsCompleted()) return; @@ -425,14 +425,14 @@ namespace UniRx.Async } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; void IAwaiter.GetResult() => GetResult(); public UnityEngine.Object GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Canceled) + if (status == UniTaskStatus.Canceled) { Error.ThrowOperationCanceledException(); } @@ -444,7 +444,7 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(AwaiterStatus.Canceled); + InvokeContinuation(UniTaskStatus.Canceled); return false; } @@ -456,14 +456,14 @@ namespace UniRx.Async if (asyncOperation.isDone) { this.result = asyncOperation.asset; - InvokeContinuation(AwaiterStatus.Succeeded); + InvokeContinuation(UniTaskStatus.Succeeded); return false; } return true; } - void InvokeContinuation(AwaiterStatus status) + void InvokeContinuation(UniTaskStatus status) { this.status = status; var cont = this.continuation; @@ -552,12 +552,12 @@ namespace UniRx.Async GetResult(token); } - public AwaiterStatus GetStatus(short token) + public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } - public AwaiterStatus UnsafeGetStatus() + public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } @@ -616,30 +616,30 @@ namespace UniRx.Async { AssetBundleRequest asyncOperation; Action continuationAction; - AwaiterStatus status; + UniTaskStatus status; UnityEngine.Object result; public AssetBundleRequestAwaiter(AssetBundleRequest asyncOperation) { - this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending; + this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null; this.continuationAction = null; } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public UnityEngine.Object GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Pending) + if (status == UniTaskStatus.Pending) { // first timing of call if (asyncOperation.isDone) { - status = AwaiterStatus.Succeeded; + status = UniTaskStatus.Succeeded; } else { @@ -683,15 +683,15 @@ namespace UniRx.Async AssetBundleRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; - AwaiterStatus status; + UniTaskStatus status; Action continuation; UnityEngine.Object result; public AssetBundleRequestConfiguredAwaiter(AssetBundleRequest asyncOperation, IProgress progress, CancellationToken cancellationToken) { - this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled - : asyncOperation.isDone ? AwaiterStatus.Succeeded - : AwaiterStatus.Pending; + this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled + : asyncOperation.isDone ? UniTaskStatus.Succeeded + : UniTaskStatus.Pending; if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset; if (this.status.IsCompleted()) return; @@ -706,14 +706,14 @@ namespace UniRx.Async } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; void IAwaiter.GetResult() => GetResult(); public UnityEngine.Object GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Canceled) + if (status == UniTaskStatus.Canceled) { Error.ThrowOperationCanceledException(); } @@ -725,7 +725,7 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(AwaiterStatus.Canceled); + InvokeContinuation(UniTaskStatus.Canceled); return false; } @@ -737,14 +737,14 @@ namespace UniRx.Async if (asyncOperation.isDone) { this.result = asyncOperation.asset; - InvokeContinuation(AwaiterStatus.Succeeded); + InvokeContinuation(UniTaskStatus.Succeeded); return false; } return true; } - void InvokeContinuation(AwaiterStatus status) + void InvokeContinuation(UniTaskStatus status) { this.status = status; var cont = this.continuation; @@ -776,30 +776,30 @@ namespace UniRx.Async { AssetBundleCreateRequest asyncOperation; Action continuationAction; - AwaiterStatus status; + UniTaskStatus status; AssetBundle result; public AssetBundleCreateRequestAwaiter(AssetBundleCreateRequest asyncOperation) { - this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending; + this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.assetBundle : null; this.continuationAction = null; } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public AssetBundle GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Pending) + if (status == UniTaskStatus.Pending) { // first timing of call if (asyncOperation.isDone) { - status = AwaiterStatus.Succeeded; + status = UniTaskStatus.Succeeded; } else { @@ -843,15 +843,15 @@ namespace UniRx.Async AssetBundleCreateRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; - AwaiterStatus status; + UniTaskStatus status; Action continuation; AssetBundle result; public AssetBundleCreateRequestConfiguredAwaiter(AssetBundleCreateRequest asyncOperation, IProgress progress, CancellationToken cancellationToken) { - this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled - : asyncOperation.isDone ? AwaiterStatus.Succeeded - : AwaiterStatus.Pending; + this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled + : asyncOperation.isDone ? UniTaskStatus.Succeeded + : UniTaskStatus.Pending; if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.assetBundle; if (this.status.IsCompleted()) return; @@ -866,14 +866,14 @@ namespace UniRx.Async } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; void IAwaiter.GetResult() => GetResult(); public AssetBundle GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Canceled) + if (status == UniTaskStatus.Canceled) { Error.ThrowOperationCanceledException(); } @@ -885,7 +885,7 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(AwaiterStatus.Canceled); + InvokeContinuation(UniTaskStatus.Canceled); return false; } @@ -897,14 +897,14 @@ namespace UniRx.Async if (asyncOperation.isDone) { this.result = asyncOperation.assetBundle; - InvokeContinuation(AwaiterStatus.Succeeded); + InvokeContinuation(UniTaskStatus.Succeeded); return false; } return true; } - void InvokeContinuation(AwaiterStatus status) + void InvokeContinuation(UniTaskStatus status) { this.status = status; var cont = this.continuation; @@ -942,14 +942,14 @@ namespace UniRx.Async WWW asyncOperation; IProgress progress; CancellationToken cancellationToken; - AwaiterStatus status; + UniTaskStatus status; Action continuation; public WWWConfiguredAwaiter(WWW asyncOperation, IProgress progress, CancellationToken cancellationToken) { - this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled - : asyncOperation.isDone ? AwaiterStatus.Succeeded - : AwaiterStatus.Pending; + this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled + : asyncOperation.isDone ? UniTaskStatus.Succeeded + : UniTaskStatus.Pending; if (this.status.IsCompleted()) return; @@ -962,15 +962,15 @@ namespace UniRx.Async } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public void GetResult() { - if (status == AwaiterStatus.Succeeded) + if (status == UniTaskStatus.Succeeded) { return; } - else if (status == AwaiterStatus.Canceled) + else if (status == UniTaskStatus.Canceled) { Error.ThrowOperationCanceledException(); } @@ -982,7 +982,7 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(AwaiterStatus.Canceled); + InvokeContinuation(UniTaskStatus.Canceled); return false; } @@ -993,14 +993,14 @@ namespace UniRx.Async if (asyncOperation.isDone) { - InvokeContinuation(AwaiterStatus.Succeeded); + InvokeContinuation(UniTaskStatus.Succeeded); return false; } return true; } - void InvokeContinuation(AwaiterStatus status) + void InvokeContinuation(UniTaskStatus status) { this.status = status; var cont = this.continuation; @@ -1039,30 +1039,30 @@ namespace UniRx.Async { UnityWebRequestAsyncOperation asyncOperation; Action continuationAction; - AwaiterStatus status; + UniTaskStatus status; UnityWebRequest result; public UnityWebRequestAsyncOperationAwaiter(UnityWebRequestAsyncOperation asyncOperation) { - this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending; + this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.webRequest : null; this.continuationAction = null; } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; public UnityWebRequest GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Pending) + if (status == UniTaskStatus.Pending) { // first timing of call if (asyncOperation.isDone) { - status = AwaiterStatus.Succeeded; + status = UniTaskStatus.Succeeded; } else { @@ -1107,15 +1107,15 @@ namespace UniRx.Async UnityWebRequestAsyncOperation asyncOperation; IProgress progress; CancellationToken cancellationToken; - AwaiterStatus status; + UniTaskStatus status; Action continuation; UnityWebRequest result; public UnityWebRequestAsyncOperationConfiguredAwaiter(UnityWebRequestAsyncOperation asyncOperation, IProgress progress, CancellationToken cancellationToken) { - this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled - : asyncOperation.isDone ? AwaiterStatus.Succeeded - : AwaiterStatus.Pending; + this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled + : asyncOperation.isDone ? UniTaskStatus.Succeeded + : UniTaskStatus.Pending; if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.webRequest; if (this.status.IsCompleted()) return; @@ -1130,14 +1130,14 @@ namespace UniRx.Async } public bool IsCompleted => status.IsCompleted(); - public AwaiterStatus Status => status; + public UniTaskStatus Status => status; void IAwaiter.GetResult() => GetResult(); public UnityWebRequest GetResult() { - if (status == AwaiterStatus.Succeeded) return this.result; + if (status == UniTaskStatus.Succeeded) return this.result; - if (status == AwaiterStatus.Canceled) + if (status == UniTaskStatus.Canceled) { Error.ThrowOperationCanceledException(); } @@ -1149,7 +1149,7 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(AwaiterStatus.Canceled); + InvokeContinuation(UniTaskStatus.Canceled); return false; } @@ -1161,14 +1161,14 @@ namespace UniRx.Async if (asyncOperation.isDone) { this.result = asyncOperation.webRequest; - InvokeContinuation(AwaiterStatus.Succeeded); + InvokeContinuation(UniTaskStatus.Succeeded); return false; } return true; } - void InvokeContinuation(AwaiterStatus status) + void InvokeContinuation(UniTaskStatus status) { this.status = status; var cont = this.continuation; diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs index b0effcb..45d9da9 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs @@ -265,7 +265,7 @@ namespace UniRx.Async } bool IAwaiter.IsCompleted => isDisposed ? true : false; - AwaiterStatus IAwaiter.Status => isDisposed ? AwaiterStatus.Canceled : AwaiterStatus.Pending; + UniTaskStatus IAwaiter.Status => isDisposed ? UniTaskStatus.Canceled : UniTaskStatus.Pending; void IAwaiter.GetResult() { if (isDisposed) throw new OperationCanceledException(); @@ -381,7 +381,7 @@ namespace UniRx.Async } bool IAwaiter.IsCompleted => isDisposed ? true : false; - AwaiterStatus IAwaiter.Status => isDisposed ? AwaiterStatus.Canceled : AwaiterStatus.Pending; + UniTaskStatus IAwaiter.Status => isDisposed ? UniTaskStatus.Canceled : UniTaskStatus.Pending; T IAwaiter.GetResult() { From 3654a9e2f98ab9d95762a15df54e4c3f4b9dad21 Mon Sep 17 00:00:00 2001 From: neuecc Date: Tue, 21 Apr 2020 13:36:23 +0900 Subject: [PATCH 011/173] WhenAll and WhenAny --- .../UniRx.Async/EnumeratorAsyncExtensions.cs | 14 +- Assets/UniRx.Async/Internal/ArrayPoolUtil.cs | 2 +- Assets/UniRx.Async/Internal/StatePool.cs | 52 + Assets/UniRx.Async/UniTask.Delay.cs | 50 +- Assets/UniRx.Async/UniTask.WaitUntil.cs | 437 +- .../UniRx.Async/UniTask.WhenAll.Generated.cs | 6738 ++++++++++++----- .../UniTask.WhenAll.Generated.cs.meta | 11 - .../UniRx.Async/UniTask.WhenAll.Generated.tt | 127 + Assets/UniRx.Async/UniTask.WhenAll.cs | 291 +- .../UniRx.Async/UniTask.WhenAny.Generated.cs | 6419 ++++++++++++---- .../UniTask.WhenAny.Generated.cs.meta | 11 - .../UniRx.Async/UniTask.WhenAny.Generated.tt | 122 + Assets/UniRx.Async/UniTask.WhenAny.cs | 519 +- Assets/UniRx.Async/UniTaskCompletionSource.cs | 121 +- Assets/UniRx.Async/UniTaskExtensions.cs | 22 +- Assets/UniRx.Async/UnityAsyncExtensions.cs | 4 +- 16 files changed, 11143 insertions(+), 3797 deletions(-) delete mode 100644 Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta create mode 100644 Assets/UniRx.Async/UniTask.WhenAll.Generated.tt delete mode 100644 Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta create mode 100644 Assets/UniRx.Async/UniTask.WhenAny.Generated.tt diff --git a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs index d31388d..4438f5b 100644 --- a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs +++ b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs @@ -96,7 +96,7 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); return false; } @@ -109,11 +109,11 @@ namespace UniRx.Async } catch (Exception ex) { - core.SetException(ex); + core.TrySetException(ex); return false; } - core.SetResult(null); + core.TrySetResult(null); return false; } @@ -126,6 +126,14 @@ namespace UniRx.Async exception = default; } + ~EnumeratorPromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } + // Unwrap YieldInstructions static IEnumerator ConsumeEnumerator(IEnumerator enumerator) diff --git a/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs b/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs index 127bb31..ee58010 100644 --- a/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs +++ b/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs @@ -40,7 +40,7 @@ namespace UniRx.Async.Internal return new RentArray(array, array.Length, null); } - var defaultCount = 4; + var defaultCount = 32; if (source is ICollection coll) { defaultCount = coll.Count; diff --git a/Assets/UniRx.Async/Internal/StatePool.cs b/Assets/UniRx.Async/Internal/StatePool.cs index b46f07b..7fe114b 100644 --- a/Assets/UniRx.Async/Internal/StatePool.cs +++ b/Assets/UniRx.Async/Internal/StatePool.cs @@ -10,6 +10,11 @@ namespace UniRx.Async.Internal { return StatePool.Create(item1, item2); } + + public static StateTuple Create(T1 item1, T2 item2, T3 item3) + { + return StatePool.Create(item1, item2, item3); + } } internal class StateTuple : IDisposable @@ -54,4 +59,51 @@ namespace UniRx.Async.Internal queue.Enqueue(tuple); } } + + internal class StateTuple : IDisposable + { + public T1 Item1; + public T2 Item2; + public T3 Item3; + + public void Deconstruct(out T1 item1, out T2 item2, out T3 item3) + { + item1 = this.Item1; + item2 = this.Item2; + item3 = this.Item3; + } + + public void Dispose() + { + StatePool.Return(this); + } + } + + internal static class StatePool + { + static readonly ConcurrentQueue> queue = new ConcurrentQueue>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static StateTuple Create(T1 item1, T2 item2, T3 item3) + { + if (queue.TryDequeue(out var value)) + { + value.Item1 = item1; + value.Item2 = item2; + value.Item3 = item3; + return value; + } + + return new StateTuple { Item1 = item1, Item2 = item2, Item3 = item3 }; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Return(StateTuple tuple) + { + tuple.Item1 = default; + tuple.Item2 = default; + tuple.Item3 = default; + queue.Enqueue(tuple); + } + } } diff --git a/Assets/UniRx.Async/UniTask.Delay.cs b/Assets/UniRx.Async/UniTask.Delay.cs index feb8074..df3f4ef 100644 --- a/Assets/UniRx.Async/UniTask.Delay.cs +++ b/Assets/UniRx.Async/UniTask.Delay.cs @@ -24,8 +24,6 @@ namespace UniRx.Async public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { - PlayerLoopHelper.Initialize( - if (delayFrameCount < 0) { throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount); @@ -121,11 +119,11 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); return false; } - core.SetResult(null); + core.TrySetResult(null); return false; } @@ -134,6 +132,14 @@ namespace UniRx.Async core.Reset(); cancellationToken = default; } + + ~YieldPromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } } sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem @@ -202,13 +208,13 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); return false; } if (currentFrameCount == delayFrameCount) { - core.SetResult(null); + core.TrySetResult(null); return false; } @@ -223,6 +229,14 @@ namespace UniRx.Async delayFrameCount = default; cancellationToken = default; } + + ~DelayFramePromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } } sealed class DelayPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem @@ -292,14 +306,14 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); return false; } elapsed += Time.deltaTime; if (elapsed >= delayFrameTimeSpan) { - core.SetResult(null); + core.TrySetResult(null); return false; } @@ -313,6 +327,14 @@ namespace UniRx.Async elapsed = default; cancellationToken = default; } + + ~DelayPromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } } sealed class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem @@ -382,14 +404,14 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); return false; } elapsed += Time.unscaledDeltaTime; if (elapsed >= delayFrameTimeSpan) { - core.SetResult(null); + core.TrySetResult(null); return false; } @@ -403,6 +425,14 @@ namespace UniRx.Async elapsed = default; cancellationToken = default; } + + ~DelayIgnoreTimeScalePromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } } } diff --git a/Assets/UniRx.Async/UniTask.WaitUntil.cs b/Assets/UniRx.Async/UniTask.WaitUntil.cs index 7326201..554dc59 100644 --- a/Assets/UniRx.Async/UniTask.WaitUntil.cs +++ b/Assets/UniRx.Async/UniTask.WaitUntil.cs @@ -12,14 +12,12 @@ namespace UniRx.Async { public static UniTask WaitUntil(Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { - var promise = new WaitUntilPromise(predicate, timing, cancellationToken); - return promise.Task; + return new UniTask(WaitUntilPromise.Create(predicate, timing, cancellationToken, out var token), token); } public static UniTask WaitWhile(Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) { - var promise = new WaitWhilePromise(predicate, timing, cancellationToken); - return promise.Task; + return new UniTask(WaitWhilePromise.Create(predicate, timing, cancellationToken, out var token), token); } public static UniTask WaitUntilValueChanged(T target, Func monitorFunction, PlayerLoopTiming monitorTiming = PlayerLoopTiming.Update, IEqualityComparer equalityComparer = null, CancellationToken cancellationToken = default(CancellationToken)) @@ -28,130 +26,293 @@ namespace UniRx.Async var unityObject = target as UnityEngine.Object; var isUnityObject = !object.ReferenceEquals(target, null); // don't use (unityObject == null) - return (isUnityObject) - ? new WaitUntilValueChangedUnityObjectPromise(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken).Task - : new WaitUntilValueChangedStandardObjectPromise(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken).Task; + return new UniTask(isUnityObject + ? WaitUntilValueChangedUnityObjectPromise.Create(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken, out var token) + : WaitUntilValueChangedStandardObjectPromise.Create(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken, out token), token); } - class WaitUntilPromise : PlayerLoopReusablePromiseBase + sealed class WaitUntilPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { - readonly Func predicate; + static readonly PromisePool pool = new PromisePool(); - public WaitUntilPromise(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 1) - { - this.predicate = predicate; - } + Func predicate; + CancellationToken cancellationToken; - protected override void OnRunningStart() + UniTaskCompletionSourceCore core; + + WaitUntilPromise() { } - public override bool MoveNext() + public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) { if (cancellationToken.IsCancellationRequested) { - Complete(); - TrySetCanceled(); - return false; + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); } - bool result = default(bool); + var result = pool.TryRent() ?? new WaitUntilPromise(); + + result.predicate = predicate; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { try { - result = predicate(); + TaskTracker2.RemoveTracking(this); + core.GetResult(token); } - catch (Exception ex) + finally { - Complete(); - TrySetException(ex); - return false; + pool.TryReturn(this); } - - if (result) - { - Complete(); - TrySetResult(); - return false; - } - - return true; } - } - class WaitWhilePromise : PlayerLoopReusablePromiseBase - { - readonly Func predicate; - - public WaitWhilePromise(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 1) + public UniTaskStatus GetStatus(short token) { - this.predicate = predicate; + return core.GetStatus(token); } - protected override void OnRunningStart() + public UniTaskStatus UnsafeGetStatus() { + return core.UnsafeGetStatus(); } - public override bool MoveNext() + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - Complete(); - TrySetCanceled(); + core.TrySetCanceled(cancellationToken); return false; } - bool result = default(bool); try { - result = predicate(); + if (!predicate()) + { + return true; + } } catch (Exception ex) { - Complete(); - TrySetException(ex); + core.TrySetException(ex); return false; } - if (!result) + core.TrySetResult(null); + return false; + } + + public void Reset() + { + core.Reset(); + predicate = default; + cancellationToken = default; + } + + ~WaitUntilPromise() + { + if (pool.TryReturn(this)) { - Complete(); - TrySetResult(); + GC.ReRegisterForFinalize(this); + } + } + } + + sealed class WaitWhilePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool pool = new PromisePool(); + + Func predicate; + CancellationToken cancellationToken; + + UniTaskCompletionSourceCore core; + + WaitWhilePromise() + { + } + + public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new WaitWhilePromise(); + + result.predicate = predicate; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); return false; } - return true; + try + { + if (predicate()) + { + return true; + } + } + catch (Exception ex) + { + core.TrySetException(ex); + return false; + } + + core.TrySetResult(null); + return false; + } + + public void Reset() + { + core.Reset(); + predicate = default; + cancellationToken = default; + } + + ~WaitWhilePromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } } } // where T : UnityEngine.Object, can not add constraint - class WaitUntilValueChangedUnityObjectPromise : PlayerLoopReusablePromiseBase + sealed class WaitUntilValueChangedUnityObjectPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { - readonly T target; - readonly Func monitorFunction; - readonly IEqualityComparer equalityComparer; + static readonly PromisePool> pool = new PromisePool>(); + + T target; U currentValue; + Func monitorFunction; + IEqualityComparer equalityComparer; + CancellationToken cancellationToken; - public WaitUntilValueChangedUnityObjectPromise(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 1) - { - this.target = target; - this.monitorFunction = monitorFunction; - this.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); - this.currentValue = monitorFunction(target); - } + UniTaskCompletionSourceCore core; - protected override void OnRunningStart() + WaitUntilValueChangedUnityObjectPromise() { } - public override bool MoveNext() + public static IUniTaskSource Create(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new WaitUntilValueChangedUnityObjectPromise(); + + result.target = target; + result.monitorFunction = monitorFunction; + result.currentValue = monitorFunction(target); + result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public U GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + return core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() { if (cancellationToken.IsCancellationRequested || target == null) // destroyed = cancel. { - Complete(); - TrySetCanceled(); + core.TrySetCanceled(cancellationToken); return false; } @@ -166,45 +327,112 @@ namespace UniRx.Async } catch (Exception ex) { - Complete(); - TrySetException(ex); + core.TrySetException(ex); return false; } - Complete(); - currentValue = nextValue; - TrySetResult(nextValue); + core.TrySetResult(nextValue); return false; } + + public void Reset() + { + core.Reset(); + target = default; + currentValue = default; + monitorFunction = default; + equalityComparer = default; + cancellationToken = default; + } + + ~WaitUntilValueChangedUnityObjectPromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } } - class WaitUntilValueChangedStandardObjectPromise : PlayerLoopReusablePromiseBase + + sealed class WaitUntilValueChangedStandardObjectPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem where T : class { - readonly WeakReference target; - readonly Func monitorFunction; - readonly IEqualityComparer equalityComparer; + static readonly PromisePool> pool = new PromisePool>(); + + WeakReference target; U currentValue; + Func monitorFunction; + IEqualityComparer equalityComparer; + CancellationToken cancellationToken; - public WaitUntilValueChangedStandardObjectPromise(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken) - : base(timing, cancellationToken, 1) - { - this.target = new WeakReference(target, false); // wrap in WeakReference. - this.monitorFunction = monitorFunction; - this.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); - this.currentValue = monitorFunction(target); - } + UniTaskCompletionSourceCore core; - protected override void OnRunningStart() + WaitUntilValueChangedStandardObjectPromise() { } - public override bool MoveNext() + public static IUniTaskSource Create(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) { - if (cancellationToken.IsCancellationRequested || !target.TryGetTarget(out var t)) + if (cancellationToken.IsCancellationRequested) { - Complete(); - TrySetCanceled(); + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new WaitUntilValueChangedStandardObjectPromise(); + + result.target = new WeakReference(target, false); // wrap in WeakReference. + result.monitorFunction = monitorFunction; + result.currentValue = monitorFunction(target); + result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public U GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + return core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested || !target.TryGetTarget(out var t)) // doesn't find = cancel. + { + core.TrySetCanceled(cancellationToken); return false; } @@ -219,16 +447,31 @@ namespace UniRx.Async } catch (Exception ex) { - Complete(); - TrySetException(ex); + core.TrySetException(ex); return false; } - Complete(); - currentValue = nextValue; - TrySetResult(nextValue); + core.TrySetResult(nextValue); return false; } + + public void Reset() + { + core.Reset(); + target = default; + currentValue = default; + monitorFunction = default; + equalityComparer = default; + cancellationToken = default; + } + + ~WaitUntilValueChangedStandardObjectPromise() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } } } } diff --git a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs index bda09db..8652192 100644 --- a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs +++ b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs @@ -1,1863 +1,5081 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Threading; +using UniRx.Async.Internal; namespace UniRx.Async { public partial struct UniTask { - public static async UniTask<(T1 result1, T2 result2)> WhenAll(UniTask task1, UniTask task2) + + public static UniTask<(T1, T2)> WhenAll(UniTask task1, UniTask task2) { - return await new WhenAllPromise(task1, task2); + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2)>(new WhenAllPromise(task1, task2), 0); } - public static async UniTask<(T1 result1, T2 result2, T3 result3)> WhenAll(UniTask task1, UniTask task2, UniTask task3) + sealed class WhenAllPromise : IUniTaskSource<(T1, T2)> { - return await new WhenAllPromise(task1, task2, task3); - } - - public static async UniTask<(T1 result1, T2 result2, T3 result3, T4 result4)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4) - { - return await new WhenAllPromise(task1, task2, task3, task4); - } - - public static async UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) - { - return await new WhenAllPromise(task1, task2, task3, task4, task5); - } - - public static async UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) - { - return await new WhenAllPromise(task1, task2, task3, task4, task5, task6); - } - - public static async UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) - { - return await new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7); - } - - class WhenAllPromise - { - const int MaxCount = 2; - - T1 result1; - T2 result2; - ExceptionDispatchInfo exception; - int completeCount; - Action whenComplete; + T1 t1 = default; + T2 t2 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2)> core; public WhenAllPromise(UniTask task1, UniTask task2) { - this.completeCount = 0; - this.whenComplete = null; - this.result1 = default(T1); - this.result2 = default(T2); - this.exception = null; + TaskTracker2.TrackActiveTask(this, 3); - RunTask1(task1); - RunTask2(task2); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } - - void RunTask1(UniTask task) - { - if (task.IsCompleted) - { - try + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) { - result1 = task.Result; + TryInvokeContinuationT1(this, awaiter); } - catch (Exception ex) + else { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask1Async(task).Forget(); - } - } - - async UniTaskVoid RunTask1Async(UniTask task) - { - try - { - result1 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask2(UniTask task) - { - if (task.IsCompleted) - { - try - { - result2 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask2Async(task).Forget(); - } - } - - async UniTaskVoid RunTask2Async(UniTask task) - { - try - { - result2 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAllPromise parent; - - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get - { - return parent.exception != null || parent.completeCount == MaxCount; - } - } - - public (T1, T2) GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return (parent.result1, parent.result2); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 2) + { + self.core.TrySetResult((self.t1, self.t2)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 2) + { + self.core.TrySetResult((self.t1, self.t2)); + } + } + + + public (T1, T2) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); } } - - class WhenAllPromise + + public static UniTask<(T1, T2, T3)> WhenAll(UniTask task1, UniTask task2, UniTask task3) { - const int MaxCount = 3; + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult())); + } - T1 result1; - T2 result2; - T3 result3; - ExceptionDispatchInfo exception; - int completeCount; - Action whenComplete; + return new UniTask<(T1, T2, T3)>(new WhenAllPromise(task1, task2, task3), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3)> core; public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3) { - this.completeCount = 0; - this.whenComplete = null; - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.exception = null; + TaskTracker2.TrackActiveTask(this, 3); - RunTask1(task1); - RunTask2(task2); - RunTask3(task3); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } - - void RunTask1(UniTask task) - { - if (task.IsCompleted) - { - try + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) { - result1 = task.Result; + TryInvokeContinuationT1(this, awaiter); } - catch (Exception ex) + else { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask1Async(task).Forget(); - } - } - - async UniTaskVoid RunTask1Async(UniTask task) - { - try - { - result1 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask2(UniTask task) - { - if (task.IsCompleted) - { - try - { - result2 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask2Async(task).Forget(); - } - } - - async UniTaskVoid RunTask2Async(UniTask task) - { - try - { - result2 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask3(UniTask task) - { - if (task.IsCompleted) - { - try - { - result3 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask3Async(task).Forget(); - } - } - - async UniTaskVoid RunTask3Async(UniTask task) - { - try - { - result3 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAllPromise parent; - - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get - { - return parent.exception != null || parent.completeCount == MaxCount; - } - } - - public (T1, T2, T3) GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return (parent.result1, parent.result2, parent.result3); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 3) + { + self.core.TrySetResult((self.t1, self.t2, self.t3)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 3) + { + self.core.TrySetResult((self.t1, self.t2, self.t3)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 3) + { + self.core.TrySetResult((self.t1, self.t2, self.t3)); + } + } + + + public (T1, T2, T3) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); } } - - class WhenAllPromise + + public static UniTask<(T1, T2, T3, T4)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - const int MaxCount = 4; + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult())); + } - T1 result1; - T2 result2; - T3 result3; - T4 result4; - ExceptionDispatchInfo exception; - int completeCount; - Action whenComplete; + return new UniTask<(T1, T2, T3, T4)>(new WhenAllPromise(task1, task2, task3, task4), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4)> core; public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - this.completeCount = 0; - this.whenComplete = null; - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); - this.exception = null; + TaskTracker2.TrackActiveTask(this, 3); - RunTask1(task1); - RunTask2(task2); - RunTask3(task3); - RunTask4(task4); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } - - void RunTask1(UniTask task) - { - if (task.IsCompleted) - { - try + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) { - result1 = task.Result; + TryInvokeContinuationT1(this, awaiter); } - catch (Exception ex) + else { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask1Async(task).Forget(); - } - } - - async UniTaskVoid RunTask1Async(UniTask task) - { - try - { - result1 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask2(UniTask task) - { - if (task.IsCompleted) - { - try - { - result2 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask2Async(task).Forget(); - } - } - - async UniTaskVoid RunTask2Async(UniTask task) - { - try - { - result2 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask3(UniTask task) - { - if (task.IsCompleted) - { - try - { - result3 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask3Async(task).Forget(); - } - } - - async UniTaskVoid RunTask3Async(UniTask task) - { - try - { - result3 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask4(UniTask task) - { - if (task.IsCompleted) - { - try - { - result4 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask4Async(task).Forget(); - } - } - - async UniTaskVoid RunTask4Async(UniTask task) - { - try - { - result4 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAllPromise parent; - - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get - { - return parent.exception != null || parent.completeCount == MaxCount; - } - } - - public (T1, T2, T3, T4) GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return (parent.result1, parent.result2, parent.result3, parent.result4); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 4) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 4) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 4) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 4) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4)); + } + } + + + public (T1, T2, T3, T4) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); } } - - class WhenAllPromise + + public static UniTask<(T1, T2, T3, T4, T5)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - const int MaxCount = 5; + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult())); + } - T1 result1; - T2 result2; - T3 result3; - T4 result4; - T5 result5; - ExceptionDispatchInfo exception; - int completeCount; - Action whenComplete; + return new UniTask<(T1, T2, T3, T4, T5)>(new WhenAllPromise(task1, task2, task3, task4, task5), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5)> core; public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - this.completeCount = 0; - this.whenComplete = null; - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); - this.result5 = default(T5); - this.exception = null; + TaskTracker2.TrackActiveTask(this, 3); - RunTask1(task1); - RunTask2(task2); - RunTask3(task3); - RunTask4(task4); - RunTask5(task5); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } - - void RunTask1(UniTask task) - { - if (task.IsCompleted) - { - try + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) { - result1 = task.Result; + TryInvokeContinuationT1(this, awaiter); } - catch (Exception ex) + else { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask1Async(task).Forget(); - } - } - - async UniTaskVoid RunTask1Async(UniTask task) - { - try - { - result1 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask2(UniTask task) - { - if (task.IsCompleted) - { - try - { - result2 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask2Async(task).Forget(); - } - } - - async UniTaskVoid RunTask2Async(UniTask task) - { - try - { - result2 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask3(UniTask task) - { - if (task.IsCompleted) - { - try - { - result3 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask3Async(task).Forget(); - } - } - - async UniTaskVoid RunTask3Async(UniTask task) - { - try - { - result3 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask4(UniTask task) - { - if (task.IsCompleted) - { - try - { - result4 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask4Async(task).Forget(); - } - } - - async UniTaskVoid RunTask4Async(UniTask task) - { - try - { - result4 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask5(UniTask task) - { - if (task.IsCompleted) - { - try - { - result5 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask5Async(task).Forget(); - } - } - - async UniTaskVoid RunTask5Async(UniTask task) - { - try - { - result5 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAllPromise parent; - - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get - { - return parent.exception != null || parent.completeCount == MaxCount; - } - } - - public (T1, T2, T3, T4, T5) GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return (parent.result1, parent.result2, parent.result3, parent.result4, parent.result5); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 5) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 5) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 5) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 5) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 5) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5)); + } + } + + + public (T1, T2, T3, T4, T5) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); } } - - class WhenAllPromise + + public static UniTask<(T1, T2, T3, T4, T5, T6)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - const int MaxCount = 6; + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult())); + } - T1 result1; - T2 result2; - T3 result3; - T4 result4; - T5 result5; - T6 result6; - ExceptionDispatchInfo exception; - int completeCount; - Action whenComplete; + return new UniTask<(T1, T2, T3, T4, T5, T6)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6)> core; public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - this.completeCount = 0; - this.whenComplete = null; - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); - this.result5 = default(T5); - this.result6 = default(T6); - this.exception = null; + TaskTracker2.TrackActiveTask(this, 3); - RunTask1(task1); - RunTask2(task2); - RunTask3(task3); - RunTask4(task4); - RunTask5(task5); - RunTask6(task6); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } - - void RunTask1(UniTask task) - { - if (task.IsCompleted) - { - try + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) { - result1 = task.Result; + TryInvokeContinuationT1(this, awaiter); } - catch (Exception ex) + else { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask1Async(task).Forget(); - } - } - - async UniTaskVoid RunTask1Async(UniTask task) - { - try - { - result1 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask2(UniTask task) - { - if (task.IsCompleted) - { - try - { - result2 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask2Async(task).Forget(); - } - } - - async UniTaskVoid RunTask2Async(UniTask task) - { - try - { - result2 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask3(UniTask task) - { - if (task.IsCompleted) - { - try - { - result3 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask3Async(task).Forget(); - } - } - - async UniTaskVoid RunTask3Async(UniTask task) - { - try - { - result3 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask4(UniTask task) - { - if (task.IsCompleted) - { - try - { - result4 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask4Async(task).Forget(); - } - } - - async UniTaskVoid RunTask4Async(UniTask task) - { - try - { - result4 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask5(UniTask task) - { - if (task.IsCompleted) - { - try - { - result5 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask5Async(task).Forget(); - } - } - - async UniTaskVoid RunTask5Async(UniTask task) - { - try - { - result5 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask6(UniTask task) - { - if (task.IsCompleted) - { - try - { - result6 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask6Async(task).Forget(); - } - } - - async UniTaskVoid RunTask6Async(UniTask task) - { - try - { - result6 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAllPromise parent; - - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get - { - return parent.exception != null || parent.completeCount == MaxCount; - } - } - - public (T1, T2, T3, T4, T5, T6) GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return (parent.result1, parent.result2, parent.result3, parent.result4, parent.result5, parent.result6); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 6) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 6) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 6) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 6) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 6) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 6) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6)); + } + } + + + public (T1, T2, T3, T4, T5, T6) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); } } - - class WhenAllPromise + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - const int MaxCount = 7; + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult())); + } - T1 result1; - T2 result2; - T3 result3; - T4 result4; - T5 result5; - T6 result6; - T7 result7; - ExceptionDispatchInfo exception; - int completeCount; - Action whenComplete; + return new UniTask<(T1, T2, T3, T4, T5, T6, T7)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7)> core; public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - this.completeCount = 0; - this.whenComplete = null; - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); - this.result5 = default(T5); - this.result6 = default(T6); - this.result7 = default(T7); - this.exception = null; + TaskTracker2.TrackActiveTask(this, 3); - RunTask1(task1); - RunTask2(task2); - RunTask3(task3); - RunTask4(task4); - RunTask5(task5); - RunTask6(task6); - RunTask7(task7); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } - - void RunTask1(UniTask task) - { - if (task.IsCompleted) - { - try + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) { - result1 = task.Result; + TryInvokeContinuationT1(this, awaiter); } - catch (Exception ex) + else { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask1Async(task).Forget(); - } - } - - async UniTaskVoid RunTask1Async(UniTask task) - { - try - { - result1 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask2(UniTask task) - { - if (task.IsCompleted) - { - try - { - result2 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask2Async(task).Forget(); - } - } - - async UniTaskVoid RunTask2Async(UniTask task) - { - try - { - result2 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask3(UniTask task) - { - if (task.IsCompleted) - { - try - { - result3 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask3Async(task).Forget(); - } - } - - async UniTaskVoid RunTask3Async(UniTask task) - { - try - { - result3 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask4(UniTask task) - { - if (task.IsCompleted) - { - try - { - result4 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask4Async(task).Forget(); - } - } - - async UniTaskVoid RunTask4Async(UniTask task) - { - try - { - result4 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask5(UniTask task) - { - if (task.IsCompleted) - { - try - { - result5 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask5Async(task).Forget(); - } - } - - async UniTaskVoid RunTask5Async(UniTask task) - { - try - { - result5 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask6(UniTask task) - { - if (task.IsCompleted) - { - try - { - result6 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask6Async(task).Forget(); - } - } - - async UniTaskVoid RunTask6Async(UniTask task) - { - try - { - result6 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - void RunTask7(UniTask task) - { - if (task.IsCompleted) - { - try - { - result7 = task.Result; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - else - { - RunTask7Async(task).Forget(); - } - } - - async UniTaskVoid RunTask7Async(UniTask task) - { - try - { - result7 = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == MaxCount) - { - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAllPromise parent; - - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get - { - return parent.exception != null || parent.completeCount == MaxCount; - } - } - - public (T1, T2, T3, T4, T5, T6, T7) GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return (parent.result1, parent.result2, parent.result3, parent.result4, parent.result5, parent.result6, parent.result7); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 7) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 7) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 7) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 7) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 7) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 7) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 7) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); } } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult())); + } + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 8) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully() && task9.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult(), task9.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + T9 t9 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + static void TryInvokeContinuationT9(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t9 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 9) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8, T9) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully() && task9.Status.IsCompletedSuccessfully() && task10.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult(), task9.GetAwaiter().GetResult(), task10.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + T9 t9 = default; + T10 t10 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT9(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t9 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + static void TryInvokeContinuationT10(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t10 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 10) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully() && task9.Status.IsCompletedSuccessfully() && task10.Status.IsCompletedSuccessfully() && task11.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult(), task9.GetAwaiter().GetResult(), task10.GetAwaiter().GetResult(), task11.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + T9 t9 = default; + T10 t10 = default; + T11 t11 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT9(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t9 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT10(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t10 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + static void TryInvokeContinuationT11(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t11 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 11) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully() && task9.Status.IsCompletedSuccessfully() && task10.Status.IsCompletedSuccessfully() && task11.Status.IsCompletedSuccessfully() && task12.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult(), task9.GetAwaiter().GetResult(), task10.GetAwaiter().GetResult(), task11.GetAwaiter().GetResult(), task12.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + T9 t9 = default; + T10 t10 = default; + T11 t11 = default; + T12 t12 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT9(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t9 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT10(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t10 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT11(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t11 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + static void TryInvokeContinuationT12(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t12 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 12) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully() && task9.Status.IsCompletedSuccessfully() && task10.Status.IsCompletedSuccessfully() && task11.Status.IsCompletedSuccessfully() && task12.Status.IsCompletedSuccessfully() && task13.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult(), task9.GetAwaiter().GetResult(), task10.GetAwaiter().GetResult(), task11.GetAwaiter().GetResult(), task12.GetAwaiter().GetResult(), task13.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + T9 t9 = default; + T10 t10 = default; + T11 t11 = default; + T12 t12 = default; + T13 t13 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task13.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT13(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT13(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT9(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t9 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT10(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t10 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT11(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t11 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT12(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t12 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + static void TryInvokeContinuationT13(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t13 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 13) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully() && task9.Status.IsCompletedSuccessfully() && task10.Status.IsCompletedSuccessfully() && task11.Status.IsCompletedSuccessfully() && task12.Status.IsCompletedSuccessfully() && task13.Status.IsCompletedSuccessfully() && task14.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult(), task9.GetAwaiter().GetResult(), task10.GetAwaiter().GetResult(), task11.GetAwaiter().GetResult(), task12.GetAwaiter().GetResult(), task13.GetAwaiter().GetResult(), task14.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + T9 t9 = default; + T10 t10 = default; + T11 t11 = default; + T12 t12 = default; + T13 t13 = default; + T14 t14 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task13.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT13(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT13(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task14.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT14(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT14(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT9(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t9 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT10(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t10 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT11(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t11 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT12(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t12 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT13(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t13 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + static void TryInvokeContinuationT14(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t14 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 14) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) + { + if (task1.Status.IsCompletedSuccessfully() && task2.Status.IsCompletedSuccessfully() && task3.Status.IsCompletedSuccessfully() && task4.Status.IsCompletedSuccessfully() && task5.Status.IsCompletedSuccessfully() && task6.Status.IsCompletedSuccessfully() && task7.Status.IsCompletedSuccessfully() && task8.Status.IsCompletedSuccessfully() && task9.Status.IsCompletedSuccessfully() && task10.Status.IsCompletedSuccessfully() && task11.Status.IsCompletedSuccessfully() && task12.Status.IsCompletedSuccessfully() && task13.Status.IsCompletedSuccessfully() && task14.Status.IsCompletedSuccessfully() && task15.Status.IsCompletedSuccessfully()) + { + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>((task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult(), task3.GetAwaiter().GetResult(), task4.GetAwaiter().GetResult(), task5.GetAwaiter().GetResult(), task6.GetAwaiter().GetResult(), task7.GetAwaiter().GetResult(), task8.GetAwaiter().GetResult(), task9.GetAwaiter().GetResult(), task10.GetAwaiter().GetResult(), task11.GetAwaiter().GetResult(), task12.GetAwaiter().GetResult(), task13.GetAwaiter().GetResult(), task14.GetAwaiter().GetResult(), task15.GetAwaiter().GetResult())); + } + + return new UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>(new WhenAllPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14, task15), 0); + } + + sealed class WhenAllPromise : IUniTaskSource<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)> + { + T1 t1 = default; + T2 t2 = default; + T3 t3 = default; + T4 t4 = default; + T5 t5 = default; + T6 t6 = default; + T7 t7 = default; + T8 t8 = default; + T9 t9 = default; + T10 t10 = default; + T11 t11 = default; + T12 t12 = default; + T13 t13 = default; + T14 t14 = default; + T15 t15 = default; + int completedCount; + UniTaskCompletionSourceCore<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)> core; + + public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task13.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT13(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT13(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task14.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT14(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT14(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task15.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT15(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT15(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t1 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT2(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t2 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT3(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t3 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT4(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t4 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT5(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t5 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT6(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t6 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT7(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t7 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT8(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t8 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT9(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t9 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT10(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t10 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT11(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t11 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT12(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t12 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT13(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t13 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT14(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t14 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + static void TryInvokeContinuationT15(WhenAllPromise self, in UniTask.Awaiter awaiter) + { + try + { + self.t15 = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 15) + { + self.core.TrySetResult((self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15)); + } + } + + + public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta deleted file mode 100644 index 40ed46c..0000000 --- a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5110117231c8a6d4095fd0cbd3f4c142 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTask.WhenAll.Generated.tt b/Assets/UniRx.Async/UniTask.WhenAll.Generated.tt new file mode 100644 index 0000000..5480dc0 --- /dev/null +++ b/Assets/UniRx.Async/UniTask.WhenAll.Generated.tt @@ -0,0 +1,127 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System; +using System.Runtime.CompilerServices; +using System.Runtime.ExceptionServices; +using System.Threading; +using UniRx.Async.Internal; + +namespace UniRx.Async +{ + public partial struct UniTask + { +<# for(var i = 2; i <= 15; i++ ) { + var range = Enumerable.Range(1, i); + var t = string.Join(", ", range.Select(x => "T" + x)); + var args = string.Join(", ", range.Select(x => $"UniTask task{x}")); + var targs = string.Join(", ", range.Select(x => $"task{x}")); + var tresult = string.Join(", ", range.Select(x => $"task{x}.GetAwaiter().GetResult()")); + var completedSuccessfullyAnd = string.Join(" && ", range.Select(x => $"task{x}.Status.IsCompletedSuccessfully()")); + var tfield = string.Join(", ", range.Select(x => $"self.t{x}")); +#> + + public static UniTask<(<#= t #>)> WhenAll<<#= t #>>(<#= args #>) + { + if (<#= completedSuccessfullyAnd #>) + { + return new UniTask<(<#= t #>)>((<#= tresult #>)); + } + + return new UniTask<(<#= t #>)>(new WhenAllPromise<<#= t #>>(<#= targs #>), 0); + } + + sealed class WhenAllPromise<<#= t #>> : IUniTaskSource<(<#= t #>)> + { +<# for(var j = 1; j <= i; j++) { #> + T<#= j #> t<#= j #> = default; +<# } #> + int completedCount; + UniTaskCompletionSourceCore<(<#= t #>)> core; + + public WhenAllPromise(<#= args #>) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; +<# for(var j = 1; j <= i; j++) { #> + { + var awaiter = task<#= j #>.GetAwaiter(); + if (awaiter.IsCompleted) + { + TryInvokeContinuationT<#= j #>(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple>, UniTask>.Awaiter>)state) + { + TryInvokeContinuationT<#= j #>(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } +<# } #> + } + +<# for(var j = 1; j <= i; j++) { #> + static void TryInvokeContinuationT<#= j #>(WhenAllPromise<<#= t #>> self, in UniTask>.Awaiter awaiter) + { + try + { + self.t<#= j #> = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == <#= i #>) + { + self.core.TrySetResult((<#= tfield #>)); + } + } + +<# } #> + + public (<#= t #>) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + ~WhenAllPromise() + { + core.Reset(); + } + } +<# } #> + } +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.WhenAll.cs b/Assets/UniRx.Async/UniTask.WhenAll.cs index 7b087d4..e9a83d7 100644 --- a/Assets/UniRx.Async/UniTask.WhenAll.cs +++ b/Assets/UniRx.Async/UniTask.WhenAll.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.ExceptionServices; using System.Threading; using UniRx.Async.Internal; @@ -12,285 +10,214 @@ namespace UniRx.Async { public partial struct UniTask { - // UniTask - - public static async UniTask WhenAll(params UniTask[] tasks) + public static UniTask WhenAll(params UniTask[] tasks) { - return await new WhenAllPromise(tasks, tasks.Length); + return new UniTask(new WhenAllPromise(tasks, tasks.Length), 0); } - public static async UniTask WhenAll(IEnumerable> tasks) + public static UniTask WhenAll(IEnumerable> tasks) { - WhenAllPromise promise; using (var span = ArrayPoolUtil.Materialize(tasks)) { - promise = new WhenAllPromise(span.Array, span.Length); + var promise = new WhenAllPromise(span.Array, span.Length); // consumed array in constructor. + return new UniTask(promise, 0); } - - return await promise; } - public static async UniTask WhenAll(params UniTask[] tasks) + public static UniTask WhenAll(params UniTask[] tasks) { - await new WhenAllPromise(tasks, tasks.Length); + return new UniTask(new WhenAllPromise(tasks, tasks.Length), 0); } - public static async UniTask WhenAll(IEnumerable tasks) + public static UniTask WhenAll(IEnumerable tasks) { - WhenAllPromise promise; using (var span = ArrayPoolUtil.Materialize(tasks)) { - promise = new WhenAllPromise(span.Array, span.Length); + var promise = new WhenAllPromise(span.Array, span.Length); // consumed array in constructor. + return new UniTask(promise, 0); } - - await promise; } - class WhenAllPromise + sealed class WhenAllPromise : IUniTaskSource { - readonly T[] result; + T[] result; int completeCount; - Action whenComplete; - ExceptionDispatchInfo exception; + UniTaskCompletionSourceCore core; // don't reset(called after GetResult, will invoke TrySetException.) public WhenAllPromise(UniTask[] tasks, int tasksLength) { + TaskTracker2.TrackActiveTask(this, 3); + this.completeCount = 0; - this.whenComplete = null; - this.exception = null; this.result = new T[tasksLength]; for (int i = 0; i < tasksLength; i++) { - if (tasks[i].Status.IsCompleted()) + UniTask.Awaiter awaiter; + try { - T value = default(T); - try - { - value = tasks[i].GetAwaiter().GetResult(); - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - continue; - } + awaiter = tasks[i].GetAwaiter(); + } + catch (Exception ex) + { + core.TrySetException(ex); + continue; + } - result[i] = value; - var count = Interlocked.Increment(ref completeCount); - if (count == result.Length) - { - TryCallContinuation(); - } + if (awaiter.IsCompleted) + { + TryInvokeContinuation(this, awaiter, i); } else { - RunTask(tasks[i], i).Forget(); + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter, int>)state) + { + TryInvokeContinuation(t.Item1, t.Item2, t.Item3); + } + }, StateTuple.Create(this, awaiter, i)); } } } - void TryCallContinuation() + static void TryInvokeContinuation(WhenAllPromise self, in UniTask.Awaiter awaiter, int i) { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } - } - - async UniTaskVoid RunTask(UniTask task, int index) - { - T value = default(T); try { - value = await task; + self.result[i] = awaiter.GetResult(); } catch (Exception ex) { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); + self.core.TrySetException(ex); return; } - result[index] = value; - var count = Interlocked.Increment(ref completeCount); - if (count == result.Length) + if (Interlocked.Increment(ref self.completeCount) == self.result.Length) { - TryCallContinuation(); + self.core.TrySetResult(self.result); } } - public Awaiter GetAwaiter() + public T[] GetResult(short token) { - return new Awaiter(this); + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); } - public struct Awaiter : ICriticalNotifyCompletion + void IUniTaskSource.GetResult(short token) { - WhenAllPromise parent; + GetResult(token); + } - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } - public bool IsCompleted - { - get - { - return parent.exception != null || parent.result.Length == parent.completeCount; - } - } + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } - public T[] GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } - return parent.result; - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) - { - action(); - } - } - } + ~WhenAllPromise() + { + core.Reset(); } } - class WhenAllPromise + sealed class WhenAllPromise : IUniTaskSource { int completeCount; - int resultLength; - Action whenComplete; - ExceptionDispatchInfo exception; + int tasksLength; + UniTaskCompletionSourceCore core; // don't reset(called after GetResult, will invoke TrySetException.) public WhenAllPromise(UniTask[] tasks, int tasksLength) { + TaskTracker2.TrackActiveTask(this, 3); + + this.tasksLength = tasksLength; this.completeCount = 0; - this.whenComplete = null; - this.exception = null; - this.resultLength = tasksLength; for (int i = 0; i < tasksLength; i++) { - if (tasks[i].Status.IsCompleted()) + UniTask.Awaiter awaiter; + try { - try - { - tasks[i].GetAwaiter().GetResult(); - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - continue; - } + awaiter = tasks[i].GetAwaiter(); + } + catch (Exception ex) + { + core.TrySetException(ex); + continue; + } - var count = Interlocked.Increment(ref completeCount); - if (count == resultLength) - { - TryCallContinuation(); - } + if (awaiter.IsCompleted) + { + TryInvokeContinuation(this, awaiter); } else { - RunTask(tasks[i], i).Forget(); + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple)state) + { + TryInvokeContinuation(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } } - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } - } - - async UniTaskVoid RunTask(UniTask task, int index) + static void TryInvokeContinuation(WhenAllPromise self, in UniTask.Awaiter awaiter) { try { - await task; + awaiter.GetResult(); } catch (Exception ex) { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); + self.core.TrySetException(ex); return; } - var count = Interlocked.Increment(ref completeCount); - if (count == resultLength) + if (Interlocked.Increment(ref self.completeCount) == self.tasksLength) { - TryCallContinuation(); + self.core.TrySetResult(AsyncUnit.Default); } } - public Awaiter GetAwaiter() + public void GetResult(short token) { - return new Awaiter(this); + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + core.GetResult(token); } - public struct Awaiter : ICriticalNotifyCompletion + public UniTaskStatus GetStatus(short token) { - WhenAllPromise parent; + return core.GetStatus(token); + } - public Awaiter(WhenAllPromise parent) - { - this.parent = parent; - } + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } - public bool IsCompleted - { - get - { - return parent.exception != null || parent.resultLength == parent.completeCount; - } - } + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } - public void GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) - { - action(); - } - } - } + ~WhenAllPromise() + { + core.Reset(); } } } diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs index ebc0fe2..0773525 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs @@ -1,1527 +1,5130 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Threading; +using UniRx.Async.Internal; namespace UniRx.Async { public partial struct UniTask { - public static async UniTask<(int winArgumentIndex, (bool hasResult, T0 result0), (bool hasResult, T1 result1))> WhenAny(UniTask task0, UniTask task1) + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> WhenAny(UniTask task1, UniTask task2) { - return await new WhenAnyPromise(task0, task1); + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2))>(new WhenAnyPromise(task1, task2), 0); } - public static async UniTask<(int winArgumentIndex, (bool hasResult, T0 result0), (bool hasResult, T1 result1), (bool hasResult, T2 result2))> WhenAny(UniTask task0, UniTask task1, UniTask task2) + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> { - return await new WhenAnyPromise(task0, task1, task2); - } + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> core; - public static async UniTask<(int winArgumentIndex, (bool hasResult, T0 result0), (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> WhenAny(UniTask task0, UniTask task1, UniTask task2, UniTask task3) - { - return await new WhenAnyPromise(task0, task1, task2, task3); - } - - public static async UniTask<(int winArgumentIndex, (bool hasResult, T0 result0), (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> WhenAny(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4) - { - return await new WhenAnyPromise(task0, task1, task2, task3, task4); - } - - public static async UniTask<(int winArgumentIndex, (bool hasResult, T0 result0), (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> WhenAny(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) - { - return await new WhenAnyPromise(task0, task1, task2, task3, task4, task5); - } - - public static async UniTask<(int winArgumentIndex, (bool hasResult, T0 result0), (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> WhenAny(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) - { - return await new WhenAnyPromise(task0, task1, task2, task3, task4, task5, task6); - } - - public static async UniTask<(int winArgumentIndex, (bool hasResult, T0 result0), (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> WhenAny(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) - { - return await new WhenAnyPromise(task0, task1, task2, task3, task4, task5, task6, task7); - } - - class WhenAnyPromise - { - T0 result0; - T1 result1; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; - int winArgumentIndex; - - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; - - public WhenAnyPromise(UniTask task0, UniTask task1) + public WhenAnyPromise(UniTask task1, UniTask task2) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); - this.result1 = default(T1); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } + var awaiter = task1.GetAwaiter(); - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - T1 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result1 = value; - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAnyPromise parent; - - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + if (awaiter.IsCompleted) { - return parent.IsCompleted; + TryInvokeContinuationT1(this, awaiter); } - } - - public (int, (bool, T0), (bool, T1)) GetResult() - { - if (parent.exception != null) + else { - parent.exception.Throw(); - } - - var i = parent.winArgumentIndex; - return (i, (i == 0, parent.result0), (i == 1, parent.result1)); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); } } - class WhenAnyPromise + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> WhenAny(UniTask task1, UniTask task2, UniTask task3) { - T0 result0; - T1 result1; - T2 result2; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; - int winArgumentIndex; + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))>(new WhenAnyPromise(task1, task2, task3), 0); + } - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> core; - public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2) + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); - this.result1 = default(T1); - this.result2 = default(T2); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - RunTask2(task2).Forget(); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) + this.completedCount = 0; { - action.Invoke(); - } - } + var awaiter = task1.GetAwaiter(); - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - T1 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result1 = value; - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask2(UniTask task) - { - T2 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result2 = value; - Volatile.Write(ref winArgumentIndex, 2); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAnyPromise parent; - - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + if (awaiter.IsCompleted) { - return parent.IsCompleted; + TryInvokeContinuationT1(this, awaiter); } - } - - public (int, (bool, T0), (bool, T1), (bool, T2)) GetResult() - { - if (parent.exception != null) + else { - parent.exception.Throw(); - } - - var i = parent.winArgumentIndex; - return (i, (i == 0, parent.result0), (i == 1, parent.result1), (i == 2, parent.result2)); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); } } - class WhenAnyPromise + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - T0 result0; - T1 result1; - T2 result2; - T3 result3; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; - int winArgumentIndex; + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))>(new WhenAnyPromise(task1, task2, task3, task4), 0); + } - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> core; - public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3) + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - RunTask2(task2).Forget(); - RunTask3(task3).Forget(); - } + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } - } - - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - T1 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result1 = value; - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask2(UniTask task) - { - T2 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result2 = value; - Volatile.Write(ref winArgumentIndex, 2); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask3(UniTask task) - { - T3 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result3 = value; - Volatile.Write(ref winArgumentIndex, 3); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAnyPromise parent; - - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + if (awaiter.IsCompleted) { - return parent.IsCompleted; + TryInvokeContinuationT1(this, awaiter); } - } - - public (int, (bool, T0), (bool, T1), (bool, T2), (bool, T3)) GetResult() - { - if (parent.exception != null) + else { - parent.exception.Throw(); - } - - var i = parent.winArgumentIndex; - return (i, (i == 0, parent.result0), (i == 1, parent.result1), (i == 2, parent.result2), (i == 3, parent.result3)); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); } } - class WhenAnyPromise + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - T0 result0; - T1 result1; - T2 result2; - T3 result3; - T4 result4; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; - int winArgumentIndex; + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))>(new WhenAnyPromise(task1, task2, task3, task4, task5), 0); + } - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> core; - public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4) + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - RunTask2(task2).Forget(); - RunTask3(task3).Forget(); - RunTask4(task4).Forget(); - } + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } - } - - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - T1 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result1 = value; - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask2(UniTask task) - { - T2 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result2 = value; - Volatile.Write(ref winArgumentIndex, 2); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask3(UniTask task) - { - T3 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result3 = value; - Volatile.Write(ref winArgumentIndex, 3); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask4(UniTask task) - { - T4 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result4 = value; - Volatile.Write(ref winArgumentIndex, 4); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAnyPromise parent; - - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + if (awaiter.IsCompleted) { - return parent.IsCompleted; + TryInvokeContinuationT1(this, awaiter); } - } - - public (int, (bool, T0), (bool, T1), (bool, T2), (bool, T3), (bool, T4)) GetResult() - { - if (parent.exception != null) + else { - parent.exception.Throw(); - } - - var i = parent.winArgumentIndex; - return (i, (i == 0, parent.result0), (i == 1, parent.result1), (i == 2, parent.result2), (i == 3, parent.result3), (i == 4, parent.result4)); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); } } - class WhenAnyPromise + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - T0 result0; - T1 result1; - T2 result2; - T3 result3; - T4 result4; - T5 result5; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; - int winArgumentIndex; + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6), 0); + } - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> core; - public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); - this.result5 = default(T5); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - RunTask2(task2).Forget(); - RunTask3(task3).Forget(); - RunTask4(task4).Forget(); - RunTask5(task5).Forget(); - } + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } - } - - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - T1 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result1 = value; - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask2(UniTask task) - { - T2 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result2 = value; - Volatile.Write(ref winArgumentIndex, 2); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask3(UniTask task) - { - T3 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result3 = value; - Volatile.Write(ref winArgumentIndex, 3); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask4(UniTask task) - { - T4 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result4 = value; - Volatile.Write(ref winArgumentIndex, 4); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask5(UniTask task) - { - T5 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result5 = value; - Volatile.Write(ref winArgumentIndex, 5); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAnyPromise parent; - - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + if (awaiter.IsCompleted) { - return parent.IsCompleted; + TryInvokeContinuationT1(this, awaiter); } - } - - public (int, (bool, T0), (bool, T1), (bool, T2), (bool, T3), (bool, T4), (bool, T5)) GetResult() - { - if (parent.exception != null) + else { - parent.exception.Throw(); - } - - var i = parent.winArgumentIndex; - return (i, (i == 0, parent.result0), (i == 1, parent.result1), (i == 2, parent.result2), (i == 3, parent.result3), (i == 4, parent.result4), (i == 5, parent.result5)); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); } } - class WhenAnyPromise + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - T0 result0; - T1 result1; - T2 result2; - T3 result3; - T4 result4; - T5 result5; - T6 result6; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; - int winArgumentIndex; + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7), 0); + } - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> core; - public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); - this.result5 = default(T5); - this.result6 = default(T6); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - RunTask2(task2).Forget(); - RunTask3(task3).Forget(); - RunTask4(task4).Forget(); - RunTask5(task5).Forget(); - RunTask6(task6).Forget(); - } + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } - } - - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - T1 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result1 = value; - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask2(UniTask task) - { - T2 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result2 = value; - Volatile.Write(ref winArgumentIndex, 2); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask3(UniTask task) - { - T3 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result3 = value; - Volatile.Write(ref winArgumentIndex, 3); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask4(UniTask task) - { - T4 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result4 = value; - Volatile.Write(ref winArgumentIndex, 4); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask5(UniTask task) - { - T5 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result5 = value; - Volatile.Write(ref winArgumentIndex, 5); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask6(UniTask task) - { - T6 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result6 = value; - Volatile.Write(ref winArgumentIndex, 6); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAnyPromise parent; - - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + if (awaiter.IsCompleted) { - return parent.IsCompleted; + TryInvokeContinuationT1(this, awaiter); } - } - - public (int, (bool, T0), (bool, T1), (bool, T2), (bool, T3), (bool, T4), (bool, T5), (bool, T6)) GetResult() - { - if (parent.exception != null) + else { - parent.exception.Throw(); - } - - var i = parent.winArgumentIndex; - return (i, (i == 0, parent.result0), (i == 1, parent.result1), (i == 2, parent.result2), (i == 3, parent.result3), (i == 4, parent.result4), (i == 5, parent.result5), (i == 6, parent.result6)); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); } } - class WhenAnyPromise + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { - T0 result0; - T1 result1; - T2 result2; - T3 result3; - T4 result4; - T5 result5; - T6 result6; - T7 result7; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; - int winArgumentIndex; + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8), 0); + } - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> core; - public WhenAnyPromise(UniTask task0, UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); - this.result1 = default(T1); - this.result2 = default(T2); - this.result3 = default(T3); - this.result4 = default(T4); - this.result5 = default(T5); - this.result6 = default(T6); - this.result7 = default(T7); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - RunTask2(task2).Forget(); - RunTask3(task3).Forget(); - RunTask4(task4).Forget(); - RunTask5(task5).Forget(); - RunTask6(task6).Forget(); - RunTask7(task7).Forget(); - } + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } - } - - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - T1 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result1 = value; - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask2(UniTask task) - { - T2 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result2 = value; - Volatile.Write(ref winArgumentIndex, 2); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask3(UniTask task) - { - T3 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result3 = value; - Volatile.Write(ref winArgumentIndex, 3); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask4(UniTask task) - { - T4 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result4 = value; - Volatile.Write(ref winArgumentIndex, 4); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask5(UniTask task) - { - T5 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result5 = value; - Volatile.Write(ref winArgumentIndex, 5); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask6(UniTask task) - { - T6 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result6 = value; - Volatile.Write(ref winArgumentIndex, 6); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask7(UniTask task) - { - T7 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result7 = value; - Volatile.Write(ref winArgumentIndex, 7); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - WhenAnyPromise parent; - - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + if (awaiter.IsCompleted) { - return parent.IsCompleted; + TryInvokeContinuationT1(this, awaiter); } - } - - public (int, (bool, T0), (bool, T1), (bool, T2), (bool, T3), (bool, T4), (bool, T5), (bool, T6), (bool, T7)) GetResult() - { - if (parent.exception != null) + else { - parent.exception.Throw(); - } - - var i = parent.winArgumentIndex; - return (i, (i == 0, parent.result0), (i == 1, parent.result1), (i == 2, parent.result2), (i == 3, parent.result3), (i == 4, parent.result4), (i == 5, parent.result5), (i == 6, parent.result6), (i == 7, parent.result7)); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) + { + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9), 0); + } + + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> core; + + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T9 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) + { + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10), 0); + } + + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> core; + + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T9 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T10 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) + { + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11), 0); + } + + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> core; + + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T9 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T10 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T11 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) + { + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12), 0); + } + + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> core; + + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T9 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T10 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T11 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T12 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) + { + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13), 0); + } + + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> core; + + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task13.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT13(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT13(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T9 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T10 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T11 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T12 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT13(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T13 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) + { + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14), 0); + } + + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> core; + + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task13.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT13(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT13(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task14.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT14(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT14(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T9 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T10 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T11 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T12 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT13(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T13 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT14(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T14 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((13, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + + public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) + { + return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14, task15), 0); + } + + sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> + { + int completedCount; + UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> core; + + public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; + { + var awaiter = task1.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT1(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT1(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task2.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT2(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT2(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task3.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT3(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT3(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task4.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT4(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT4(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task5.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT5(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT5(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task6.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT6(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT6(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task7.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT7(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT7(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task8.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT8(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT8(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task9.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT9(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT9(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task10.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT10(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT10(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task11.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT11(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT11(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task12.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT12(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT12(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task13.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT13(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT13(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task14.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT14(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT14(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + { + var awaiter = task15.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT15(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryInvokeContinuationT15(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T1 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T2 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T3 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T4 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T5 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T6 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T7 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T8 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T9 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T10 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T11 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T12 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT13(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T13 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + } + } + + static void TryInvokeContinuationT14(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T14 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((13, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + } + } + + static void TryInvokeContinuationT15(WhenAnyPromise self, in UniTask.Awaiter awaiter) + { + T15 result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((14, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + } + } + + + public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15)) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta deleted file mode 100644 index 49a2c3f..0000000 --- a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 13d604ac281570c4eac9962429f19ca9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt b/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt new file mode 100644 index 0000000..3d50260 --- /dev/null +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt @@ -0,0 +1,122 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System; +using System.Runtime.CompilerServices; +using System.Runtime.ExceptionServices; +using System.Threading; +using UniRx.Async.Internal; + +namespace UniRx.Async +{ + public partial struct UniTask + { +<# for(var i = 2; i <= 15; i++ ) { + var range = Enumerable.Range(1, i); + var t = string.Join(", ", range.Select(x => "T" + x)); + var args = string.Join(", ", range.Select(x => $"UniTask task{x}")); + var targs = string.Join(", ", range.Select(x => $"task{x}")); + var tresult = string.Join(", ", range.Select(x => $"task{x}.GetAwaiter().GetResult()")); + var tBool = string.Join(", ", range.Select(x => $"(bool hasResult, T{x} result{x})")); + var tfield = string.Join(", ", range.Select(x => $"self.t{x}")); + Func getResult = j => string.Join(", ", range.Select(x => (x == j) ? "(true, result)" : "(false, default)")); +#> + public static UniTask<(int winArgumentIndex, <#= tBool #>)> WhenAny<<#= t #>>(<#= args #>) + { + return new UniTask<(int winArgumentIndex, <#= tBool #>)>(new WhenAnyPromise<<#= t #>>(<#= targs #>), 0); + } + + sealed class WhenAnyPromise<<#= t #>> : IUniTaskSource<(int, <#= tBool #>)> + { + int completedCount; + UniTaskCompletionSourceCore<(int, <#= tBool #>)> core; + + public WhenAnyPromise(<#= args #>) + { + TaskTracker2.TrackActiveTask(this, 3); + + this.completedCount = 0; +<# for(var j = 1; j <= i; j++) { #> + { + var awaiter = task<#= j #>.GetAwaiter(); + + if (awaiter.IsCompleted) + { + TryInvokeContinuationT<#= j #>(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple>, UniTask>.Awaiter>)state) + { + TryInvokeContinuationT<#= j #>(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } +<# } #> + } + +<# for(var j = 1; j <= i; j++) { #> + static void TryInvokeContinuationT<#= j #>(WhenAnyPromise<<#= t #>> self, in UniTask>.Awaiter awaiter) + { + T<#= j #> result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((<#= j - 1 #>, <#= getResult(j) #>)); + } + } + +<# } #> + + public (int, <#= tBool #>) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyPromise() + { + core.Reset(); + } + } + +<# } #> + } +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.WhenAny.cs b/Assets/UniRx.Async/UniTask.WhenAny.cs index 2c5049b..3bfe25c 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.cs +++ b/Assets/UniRx.Async/UniTask.WhenAny.cs @@ -2,370 +2,365 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; -using System.Runtime.CompilerServices; -using System.Runtime.ExceptionServices; +using System.Collections.Generic; using System.Threading; +using UniRx.Async.Internal; namespace UniRx.Async { public partial struct UniTask { - // UniTask - - public static async UniTask<(bool hasResultLeft, T0 result)> WhenAny(UniTask task0, UniTask task1) + public static UniTask<(bool hasResultLeft, T result)> WhenAny(UniTask leftTask, UniTask rightTask) { - return await new UnitWhenAnyPromise(task0, task1); + return new UniTask<(bool, T)>(new WhenAnyLRPromise(leftTask, rightTask), 0); } - public static async UniTask<(int winArgumentIndex, T result)> WhenAny(params UniTask[] tasks) + public static UniTask<(int winArgumentIndex, T result)> WhenAny(params UniTask[] tasks) { - return await new WhenAnyPromise(tasks); + return new UniTask<(int, T)>(new WhenAnyPromise(tasks, tasks.Length), 0); + } + + public static UniTask<(int winArgumentIndex, T result)> WhenAny(IEnumerable> tasks) + { + using (var span = ArrayPoolUtil.Materialize(tasks)) + { + return new UniTask<(int, T)>(new WhenAnyPromise(span.Array, span.Length), 0); + } } /// Return value is winArgumentIndex - public static async UniTask WhenAny(params UniTask[] tasks) + public static UniTask WhenAny(params UniTask[] tasks) { - return await new WhenAnyPromise(tasks); + return new UniTask(new WhenAnyPromise(tasks, tasks.Length), 0); } - class UnitWhenAnyPromise + /// Return value is winArgumentIndex + public static UniTask WhenAny(IEnumerable tasks) { - T0 result0; - ExceptionDispatchInfo exception; - Action whenComplete; - int completeCount; + using (var span = ArrayPoolUtil.Materialize(tasks)) + { + return new UniTask(new WhenAnyPromise(span.Array, span.Length), 0); + } + } + + sealed class WhenAnyLRPromise : IUniTaskSource<(bool, T)> + { + int completedCount; int winArgumentIndex; + UniTaskCompletionSourceCore<(bool, T)> core; - bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1; - - public UnitWhenAnyPromise(UniTask task0, UniTask task1) + public WhenAnyLRPromise(UniTask leftTask, UniTask rightTask) { - this.whenComplete = null; - this.exception = null; - this.completeCount = 0; - this.winArgumentIndex = -1; - this.result0 = default(T0); + TaskTracker2.TrackActiveTask(this, 3); - RunTask0(task0).Forget(); - RunTask1(task1).Forget(); - } - - void TryCallContinuation() - { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) { - action.Invoke(); - } - } - - async UniTaskVoid RunTask0(UniTask task) - { - T0 value; - try - { - value = await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - result0 = value; - Volatile.Write(ref winArgumentIndex, 0); - TryCallContinuation(); - } - } - - async UniTaskVoid RunTask1(UniTask task) - { - try - { - await task; - } - catch (Exception ex) - { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); - return; - } - - var count = Interlocked.Increment(ref completeCount); - if (count == 1) - { - Volatile.Write(ref winArgumentIndex, 1); - TryCallContinuation(); - } - } - - - public Awaiter GetAwaiter() - { - return new Awaiter(this); - } - - public struct Awaiter : ICriticalNotifyCompletion - { - UnitWhenAnyPromise parent; - - public Awaiter(UnitWhenAnyPromise parent) - { - this.parent = parent; - } - - public bool IsCompleted - { - get + UniTask.Awaiter awaiter; + try { - return parent.IsCompleted; + awaiter = leftTask.GetAwaiter(); } - } - - public (bool, T0) GetResult() - { - if (parent.exception != null) + catch (Exception ex) { - parent.exception.Throw(); + core.TrySetException(ex); + goto RIGHT; } - return (parent.winArgumentIndex == 0, parent.result0); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) + if (awaiter.IsCompleted) { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) + TryLeftInvokeContinuation(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => { - action(); - } + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryLeftInvokeContinuation(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); } } + RIGHT: + { + UniTask.Awaiter awaiter; + try + { + awaiter = rightTask.GetAwaiter(); + } + catch (Exception ex) + { + core.TrySetException(ex); + return; + } + + if (awaiter.IsCompleted) + { + TryRightInvokeContinuation(this, awaiter); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter>)state) + { + TryRightInvokeContinuation(t.Item1, t.Item2); + } + }, StateTuple.Create(this, awaiter)); + } + } + } + + static void TryLeftInvokeContinuation(WhenAnyLRPromise self, in UniTask.Awaiter awaiter) + { + T result; + try + { + result = awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((true, result)); + } + } + + static void TryRightInvokeContinuation(WhenAnyLRPromise self, in UniTask.Awaiter awaiter) + { + try + { + awaiter.GetResult(); + } + catch (Exception ex) + { + self.core.TrySetException(ex); + return; + } + + if (Interlocked.Increment(ref self.completedCount) == 1) + { + self.core.TrySetResult((false, default)); + } + } + + public (bool, T) GetResult(short token) + { + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + ~WhenAnyLRPromise() + { + core.Reset(); } } - class WhenAnyPromise + sealed class WhenAnyPromise : IUniTaskSource<(int, T)> { - T result; - int completeCount; + int completedCount; int winArgumentIndex; - Action whenComplete; - ExceptionDispatchInfo exception; + UniTaskCompletionSourceCore<(int, T)> core; - public bool IsComplete => exception != null || Volatile.Read(ref winArgumentIndex) != -1; - - public WhenAnyPromise(UniTask[] tasks) + public WhenAnyPromise(UniTask[] tasks, int tasksLength) { - this.completeCount = 0; - this.winArgumentIndex = -1; - this.whenComplete = null; - this.exception = null; - this.result = default(T); + TaskTracker2.TrackActiveTask(this, 3); - for (int i = 0; i < tasks.Length; i++) + for (int i = 0; i < tasksLength; i++) { - RunTask(tasks[i], i).Forget(); + UniTask.Awaiter awaiter; + try + { + awaiter = tasks[i].GetAwaiter(); + } + catch (Exception ex) + { + core.TrySetException(ex); + continue; // consume others. + } + + if (awaiter.IsCompleted) + { + TryInvokeContinuation(this, awaiter, i); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple, UniTask.Awaiter, int>)state) + { + TryInvokeContinuation(t.Item1, t.Item2, t.Item3); + } + }, StateTuple.Create(this, awaiter, i)); + } } } - async UniTaskVoid RunTask(UniTask task, int index) + static void TryInvokeContinuation(WhenAnyPromise self, in UniTask.Awaiter awaiter, int i) { - T value; + T result; try { - value = await task; + result = awaiter.GetResult(); } catch (Exception ex) { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); + self.core.TrySetException(ex); return; } - var count = Interlocked.Increment(ref completeCount); - if (count == 1) + if (Interlocked.Increment(ref self.completedCount) == 1) { - result = value; - Volatile.Write(ref winArgumentIndex, index); - TryCallContinuation(); + self.core.TrySetResult((i, result)); } } - void TryCallContinuation() + public (int, T) GetResult(short token) { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); } - public Awaiter GetAwaiter() + public UniTaskStatus GetStatus(short token) { - return new Awaiter(this); + return core.GetStatus(token); } - public struct Awaiter : ICriticalNotifyCompletion + public void OnCompleted(Action continuation, object state, short token) { - WhenAnyPromise parent; + core.OnCompleted(continuation, state, token); + } - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } - public bool IsCompleted - { - get - { - return parent.IsComplete; - } - } + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } - public (int, T) GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return (parent.winArgumentIndex, parent.result); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) - { - action(); - } - } - } + ~WhenAnyPromise() + { + core.Reset(); } } - class WhenAnyPromise + sealed class WhenAnyPromise : IUniTaskSource { - int completeCount; + int completedCount; int winArgumentIndex; - Action whenComplete; - ExceptionDispatchInfo exception; + UniTaskCompletionSourceCore core; - public bool IsComplete => exception != null || Volatile.Read(ref winArgumentIndex) != -1; - - public WhenAnyPromise(UniTask[] tasks) + public WhenAnyPromise(UniTask[] tasks, int tasksLength) { - this.completeCount = 0; - this.winArgumentIndex = -1; - this.whenComplete = null; - this.exception = null; + TaskTracker2.TrackActiveTask(this, 3); - for (int i = 0; i < tasks.Length; i++) + for (int i = 0; i < tasksLength; i++) { - RunTask(tasks[i], i).Forget(); + UniTask.Awaiter awaiter; + try + { + awaiter = tasks[i].GetAwaiter(); + } + catch (Exception ex) + { + core.TrySetException(ex); + continue; // consume others. + } + + if (awaiter.IsCompleted) + { + TryInvokeContinuation(this, awaiter, i); + } + else + { + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple)state) + { + TryInvokeContinuation(t.Item1, t.Item2, t.Item3); + } + }, StateTuple.Create(this, awaiter, i)); + } } } - async UniTaskVoid RunTask(UniTask task, int index) + static void TryInvokeContinuation(WhenAnyPromise self, in UniTask.Awaiter awaiter, int i) { try { - await task; + awaiter.GetResult(); } catch (Exception ex) { - exception = ExceptionDispatchInfo.Capture(ex); - TryCallContinuation(); + self.core.TrySetException(ex); return; } - var count = Interlocked.Increment(ref completeCount); - if (count == 1) + if (Interlocked.Increment(ref self.completedCount) == 1) { - Volatile.Write(ref winArgumentIndex, index); - TryCallContinuation(); + self.core.TrySetResult(i); } } - void TryCallContinuation() + public int GetResult(short token) { - var action = Interlocked.Exchange(ref whenComplete, null); - if (action != null) - { - action.Invoke(); - } + TaskTracker2.RemoveTracking(this); + GC.SuppressFinalize(this); + return core.GetResult(token); } - public Awaiter GetAwaiter() + public UniTaskStatus GetStatus(short token) { - return new Awaiter(this); + return core.GetStatus(token); } - public struct Awaiter : ICriticalNotifyCompletion + public void OnCompleted(Action continuation, object state, short token) { - WhenAnyPromise parent; + core.OnCompleted(continuation, state, token); + } - public Awaiter(WhenAnyPromise parent) - { - this.parent = parent; - } + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } - public bool IsCompleted - { - get - { - return parent.IsComplete; - } - } + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } - public int GetResult() - { - if (parent.exception != null) - { - parent.exception.Throw(); - } - - return parent.winArgumentIndex; - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - parent.whenComplete = continuation; - if (IsCompleted) - { - var action = Interlocked.Exchange(ref parent.whenComplete, null); - if (action != null) - { - action(); - } - } - } + ~WhenAnyPromise() + { + core.Reset(); } } } diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index 0ef9906..89d700d 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -47,9 +47,8 @@ namespace UniRx.Async TResult result; object error; // ExceptionDispatchInfo or OperationCanceledException short version; - bool completed; bool hasUnhandledError; - + int completedCount; // 0: completed == false Action continuation; object continuationState; @@ -61,7 +60,7 @@ namespace UniRx.Async { version += 1; // incr version. } - completed = false; + completedCount = 0; result = default; error = null; hasUnhandledError = false; @@ -92,25 +91,59 @@ namespace UniRx.Async /// Completes with a successful result. /// The result. - public void SetResult(TResult result) + public bool TrySetResult(TResult result) { - this.result = result; - SignalCompletion(); + if (Interlocked.Increment(ref completedCount) == 1) + { + // setup result + this.result = result; + + if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) + { + continuation(continuationState); + return true; + } + } + + return false; } /// Completes with an error. /// The exception. - public void SetException(Exception error) + public bool TrySetException(Exception error) { - this.hasUnhandledError = true; - this.error = ExceptionDispatchInfo.Capture(error); - SignalCompletion(); + if (Interlocked.Increment(ref completedCount) == 1) + { + // setup result + this.hasUnhandledError = true; + this.error = ExceptionDispatchInfo.Capture(error); + + if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) + { + continuation(continuationState); + return true; + } + } + + return false; } - public void SetCanceled(CancellationToken cancellationToken = default) + public bool TrySetCanceled(CancellationToken cancellationToken = default) { - this.error = new OperationCanceledException(cancellationToken); - SignalCompletion(); + if (Interlocked.Increment(ref completedCount) == 1) + { + // setup result + this.hasUnhandledError = true; + this.error = new OperationCanceledException(cancellationToken); + + if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) + { + continuation(continuationState); + return true; + } + } + + return false; } /// Gets the operation version. @@ -122,7 +155,7 @@ namespace UniRx.Async public UniTaskStatus GetStatus(short token) { ValidateToken(token); - return (continuation == null || !completed) ? UniTaskStatus.Pending + return (continuation == null || (completedCount == 0)) ? UniTaskStatus.Pending : (error == null) ? UniTaskStatus.Succeeded : (error is OperationCanceledException) ? UniTaskStatus.Canceled : UniTaskStatus.Faulted; @@ -132,7 +165,7 @@ namespace UniRx.Async [MethodImpl(MethodImplOptions.AggressiveInlining)] public UniTaskStatus UnsafeGetStatus() { - return (continuation == null || !completed) ? UniTaskStatus.Pending + return (continuation == null || (completedCount == 0)) ? UniTaskStatus.Pending : (error == null) ? UniTaskStatus.Succeeded : (error is OperationCanceledException) ? UniTaskStatus.Canceled : UniTaskStatus.Faulted; @@ -145,7 +178,7 @@ namespace UniRx.Async public TResult GetResult(short token) { ValidateToken(token); - if (!completed) + if (!(completedCount == 0)) { throw new InvalidOperationException("not yet completed."); } @@ -183,6 +216,15 @@ namespace UniRx.Async /* no use ValueTaskSourceOnCOmpletedFlags, always no capture ExecutionContext and SynchronizationContext. */ + /* + PatternA: GetStatus=Pending => OnCompleted => TrySet*** => GetResult + PatternB: TrySet*** => GetStatus=!Pending => GetResult + PatternC: GetStatus=Pending => TrySet/OnCompleted(race condition) => GetResult + C.1: win OnCompleted -> TrySet invoke saved continuation + C.2: win TrySet -> should invoke continuation here. + */ + + // not set continuation yet. object oldContinuation = this.continuation; if (oldContinuation == null) { @@ -192,10 +234,11 @@ namespace UniRx.Async if (oldContinuation != null) { - // Operation already completed, so we need to queue the supplied callback. + // already running continuation in TrySet. + // It will cause call OnCompleted multiple time, invalid. if (!ReferenceEquals(oldContinuation, UniTaskCompletionSourceCoreShared.s_sentinel)) { - throw new InvalidOperationException("already completed."); + throw new InvalidOperationException(); } continuation(state); @@ -210,23 +253,6 @@ namespace UniRx.Async throw new InvalidOperationException("token version is not matched."); } } - - /// Signals that the operation has completed. Invoked after the result or error has been set. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void SignalCompletion() - { - if (completed) - { - throw new InvalidOperationException(); - } - - completed = true; - - if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) - { - continuation(continuationState); - } - } } internal static class UniTaskCompletionSourceCoreShared // separated out of generic to avoid unnecessary duplication @@ -277,17 +303,17 @@ namespace UniRx.Async public void SetResult() { - core.SetResult(AsyncUnit.Default); + core.TrySetResult(AsyncUnit.Default); } public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); } public void SetException(Exception exception) { - core.SetException(exception); + core.TrySetException(exception); } public void GetResult(short token) @@ -369,17 +395,17 @@ namespace UniRx.Async public void SetResult() { - core.SetResult(AsyncUnit.Default); + core.TrySetResult(AsyncUnit.Default); } public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); } public void SetException(Exception exception) { - core.SetException(exception); + core.TrySetException(exception); } public void GetResult(short token) @@ -463,17 +489,17 @@ namespace UniRx.Async public void SetResult(T result) { - core.SetResult(result); + core.TrySetResult(result); } public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); } public void SetException(Exception exception) { - core.SetException(exception); + core.TrySetException(exception); } public T GetResult(short token) @@ -560,17 +586,17 @@ namespace UniRx.Async public void SetResult(T result) { - core.SetResult(result); + core.TrySetResult(result); } public void SetCanceled(CancellationToken cancellationToken = default) { - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); } public void SetException(Exception exception) { - core.SetException(exception); + core.TrySetException(exception); } public T GetResult(short token) @@ -616,7 +642,6 @@ namespace UniRx.Async if (pool.TryReturn(this)) { GC.ReRegisterForFinalize(this); - return; } } } diff --git a/Assets/UniRx.Async/UniTaskExtensions.cs b/Assets/UniRx.Async/UniTaskExtensions.cs index d643bc3..6115478 100644 --- a/Assets/UniRx.Async/UniTaskExtensions.cs +++ b/Assets/UniRx.Async/UniTaskExtensions.cs @@ -76,7 +76,16 @@ namespace UniRx.Async { try { - var awaiter = task.GetAwaiter(); + UniTask.Awaiter awaiter; + try + { + awaiter = task.GetAwaiter(); + } + catch (Exception ex) + { + return Task.FromException(ex); + } + if (awaiter.IsCompleted) { try @@ -121,7 +130,16 @@ namespace UniRx.Async { try { - var awaiter = task.GetAwaiter(); + UniTask.Awaiter awaiter; + try + { + awaiter = task.GetAwaiter(); + } + catch (Exception ex) + { + return Task.FromException(ex); + } + if (awaiter.IsCompleted) { try diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index 9bf78bb..cec9a2f 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -573,7 +573,7 @@ namespace UniRx.Async { // TODO:Remove Tracking // TaskTracker.RemoveTracking(); - core.SetCanceled(cancellationToken); + core.TrySetCanceled(cancellationToken); return false; } @@ -586,7 +586,7 @@ namespace UniRx.Async { // TODO:Remove Tracking // TaskTracker.RemoveTracking(); - core.SetResult(asyncOperation.asset); + core.TrySetResult(asyncOperation.asset); return false; } From f28743f7f6f630a17a0eed8ed2282f4d5bdd3510 Mon Sep 17 00:00:00 2001 From: neuecc Date: Sun, 26 Apr 2020 02:38:16 +0900 Subject: [PATCH 012/173] more working --- Assets/Scenes/SandboxMain.cs | 2 +- .../CancellationTokenExtensions.cs | 2 +- .../AsyncUniTaskMethodBuilder.cs | 8 +- Assets/UniRx.Async/Internal/StatePool.cs | 44 ++ Assets/UniRx.Async/UniTask.Factory.cs | 12 +- .../UniRx.Async/UniTask.WhenAny.Generated.cs | 378 +++++++++--------- .../UniRx.Async/UniTask.WhenAny.Generated.tt | 4 +- Assets/UniRx.Async/UniTask.cs | 1 + Assets/UniRx.Async/UniTaskCompletionSource.cs | 68 ++-- .../UniTaskExtensions.Shorthand.cs | 168 +++++++- .../UniTaskExtensions.Shorthand.cs.meta | 11 - .../UniTaskExtensions.Shorthand.tt | 63 +++ Assets/UniRx.Async/UniTaskExtensions.cs | 250 +++++++++--- .../UniTaskObservableExtensions.cs | 4 +- .../UnityAsyncExtensions.MonoBehaviour.cs | 14 + Assets/UniRx.Async/UnityAsyncExtensions.cs | 15 +- 16 files changed, 710 insertions(+), 334 deletions(-) delete mode 100644 Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta create mode 100644 Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt create mode 100644 Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs diff --git a/Assets/Scenes/SandboxMain.cs b/Assets/Scenes/SandboxMain.cs index 6417aa3..8d6fc4a 100644 --- a/Assets/Scenes/SandboxMain.cs +++ b/Assets/Scenes/SandboxMain.cs @@ -50,7 +50,7 @@ public class SandboxMain : MonoBehaviour { text.text = ""; - ucs.SetResult(); + ucs.TrySetResult(); await ucs.Task; }); diff --git a/Assets/UniRx.Async/CancellationTokenExtensions.cs b/Assets/UniRx.Async/CancellationTokenExtensions.cs index 3f9a89b..3e0fbc1 100644 --- a/Assets/UniRx.Async/CancellationTokenExtensions.cs +++ b/Assets/UniRx.Async/CancellationTokenExtensions.cs @@ -24,7 +24,7 @@ namespace UniRx.Async static void Callback(object state) { var promise = (UniTaskCompletionSource)state; - promise.SetResult(); + promise.TrySetResult(); } public static CancellationTokenRegistration RegisterWithoutCaptureExecutionContext(this CancellationToken cancellationToken, Action callback) diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs index e53f0f2..0c10c95 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs @@ -60,7 +60,7 @@ namespace UniRx.Async.CompilerServices if (promise != null) { - promise.SetException(exception); + promise.TrySetException(exception); } else { @@ -81,7 +81,7 @@ namespace UniRx.Async.CompilerServices if (promise != null) { - promise.SetResult(); + promise.TrySetResult(); } } @@ -192,7 +192,7 @@ namespace UniRx.Async.CompilerServices } else { - promise.SetException(exception); + promise.TrySetException(exception); } } @@ -213,7 +213,7 @@ namespace UniRx.Async.CompilerServices return; } - promise.SetResult(result); + promise.TrySetResult(result); } // 5. AwaitOnCompleted diff --git a/Assets/UniRx.Async/Internal/StatePool.cs b/Assets/UniRx.Async/Internal/StatePool.cs index 7fe114b..9182952 100644 --- a/Assets/UniRx.Async/Internal/StatePool.cs +++ b/Assets/UniRx.Async/Internal/StatePool.cs @@ -6,6 +6,11 @@ namespace UniRx.Async.Internal { internal static class StateTuple { + public static StateTuple Create(T1 item1) + { + return StatePool.Create(item1); + } + public static StateTuple Create(T1 item1, T2 item2) { return StatePool.Create(item1, item2); @@ -17,6 +22,45 @@ namespace UniRx.Async.Internal } } + internal class StateTuple : IDisposable + { + public T1 Item1; + + public void Deconstruct(out T1 item1) + { + item1 = this.Item1; + } + + public void Dispose() + { + StatePool.Return(this); + } + } + + internal static class StatePool + { + static readonly ConcurrentQueue> queue = new ConcurrentQueue>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static StateTuple Create(T1 item1) + { + if (queue.TryDequeue(out var value)) + { + value.Item1 = item1; + return value; + } + + return new StateTuple { Item1 = item1 }; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Return(StateTuple tuple) + { + tuple.Item1 = default; + queue.Enqueue(tuple); + } + } + internal class StateTuple : IDisposable { public T1 Item1; diff --git a/Assets/UniRx.Async/UniTask.Factory.cs b/Assets/UniRx.Async/UniTask.Factory.cs index 5878d91..c63d8c3 100644 --- a/Assets/UniRx.Async/UniTask.Factory.cs +++ b/Assets/UniRx.Async/UniTask.Factory.cs @@ -12,7 +12,7 @@ namespace UniRx.Async static readonly UniTask CanceledUniTask = new Func(() => { var promise = new UniTaskCompletionSource(); - promise.SetCanceled(CancellationToken.None); + promise.TrySetCanceled(CancellationToken.None); promise.MarkHandled(); return promise.Task; })(); @@ -24,7 +24,7 @@ namespace UniRx.Async static CanceledUniTaskCache() { var promise = new UniTaskCompletionSource(); - promise.SetCanceled(CancellationToken.None); + promise.TrySetCanceled(CancellationToken.None); promise.MarkHandled(); Task = promise.Task; } @@ -35,7 +35,7 @@ namespace UniRx.Async public static UniTask FromException(Exception ex) { var promise = new UniTaskCompletionSource(); - promise.SetException(ex); + promise.TrySetException(ex); promise.MarkHandled(); return promise.Task; } @@ -43,7 +43,7 @@ namespace UniRx.Async public static UniTask FromException(Exception ex) { var promise = new UniTaskCompletionSource(); - promise.SetException(ex); + promise.TrySetException(ex); promise.MarkHandled(); return promise.Task; } @@ -62,7 +62,7 @@ namespace UniRx.Async else { var promise = new UniTaskCompletionSource(); - promise.SetCanceled(cancellationToken); + promise.TrySetCanceled(cancellationToken); promise.MarkHandled(); return promise.Task; } @@ -77,7 +77,7 @@ namespace UniRx.Async else { var promise = new UniTaskCompletionSource(); - promise.SetCanceled(cancellationToken); + promise.TrySetCanceled(cancellationToken); promise.MarkHandled(); return promise.Task; } diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs index 0773525..14a29b6 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs @@ -9,15 +9,15 @@ namespace UniRx.Async { public partial struct UniTask { - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> WhenAny(UniTask task1, UniTask task2) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2)> WhenAny(UniTask task1, UniTask task2) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2))>(new WhenAnyPromise(task1, task2), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2)>(new WhenAnyPromise(task1, task2), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2)> core; public WhenAnyPromise(UniTask task1, UniTask task2) { @@ -77,7 +77,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default))); + self.core.TrySetResult((0, result, default)); } } @@ -96,12 +96,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result))); + self.core.TrySetResult((1, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2)) GetResult(short token) + public (int, T1 result1, T2 result2) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -134,15 +134,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> WhenAny(UniTask task1, UniTask task2, UniTask task3) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3)> WhenAny(UniTask task1, UniTask task2, UniTask task3) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))>(new WhenAnyPromise(task1, task2, task3), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3)>(new WhenAnyPromise(task1, task2, task3), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3) { @@ -220,7 +220,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default)); } } @@ -239,7 +239,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default))); + self.core.TrySetResult((1, default, result, default)); } } @@ -258,12 +258,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result))); + self.core.TrySetResult((2, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -296,15 +296,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))>(new WhenAnyPromise(task1, task2, task3, task4), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4)>(new WhenAnyPromise(task1, task2, task3, task4), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { @@ -400,7 +400,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default)); } } @@ -419,7 +419,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default)); } } @@ -438,7 +438,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((2, default, default, result, default)); } } @@ -457,12 +457,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((3, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -495,15 +495,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))>(new WhenAnyPromise(task1, task2, task3, task4, task5), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)>(new WhenAnyPromise(task1, task2, task3, task4, task5), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { @@ -617,7 +617,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default)); } } @@ -636,7 +636,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default)); } } @@ -655,7 +655,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default)); } } @@ -674,7 +674,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default)); } } @@ -693,12 +693,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((4, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -731,15 +731,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { @@ -871,7 +871,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default)); } } @@ -890,7 +890,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default)); } } @@ -909,7 +909,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default)); } } @@ -928,7 +928,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default)); } } @@ -947,7 +947,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default)); } } @@ -966,12 +966,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((5, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -1004,15 +1004,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { @@ -1162,7 +1162,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default)); } } @@ -1181,7 +1181,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default)); } } @@ -1200,7 +1200,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default)); } } @@ -1219,7 +1219,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default)); } } @@ -1238,7 +1238,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default)); } } @@ -1257,7 +1257,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default)); } } @@ -1276,12 +1276,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((6, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -1314,15 +1314,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { @@ -1490,7 +1490,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default)); } } @@ -1509,7 +1509,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default)); } } @@ -1528,7 +1528,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default)); } } @@ -1547,7 +1547,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default)); } } @@ -1566,7 +1566,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default)); } } @@ -1585,7 +1585,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default)); } } @@ -1604,7 +1604,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default)); } } @@ -1623,12 +1623,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -1661,15 +1661,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { @@ -1855,7 +1855,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default)); } } @@ -1874,7 +1874,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default)); } } @@ -1893,7 +1893,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default)); } } @@ -1912,7 +1912,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default)); } } @@ -1931,7 +1931,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default)); } } @@ -1950,7 +1950,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default)); } } @@ -1969,7 +1969,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default)); } } @@ -1988,7 +1988,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default)); } } @@ -2007,12 +2007,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -2045,15 +2045,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { @@ -2257,7 +2257,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default)); } } @@ -2276,7 +2276,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default)); } } @@ -2295,7 +2295,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default)); } } @@ -2314,7 +2314,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default)); } } @@ -2333,7 +2333,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default)); } } @@ -2352,7 +2352,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default)); } } @@ -2371,7 +2371,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default)); } } @@ -2390,7 +2390,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default)); } } @@ -2409,7 +2409,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default)); } } @@ -2428,12 +2428,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -2466,15 +2466,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { @@ -2696,7 +2696,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default)); } } @@ -2715,7 +2715,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default)); } } @@ -2734,7 +2734,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default)); } } @@ -2753,7 +2753,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default)); } } @@ -2772,7 +2772,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default)); } } @@ -2791,7 +2791,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default)); } } @@ -2810,7 +2810,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default)); } } @@ -2829,7 +2829,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default)); } } @@ -2848,7 +2848,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default)); } } @@ -2867,7 +2867,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default)); } } @@ -2886,12 +2886,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -2924,15 +2924,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { @@ -3172,7 +3172,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -3191,7 +3191,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default)); } } @@ -3210,7 +3210,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default)); } } @@ -3229,7 +3229,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default)); } } @@ -3248,7 +3248,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default)); } } @@ -3267,7 +3267,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default)); } } @@ -3286,7 +3286,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default)); } } @@ -3305,7 +3305,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default)); } } @@ -3324,7 +3324,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default)); } } @@ -3343,7 +3343,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default)); } } @@ -3362,7 +3362,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default)); } } @@ -3381,12 +3381,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -3419,15 +3419,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { @@ -3685,7 +3685,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -3704,7 +3704,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -3723,7 +3723,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default, default)); } } @@ -3742,7 +3742,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default, default)); } } @@ -3761,7 +3761,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default, default)); } } @@ -3780,7 +3780,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default, default)); } } @@ -3799,7 +3799,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default, default)); } } @@ -3818,7 +3818,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default, default)); } } @@ -3837,7 +3837,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default, default)); } } @@ -3856,7 +3856,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default, default)); } } @@ -3875,7 +3875,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default, default)); } } @@ -3894,7 +3894,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result, default)); } } @@ -3913,12 +3913,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((12, default, default, default, default, default, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -3951,15 +3951,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { @@ -4235,7 +4235,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -4254,7 +4254,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -4273,7 +4273,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -4292,7 +4292,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default, default, default)); } } @@ -4311,7 +4311,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default, default, default)); } } @@ -4330,7 +4330,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default, default, default)); } } @@ -4349,7 +4349,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default, default, default)); } } @@ -4368,7 +4368,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default, default, default)); } } @@ -4387,7 +4387,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default, default, default)); } } @@ -4406,7 +4406,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default, default, default)); } } @@ -4425,7 +4425,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default, default, default)); } } @@ -4444,7 +4444,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result, default, default)); } } @@ -4463,7 +4463,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((12, default, default, default, default, default, default, default, default, default, default, default, default, result, default)); } } @@ -4482,12 +4482,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((13, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((13, default, default, default, default, default, default, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); @@ -4520,15 +4520,15 @@ namespace UniRx.Async } } - public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) + public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { - return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14, task15), 0); + return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15)>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14, task15), 0); } - sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> + sealed class WhenAnyPromise : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15)> { int completedCount; - UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> core; + UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15)> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { @@ -4822,7 +4822,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -4841,7 +4841,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -4860,7 +4860,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -4879,7 +4879,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default, default, default, default)); } } @@ -4898,7 +4898,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default, default, default, default)); } } @@ -4917,7 +4917,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default, default, default, default)); } } @@ -4936,7 +4936,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default, default, default, default)); } } @@ -4955,7 +4955,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default, default, default, default)); } } @@ -4974,7 +4974,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default, default, default, default)); } } @@ -4993,7 +4993,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default, default, default, default)); } } @@ -5012,7 +5012,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); + self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default, default, default, default)); } } @@ -5031,7 +5031,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); + self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result, default, default, default)); } } @@ -5050,7 +5050,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); + self.core.TrySetResult((12, default, default, default, default, default, default, default, default, default, default, default, default, result, default, default)); } } @@ -5069,7 +5069,7 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((13, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); + self.core.TrySetResult((13, default, default, default, default, default, default, default, default, default, default, default, default, default, result, default)); } } @@ -5088,12 +5088,12 @@ namespace UniRx.Async if (Interlocked.Increment(ref self.completedCount) == 1) { - self.core.TrySetResult((14, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); + self.core.TrySetResult((14, default, default, default, default, default, default, default, default, default, default, default, default, default, default, result)); } } - public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15)) GetResult(short token) + public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt b/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt index 3d50260..ab66053 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt @@ -21,9 +21,9 @@ namespace UniRx.Async var args = string.Join(", ", range.Select(x => $"UniTask task{x}")); var targs = string.Join(", ", range.Select(x => $"task{x}")); var tresult = string.Join(", ", range.Select(x => $"task{x}.GetAwaiter().GetResult()")); - var tBool = string.Join(", ", range.Select(x => $"(bool hasResult, T{x} result{x})")); + var tBool = string.Join(", ", range.Select(x => $"T{x} result{x}")); var tfield = string.Join(", ", range.Select(x => $"self.t{x}")); - Func getResult = j => string.Join(", ", range.Select(x => (x == j) ? "(true, result)" : "(false, default)")); + Func getResult = j => string.Join(", ", range.Select(x => (x == j) ? "result" : "default")); #> public static UniTask<(int winArgumentIndex, <#= tBool #>)> WhenAny<<#= t #>>(<#= args #>) { diff --git a/Assets/UniRx.Async/UniTask.cs b/Assets/UniRx.Async/UniTask.cs index 5a372a7..bc7fe96 100644 --- a/Assets/UniRx.Async/UniTask.cs +++ b/Assets/UniRx.Async/UniTask.cs @@ -403,6 +403,7 @@ namespace UniRx.Async return UniTask.CompletedTask; } + // Converting UniTask -> UniTask is zero overhead. return new UniTask(this.source, this.token); } diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index 89d700d..ccc4f4a 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -13,22 +13,22 @@ namespace UniRx.Async { public interface IResolvePromise { - void SetResult(); + bool TrySetResult(); } public interface IResolvePromise { - void SetResult(T value); + bool TrySetResult(T value); } public interface IRejectPromise { - void SetException(Exception exception); + bool TrySetException(Exception exception); } public interface ICancelPromise { - void SetCanceled(CancellationToken cancellationToken = default); + bool TrySetCanceled(CancellationToken cancellationToken = default); } public interface IPromise : IResolvePromise, IRejectPromise, ICancelPromise @@ -301,19 +301,19 @@ namespace UniRx.Async core.Reset(); } - public void SetResult() + public bool TrySetResult() { - core.TrySetResult(AsyncUnit.Default); + return core.TrySetResult(AsyncUnit.Default); } - public void SetCanceled(CancellationToken cancellationToken = default) + public bool TrySetCanceled(CancellationToken cancellationToken = default) { - core.TrySetCanceled(cancellationToken); + return core.TrySetCanceled(cancellationToken); } - public void SetException(Exception exception) + public bool TrySetException(Exception exception) { - core.TrySetException(exception); + return core.TrySetException(exception); } public void GetResult(short token) @@ -364,7 +364,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) { var source = Create(); - source.SetCanceled(cancellationToken); + source.TrySetCanceled(cancellationToken); token = source.core.Version; return source; } @@ -372,7 +372,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateFromException(Exception exception, out short token) { var source = Create(); - source.SetException(exception); + source.TrySetException(exception); token = source.core.Version; return source; } @@ -380,7 +380,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateCompleted(out short token) { var source = Create(); - source.SetResult(); + source.TrySetResult(); token = source.core.Version; return source; } @@ -393,19 +393,19 @@ namespace UniRx.Async } } - public void SetResult() + public bool TrySetResult() { - core.TrySetResult(AsyncUnit.Default); + return core.TrySetResult(AsyncUnit.Default); } - public void SetCanceled(CancellationToken cancellationToken = default) + public bool TrySetCanceled(CancellationToken cancellationToken = default) { - core.TrySetCanceled(cancellationToken); + return core.TrySetCanceled(cancellationToken); } - public void SetException(Exception exception) + public bool TrySetException(Exception exception) { - core.TrySetException(exception); + return core.TrySetException(exception); } public void GetResult(short token) @@ -487,19 +487,19 @@ namespace UniRx.Async TaskTracker2.TrackActiveTask(this, 2); } - public void SetResult(T result) + public bool TrySetResult(T result) { - core.TrySetResult(result); + return core.TrySetResult(result); } - public void SetCanceled(CancellationToken cancellationToken = default) + public bool TrySetCanceled(CancellationToken cancellationToken = default) { - core.TrySetCanceled(cancellationToken); + return core.TrySetCanceled(cancellationToken); } - public void SetException(Exception exception) + public bool TrySetException(Exception exception) { - core.TrySetException(exception); + return core.TrySetException(exception); } public T GetResult(short token) @@ -555,7 +555,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) { var source = Create(); - source.SetCanceled(cancellationToken); + source.TrySetCanceled(cancellationToken); token = source.core.Version; return source; } @@ -563,7 +563,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateFromException(Exception exception, out short token) { var source = Create(); - source.SetException(exception); + source.TrySetException(exception); token = source.core.Version; return source; } @@ -571,7 +571,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource CreateFromResult(T result, out short token) { var source = Create(); - source.SetResult(result); + source.TrySetResult(result); token = source.core.Version; return source; } @@ -584,19 +584,19 @@ namespace UniRx.Async } } - public void SetResult(T result) + public bool TrySetResult(T result) { - core.TrySetResult(result); + return core.TrySetResult(result); } - public void SetCanceled(CancellationToken cancellationToken = default) + public bool TrySetCanceled(CancellationToken cancellationToken = default) { - core.TrySetCanceled(cancellationToken); + return core.TrySetCanceled(cancellationToken); } - public void SetException(Exception exception) + public bool TrySetException(Exception exception) { - core.TrySetException(exception); + return core.TrySetException(exception); } public T GetResult(short token) diff --git a/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs index 235bcac..37fdd80 100644 --- a/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs +++ b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs @@ -1,6 +1,4 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System.Collections.Generic; namespace UniRx.Async @@ -8,46 +6,182 @@ namespace UniRx.Async public static partial class UniTaskExtensions { // shorthand of WhenAll + + public static UniTask.Awaiter GetAwaiter(this UniTask[] tasks) + { + return UniTask.WhenAll(tasks).GetAwaiter(); + } public static UniTask.Awaiter GetAwaiter(this IEnumerable tasks) { return UniTask.WhenAll(tasks).GetAwaiter(); } + public static UniTask.Awaiter GetAwaiter(this UniTask[] tasks) + { + return UniTask.WhenAll(tasks).GetAwaiter(); + } + public static UniTask.Awaiter GetAwaiter(this IEnumerable> tasks) { return UniTask.WhenAll(tasks).GetAwaiter(); } - public static UniTask<(T1 result1, T2 result2)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2) tasks) + public static UniTask<(T1, T2)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2) tasks) { - return UniTask.WhenAll(tasks.task1, tasks.task2).GetAwaiter(); + return UniTask.WhenAll(tasks.Item1, tasks.Item2).GetAwaiter(); } - public static UniTask<(T1 result1, T2 result2, T3 result3)> WhenAll(this (UniTask task1, UniTask task2, UniTask task3) tasks) + public static UniTask<(T1, T2, T3)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3) tasks) { - return UniTask.WhenAll(tasks.task1, tasks.task2, tasks.task3); + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3).GetAwaiter(); } - public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4)> WhenAll(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4) tasks) + public static UniTask<(T1, T2, T3, T4)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4) tasks) { - return UniTask.WhenAll(tasks.task1, tasks.task2, tasks.task3, tasks.task4); + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4).GetAwaiter(); } - public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> WhenAll(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) tasks) + public static UniTask<(T1, T2, T3, T4, T5)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) tasks) { - return UniTask.WhenAll(tasks.task1, tasks.task2, tasks.task3, tasks.task4, tasks.task5); + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5).GetAwaiter(); } - public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> WhenAll(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) tasks) + public static UniTask<(T1, T2, T3, T4, T5, T6)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) tasks) { - return UniTask.WhenAll(tasks.task1, tasks.task2, tasks.task3, tasks.task4, tasks.task5, tasks.task6); + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6).GetAwaiter(); } - public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> WhenAll(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) tasks) + public static UniTask<(T1, T2, T3, T4, T5, T6, T7)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) tasks) { - return UniTask.WhenAll(tasks.task1, tasks.task2, tasks.task3, tasks.task4, tasks.task5, tasks.task6, tasks.task7); + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7).GetAwaiter(); } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8).GetAwaiter(); + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9).GetAwaiter(); + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10).GetAwaiter(); + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11).GetAwaiter(); + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12).GetAwaiter(); + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12, tasks.Item13).GetAwaiter(); + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12, tasks.Item13, tasks.Item14).GetAwaiter(); + } + + public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12, tasks.Item13, tasks.Item14, tasks.Item15).GetAwaiter(); + } + + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12, tasks.Item13).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12, tasks.Item13, tasks.Item14).GetAwaiter(); + } + + + public static UniTask.Awaiter GetAwaiter(this (UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) tasks) + { + return UniTask.WhenAll(tasks.Item1, tasks.Item2, tasks.Item3, tasks.Item4, tasks.Item5, tasks.Item6, tasks.Item7, tasks.Item8, tasks.Item9, tasks.Item10, tasks.Item11, tasks.Item12, tasks.Item13, tasks.Item14, tasks.Item15).GetAwaiter(); + } + + } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta deleted file mode 100644 index e2dcc14..0000000 --- a/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4b4ff020f73dc6d4b8ebd4760d61fb43 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt new file mode 100644 index 0000000..ecc0767 --- /dev/null +++ b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt @@ -0,0 +1,63 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System.Collections.Generic; + +namespace UniRx.Async +{ + public static partial class UniTaskExtensions + { + // shorthand of WhenAll + + public static UniTask.Awaiter GetAwaiter(this UniTask[] tasks) + { + return UniTask.WhenAll(tasks).GetAwaiter(); + } + + public static UniTask.Awaiter GetAwaiter(this IEnumerable tasks) + { + return UniTask.WhenAll(tasks).GetAwaiter(); + } + + public static UniTask.Awaiter GetAwaiter(this UniTask[] tasks) + { + return UniTask.WhenAll(tasks).GetAwaiter(); + } + + public static UniTask.Awaiter GetAwaiter(this IEnumerable> tasks) + { + return UniTask.WhenAll(tasks).GetAwaiter(); + } + +<# for(var i = 2; i <= 15; i++ ) { + var range = Enumerable.Range(1, i); + var t = string.Join(", ", range.Select(x => "T" + x)); + var args = string.Join(", ", range.Select(x => $"UniTask task{x}")); + var titems = string.Join(", ", range.Select(x => $"tasks.Item{x}")); +#> + public static UniTask<(<#= t #>)>.Awaiter GetAwaiter<<#= t #>>(this (<#= args #>) tasks) + { + return UniTask.WhenAll(<#= titems #>).GetAwaiter(); + } + +<# } #> + +<# for(var i = 2; i <= 15; i++ ) { + var range = Enumerable.Range(1, i); + var args = string.Join(", ", range.Select(x => $"UniTask task{x}")); + var titems = string.Join(", ", range.Select(x => $"tasks.Item{x}")); +#> + + public static UniTask.Awaiter GetAwaiter(this (<#= args #>) tasks) + { + return UniTask.WhenAll(<#= titems #>).GetAwaiter(); + } + +<# } #> + + } +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTaskExtensions.cs b/Assets/UniRx.Async/UniTaskExtensions.cs index 6115478..9642af1 100644 --- a/Assets/UniRx.Async/UniTaskExtensions.cs +++ b/Assets/UniRx.Async/UniTaskExtensions.cs @@ -26,13 +26,13 @@ namespace UniRx.Async switch (x.Status) { case TaskStatus.Canceled: - p.SetCanceled(); + p.TrySetCanceled(); break; case TaskStatus.Faulted: - p.SetException(x.Exception); + p.TrySetException(x.Exception); break; case TaskStatus.RanToCompletion: - p.SetResult(x.Result); + p.TrySetResult(x.Result); break; default: throw new NotSupportedException(); @@ -56,13 +56,13 @@ namespace UniRx.Async switch (x.Status) { case TaskStatus.Canceled: - p.SetCanceled(); + p.TrySetCanceled(); break; case TaskStatus.Faulted: - p.SetException(x.Exception); + p.TrySetException(x.Exception); break; case TaskStatus.RanToCompletion: - p.SetResult(); + p.TrySetResult(); break; default: throw new NotSupportedException(); @@ -190,23 +190,26 @@ namespace UniRx.Async return new ToCoroutineEnumerator(task, exceptionHandler); } - public static UniTask Timeout(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + public static async UniTask Timeout(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) { - return Timeout(task.AsAsyncUnitUniTask(), timeout, ignoreTimeScale, timeoutCheckTiming, taskCancellationTokenSource); - } - - // TODO: require UniTask2.Delay, WhenAny, etc... - - public static async UniTask Timeout(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) - { - // left, right both suppress operation canceled exception. - var delayCancellationTokenSource = new CancellationTokenSource(); - var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); + var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming, delayCancellationTokenSource.Token).SuppressCancellationThrow(); - var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + int winArgIndex; + bool taskResultIsCanceled; + try + { + (winArgIndex, taskResultIsCanceled, _) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + } + catch + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + throw; + } - if (!hasValue) + // timeout + if (winArgIndex == 1) { if (taskCancellationTokenSource != null) { @@ -222,37 +225,32 @@ namespace UniRx.Async delayCancellationTokenSource.Dispose(); } - if (value.IsCanceled) + if (taskResultIsCanceled) { Error.ThrowOperationCanceledException(); } - - return value.Result; } - /// - /// Timeout with suppress OperationCanceledException. Returns (bool, IsCacneled). - /// - public static async UniTask TimeoutWithoutException(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + public static async UniTask Timeout(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) { - var v = await TimeoutWithoutException(task.AsAsyncUnitUniTask(), timeout, ignoreTimeScale, timeoutCheckTiming, taskCancellationTokenSource); - return v.IsTimeout; - } - - - /// - /// Timeout with suppress OperationCanceledException. Returns (bool IsTimeout, T Result). - /// - public static async UniTask<(bool IsTimeout, T Result)> TimeoutWithoutException(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) - { - // left, right both suppress operation canceled exception. - var delayCancellationTokenSource = new CancellationTokenSource(); - var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow(); + var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming, delayCancellationTokenSource.Token).SuppressCancellationThrow(); - var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + int winArgIndex; + (bool IsCanceled, T Result) taskResult; + try + { + (winArgIndex, taskResult, _) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + } + catch + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + throw; + } - if (!hasValue) + // timeout + if (winArgIndex == 1) { if (taskCancellationTokenSource != null) { @@ -260,7 +258,7 @@ namespace UniRx.Async taskCancellationTokenSource.Dispose(); } - return (true, default(T)); + throw new TimeoutException("Exceed Timeout:" + timeout); } else { @@ -268,24 +266,142 @@ namespace UniRx.Async delayCancellationTokenSource.Dispose(); } - if (value.IsCanceled) + if (taskResult.IsCanceled) { Error.ThrowOperationCanceledException(); } - return (false, value.Result); + return taskResult.Result; + } + + /// + /// Timeout with suppress OperationCanceledException. Returns (bool, IsCacneled). + /// + public static async UniTask TimeoutWithoutException(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + { + var delayCancellationTokenSource = new CancellationTokenSource(); + var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming, delayCancellationTokenSource.Token).SuppressCancellationThrow(); + + int winArgIndex; + bool taskResultIsCanceled; + try + { + (winArgIndex, taskResultIsCanceled, _) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + } + catch + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + return true; + } + + // timeout + if (winArgIndex == 1) + { + if (taskCancellationTokenSource != null) + { + taskCancellationTokenSource.Cancel(); + taskCancellationTokenSource.Dispose(); + } + + throw new TimeoutException("Exceed Timeout:" + timeout); + } + else + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + } + + if (taskResultIsCanceled) + { + Error.ThrowOperationCanceledException(); + } + + return false; + } + + /// + /// Timeout with suppress OperationCanceledException. Returns (bool IsTimeout, T Result). + /// + public static async UniTask<(bool IsTimeout, T Result)> TimeoutWithoutException(this UniTask task, TimeSpan timeout, bool ignoreTimeScale = true, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) + { + var delayCancellationTokenSource = new CancellationTokenSource(); + var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming, delayCancellationTokenSource.Token).SuppressCancellationThrow(); + + int winArgIndex; + (bool IsCanceled, T Result) taskResult; + try + { + (winArgIndex, taskResult, _) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask); + } + catch + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + return (true, default); + } + + // timeout + if (winArgIndex == 1) + { + if (taskCancellationTokenSource != null) + { + taskCancellationTokenSource.Cancel(); + taskCancellationTokenSource.Dispose(); + } + + throw new TimeoutException("Exceed Timeout:" + timeout); + } + else + { + delayCancellationTokenSource.Cancel(); + delayCancellationTokenSource.Dispose(); + } + + if (taskResult.IsCanceled) + { + Error.ThrowOperationCanceledException(); + } + + return (false, taskResult.Result); } public static void Forget(this UniTask task) { - ForgetCore(task).Forget(); + var awaiter = task.GetAwaiter(); + if (awaiter.IsCompleted) + { + try + { + awaiter.GetResult(); + } + catch (Exception ex) + { + UniTaskScheduler.PublishUnobservedTaskException(ex); + } + } + + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple)state) + { + try + { + t.Item1.GetResult(); + } + catch (Exception ex) + { + UniTaskScheduler.PublishUnobservedTaskException(ex); + } + } + }, StateTuple.Create(awaiter)); } public static void Forget(this UniTask task, Action exceptionHandler, bool handleExceptionOnMainThread = true) { if (exceptionHandler == null) { - ForgetCore(task).Forget(); + Forget(task); } else { @@ -293,12 +409,6 @@ namespace UniRx.Async } } - // UniTask to UniTaskVoid - static async UniTaskVoid ForgetCore(UniTask task) - { - await task; - } - static async UniTaskVoid ForgetCoreWithCatch(UniTask task, Action exceptionHandler, bool handleExceptionOnMainThread) { try @@ -324,14 +434,40 @@ namespace UniRx.Async public static void Forget(this UniTask task) { - ForgetCore(task).Forget(); + var awaiter = task.GetAwaiter(); + if (awaiter.IsCompleted) + { + try + { + awaiter.GetResult(); + } + catch (Exception ex) + { + UniTaskScheduler.PublishUnobservedTaskException(ex); + } + } + + awaiter.SourceOnCompleted(state => + { + using (var t = (StateTuple.Awaiter>)state) + { + try + { + t.Item1.GetResult(); + } + catch (Exception ex) + { + UniTaskScheduler.PublishUnobservedTaskException(ex); + } + } + }, StateTuple.Create(awaiter)); } public static void Forget(this UniTask task, Action exceptionHandler, bool handleExceptionOnMainThread = true) { if (exceptionHandler == null) { - ForgetCore(task).Forget(); + task.Forget(); } else { @@ -339,12 +475,6 @@ namespace UniRx.Async } } - // UniTask to UniTaskVoid - static async UniTaskVoid ForgetCore(UniTask task) - { - await task; - } - static async UniTaskVoid ForgetCoreWithCatch(UniTask task, Action exceptionHandler, bool handleExceptionOnMainThread) { try diff --git a/Assets/UniRx.Async/UniTaskObservableExtensions.cs b/Assets/UniRx.Async/UniTaskObservableExtensions.cs index 2c5dd49..2276bd4 100644 --- a/Assets/UniRx.Async/UniTaskObservableExtensions.cs +++ b/Assets/UniRx.Async/UniTaskObservableExtensions.cs @@ -33,7 +33,7 @@ namespace UniRx.Async public static IObservable ToObservable(this UniTask task) { - if (task.IsCompleted) + if (task.Status.IsCompleted()) { try { @@ -55,7 +55,7 @@ namespace UniRx.Async /// public static IObservable ToObservable(this UniTask task) { - if (task.IsCompleted) + if (task.Status.IsCompleted()) { try { diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs b/Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs new file mode 100644 index 0000000..82e26c8 --- /dev/null +++ b/Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading; + +namespace UniRx.Async +{ + public static partial class UnityAsyncExtensions + { + public static void StartAsyncCoroutine(this UnityEngine.MonoBehaviour monoBehaviour, Func asyncCoroutine) + { + var token = monoBehaviour.GetCancellationTokenOnDestroy(); + asyncCoroutine(token).Forget(); + } + } +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index cec9a2f..285eda5 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -2,6 +2,7 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; +using System.Runtime.CompilerServices; using System.Threading; using UniRx.Async.Internal; using UnityEngine; @@ -183,11 +184,11 @@ namespace UniRx.Async #endif - public struct AsyncOperationAwaiter : IAwaiter + public struct AsyncOperationAwaiter : ICriticalNotifyCompletion { AsyncOperation asyncOperation; Action continuationAction; - UniTaskStatus status; + // UniTaskStatus status; public AsyncOperationAwaiter(AsyncOperation asyncOperation) { @@ -196,13 +197,12 @@ namespace UniRx.Async this.continuationAction = null; } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; + public bool IsCompleted => asyncOperation.isDone; public void GetResult() { - if (status == UniTaskStatus.Succeeded) return; - + //*/ if (status == UniTaskStatus.Succeeded) return; + /* if (status == UniTaskStatus.Pending) { // first timing of call @@ -215,6 +215,7 @@ namespace UniRx.Async Error.ThrowNotYetCompleted(); } } + */ if (continuationAction != null) { @@ -236,7 +237,7 @@ namespace UniRx.Async public void UnsafeOnCompleted(Action continuation) { Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction); - continuationAction = continuation.AsFuncOfT(); + continuationAction = continuation.AsFuncOfT(); // allocate delegate. asyncOperation.completed += continuationAction; } } From 7bc9ef90f1044b8a983c3cbff966623592640430 Mon Sep 17 00:00:00 2001 From: neuecc Date: Mon, 4 May 2020 01:59:22 +0900 Subject: [PATCH 013/173] complete except trigger --- Assets/Scenes/SandboxMain.cs | 13 +- .../LazyPromise.cs.meta => AsyncLazy.cs.meta} | 2 +- .../UniRx.Async/EnumeratorAsyncExtensions.cs | 5 - Assets/UniRx.Async/Internal/LazyPromise.cs | 130 -- Assets/UniRx.Async/Internal/MinimumQueue.cs | 5 +- .../StatePool.cs.meta} | 2 +- .../UniRx.Async/Triggers/AsyncTriggerBase.cs | 46 +- .../Triggers/AsyncUpdateTrigger.cs | 159 +++ .../UniTask.WhenAll.Generated.cs.meta | 11 + .../UniTask.WhenAll.Generated.tt.meta | 7 + .../UniTask.WhenAny.Generated.cs.meta | 11 + .../UniTask.WhenAny.Generated.tt.meta | 7 + .../UniTaskExtensions.Shorthand.cs.meta | 11 + .../UniTaskExtensions.Shorthand.tt.meta | 7 + .../UniTaskObservableExtensions.cs | 4 +- ...UnityAsyncExtensions.MonoBehaviour.cs.meta | 11 + Assets/UniRx.Async/UnityAsyncExtensions.cs | 1094 ++++++----------- Assets/UniRx.Async/UnityAsyncExtensions.tt | 234 ++++ .../UniRx.Async/UnityAsyncExtensions.uGUI.cs | 225 ++-- 19 files changed, 960 insertions(+), 1024 deletions(-) rename Assets/UniRx.Async/{Internal/LazyPromise.cs.meta => AsyncLazy.cs.meta} (83%) delete mode 100644 Assets/UniRx.Async/Internal/LazyPromise.cs rename Assets/UniRx.Async/{UnityAsyncExtensions.cs.meta => Internal/StatePool.cs.meta} (83%) create mode 100644 Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta create mode 100644 Assets/UniRx.Async/UniTask.WhenAll.Generated.tt.meta create mode 100644 Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta create mode 100644 Assets/UniRx.Async/UniTask.WhenAny.Generated.tt.meta create mode 100644 Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta create mode 100644 Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt.meta create mode 100644 Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs.meta create mode 100644 Assets/UniRx.Async/UnityAsyncExtensions.tt diff --git a/Assets/Scenes/SandboxMain.cs b/Assets/Scenes/SandboxMain.cs index 8d6fc4a..5ddbaab 100644 --- a/Assets/Scenes/SandboxMain.cs +++ b/Assets/Scenes/SandboxMain.cs @@ -22,17 +22,6 @@ public class SandboxMain : MonoBehaviour void Start() { - // Setup unobserverd tskexception handling - TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; - - // Optional: disable ExecutionContext if you don't use AsyncLocal. - //if (!ExecutionContext.IsFlowSuppressed()) - //{ - // ExecutionContext.SuppressFlow(); - //} - - //// Optional: disable SynchronizationContext(to boostup performance) if you completely use UniTask only - //SynchronizationContext.SetSynchronizationContext(null); // ----- @@ -50,7 +39,7 @@ public class SandboxMain : MonoBehaviour { text.text = ""; - ucs.TrySetResult(); + // ucs.TrySetResult(); await ucs.Task; }); diff --git a/Assets/UniRx.Async/Internal/LazyPromise.cs.meta b/Assets/UniRx.Async/AsyncLazy.cs.meta similarity index 83% rename from Assets/UniRx.Async/Internal/LazyPromise.cs.meta rename to Assets/UniRx.Async/AsyncLazy.cs.meta index ee8f3f7..554d162 100644 --- a/Assets/UniRx.Async/Internal/LazyPromise.cs.meta +++ b/Assets/UniRx.Async/AsyncLazy.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fe7a4187b7f89f84582fd1e466a7f27e +guid: 01d1404ca421466419a7db7340ff5e77 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs index 4438f5b..f5f4b33 100644 --- a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs +++ b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs @@ -35,9 +35,6 @@ namespace UniRx.Async IEnumerator innerEnumerator; CancellationToken cancellationToken; - Action continuation; - ExceptionDispatchInfo exception; - UniTaskCompletionSourceCore core; EnumeratorPromise() @@ -122,8 +119,6 @@ namespace UniRx.Async core.Reset(); innerEnumerator = default; cancellationToken = default; - continuation = default; - exception = default; } ~EnumeratorPromise() diff --git a/Assets/UniRx.Async/Internal/LazyPromise.cs b/Assets/UniRx.Async/Internal/LazyPromise.cs deleted file mode 100644 index dfea432..0000000 --- a/Assets/UniRx.Async/Internal/LazyPromise.cs +++ /dev/null @@ -1,130 +0,0 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System; -using System.Threading; - -namespace UniRx.Async.Internal -{ - internal sealed class LazyPromise : IAwaiter - { - Func factory; - UniTask value; - - public LazyPromise(Func factory) - { - this.factory = factory; - } - - void Create() - { - var f = Interlocked.Exchange(ref factory, null); - if (f != null) - { - value = f(); - } - } - - public bool IsCompleted - { - get - { - Create(); - return value.IsCompleted; - } - } - - public UniTaskStatus Status - { - get - { - Create(); - return value.Status; - } - } - - public void GetResult() - { - Create(); - value.GetResult(); - } - - void IAwaiter.GetResult() - { - GetResult(); - } - - public void UnsafeOnCompleted(Action continuation) - { - Create(); - value.GetAwaiter().UnsafeOnCompleted(continuation); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - } - - internal sealed class LazyPromise : IAwaiter - { - Func> factory; - UniTask value; - - public LazyPromise(Func> factory) - { - this.factory = factory; - } - - void Create() - { - var f = Interlocked.Exchange(ref factory, null); - if (f != null) - { - value = f(); - } - } - - public bool IsCompleted - { - get - { - Create(); - return value.IsCompleted; - } - } - - public UniTaskStatus Status - { - get - { - Create(); - return value.Status; - } - } - - public T GetResult() - { - Create(); - return value.Result; - } - - void IAwaiter.GetResult() - { - GetResult(); - } - - public void UnsafeOnCompleted(Action continuation) - { - Create(); - value.GetAwaiter().UnsafeOnCompleted(continuation); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - } -} - -#endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Internal/MinimumQueue.cs b/Assets/UniRx.Async/Internal/MinimumQueue.cs index acf4962..5f3b589 100644 --- a/Assets/UniRx.Async/Internal/MinimumQueue.cs +++ b/Assets/UniRx.Async/Internal/MinimumQueue.cs @@ -8,7 +8,8 @@ using System.Runtime.CompilerServices; namespace UniRx.Async.Internal { // optimized version of Standard Queue. - internal class MinimumQueue + // TODO: to internal. + public class MinimumQueue { const int MinimumGrow = 4; const int GrowFactor = 200; @@ -28,7 +29,7 @@ namespace UniRx.Async.Internal public int Count { #if NET_4_6 || NET_STANDARD_2_0 - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif get { return size; } } diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs.meta b/Assets/UniRx.Async/Internal/StatePool.cs.meta similarity index 83% rename from Assets/UniRx.Async/UnityAsyncExtensions.cs.meta rename to Assets/UniRx.Async/Internal/StatePool.cs.meta index 6dfab81..6779aa1 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs.meta +++ b/Assets/UniRx.Async/Internal/StatePool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8cc7fd65dd1433e419be4764aeb51391 +guid: 60cdf0bcaea36b444a7ae7263ae7598f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs index b0ffa57..a7b0d7a 100644 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs +++ b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs @@ -15,46 +15,6 @@ namespace UniRx.Async.Triggers bool TrySetCanceled(); } - public class AsyncTriggerPromise : ReusablePromise, IPromise, ICancelablePromise - { - public CancellationToken RegisteredCancellationToken { get; private set; } - - public AsyncTriggerPromise() - : this(CancellationToken.None) - { - } - - public AsyncTriggerPromise(CancellationToken cancellationToken) - { - this.RegisteredCancellationToken = cancellationToken; - TaskTracker.TrackActiveTask(this); - } - - public override T GetResult() - { - if (Status == UniTaskStatus.Pending) return RawResult; - return base.GetResult(); - } - - public override bool TrySetResult(T result) - { - if (Status == UniTaskStatus.Pending) - { - // keep status as Pending. - this.ForceSetResult(result); - TryInvokeContinuation(); - return true; - } - return false; - } - - public override bool TrySetCanceled() - { - if (Status == UniTaskStatus.Canceled) return false; - TaskTracker.RemoveTracking(this); - return base.TrySetCanceled(); - } - } public interface ICancellationTokenKeyDictionary { @@ -62,7 +22,7 @@ namespace UniRx.Async.Triggers } public class AsyncTriggerPromiseDictionary : - Dictionary>, + Dictionary>, ICancellationTokenKeyDictionary, IEnumerable { @@ -73,7 +33,9 @@ namespace UniRx.Async.Triggers IEnumerator IEnumerable.GetEnumerator() { - return Values.GetEnumerator(); + // TODO: + throw new NotImplementedException(); + //return Values.GetEnumerator(); } void ICancellationTokenKeyDictionary.Remove(CancellationToken token) diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs index 258eec9..20df476 100644 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs +++ b/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs @@ -2,8 +2,11 @@ #if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System; using System.Collections.Generic; +using System.Linq; using System.Threading; +using UniRx.Async.Internal; using UnityEngine; using UnityEngine.EventSystems; @@ -35,6 +38,162 @@ namespace UniRx.Async.Triggers } + + + + // TODO:remove 2. + public abstract class AsyncTriggerBase2 : MonoBehaviour + { + static readonly Action Callback = CancelCallback; + + bool calledAwake = false; + bool destroyCalled = false; + CancellationTokenRegistration[] registeredCancellations; + int registeredCancellationsCount; + + protected abstract IEnumerable GetPromises(); + + void Awake() + { + calledAwake = true; + } + + void OnDestroy() + { + if (destroyCalled) return; + destroyCalled = true; + foreach (var item in GetPromises()) + { + item.TrySetCanceled(); + } + if (registeredCancellations != null) + { + for (int i = 0; i < registeredCancellationsCount; i++) + { + registeredCancellations[i].Dispose(); + registeredCancellations[i] = default(CancellationTokenRegistration); + } + ArrayPool.Shared.Return(registeredCancellations); + } + } + + protected void TrySetResult(MinimumQueue> promise, AsyncTriggerPromiseDictionary promises, T result) + { + if (promise != null) + { + // TODO: + } + + if (promises != null) + { + PromiseHelper.TrySetResultAll(promises.Values, result); + } + } + + public UniTask CreatePromise(ref MinimumQueue> promise, ref AsyncTriggerPromiseDictionary promises, CancellationToken cancellationToken) + { + if (destroyCalled) return UniTask.FromCanceled(); + + if (!calledAwake) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + + if (!cancellationToken.CanBeCanceled) + { + if (promise == null) + { + promise = new MinimumQueue>(4); // kakko kari.(ArrayPool?) + } + + var tcs = AutoResetUniTaskCompletionSource.Create(); + promise.Enqueue(tcs); + return tcs.Task; + } + + + CancellationTokenRegistration registrationToken = default; + // TODO:atode. + // var registrationToken = cancellationToken.RegisterWithoutCaptureExecutionContext(Callback, Tuple.Create((ICancellationTokenKeyDictionary)promises, (ICancelablePromise)cancellablePromise)); + if (registeredCancellations == null) + { + registeredCancellations = ArrayPool.Shared.Rent(4); + } + + ArrayPoolUtil.EnsureCapacity(ref registeredCancellations, registeredCancellationsCount + 1, ArrayPool.Shared); + registeredCancellations[registeredCancellationsCount++] = registrationToken; + + // TODO:use at registration + { + if (promises == null) + { + promises = new AsyncTriggerPromiseDictionary(); + } + + var tcs = AutoResetUniTaskCompletionSource.Create(); + promises.Add(cancellationToken, tcs); + return tcs.Task; + } + } + + static void CancelCallback(object state) + { + // TODO:nantokasuru. + + //var tuple = (Tuple)state; + //var dict = tuple.Item1; + //var promise = tuple.Item2; + + //promise.TrySetCanceled(); + //dict.Remove(promise.RegisteredCancellationToken); + } + + class AwakeMonitor : IPlayerLoopItem + { + readonly AsyncTriggerBase2 trigger; + + public AwakeMonitor(AsyncTriggerBase2 trigger) + { + this.trigger = trigger; + } + + public bool MoveNext() + { + if (trigger.calledAwake) return false; + if (trigger == null) + { + trigger.OnDestroy(); + return false; + } + return true; + } + } + } + + + // TODO:remove 2. + [DisallowMultipleComponent] + public class AsyncUpdateTrigger2 : AsyncTriggerBase2 + { + MinimumQueue> promise; + AsyncTriggerPromiseDictionary promises; + + protected override IEnumerable GetPromises() + { + // TODO: + throw new NotImplementedException(); + } + + void Update() + { + // TrySetResult + } + + public UniTask UpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + return CreatePromise(ref promise, ref promises, cancellationToken).AsUniTask(); + } + } } #endif diff --git a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta new file mode 100644 index 0000000..40ed46c --- /dev/null +++ b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5110117231c8a6d4095fd0cbd3f4c142 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTask.WhenAll.Generated.tt.meta b/Assets/UniRx.Async/UniTask.WhenAll.Generated.tt.meta new file mode 100644 index 0000000..f64cefd --- /dev/null +++ b/Assets/UniRx.Async/UniTask.WhenAll.Generated.tt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2c2ecfd98ee1b9a4c9fae1b398c32d75 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta new file mode 100644 index 0000000..49a2c3f --- /dev/null +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13d604ac281570c4eac9962429f19ca9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt.meta b/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt.meta new file mode 100644 index 0000000..389cfd2 --- /dev/null +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.tt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 71c2c0bce7543454c8ef545083e18170 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta new file mode 100644 index 0000000..e2dcc14 --- /dev/null +++ b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4b4ff020f73dc6d4b8ebd4760d61fb43 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt.meta b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt.meta new file mode 100644 index 0000000..4b7ff9e --- /dev/null +++ b/Assets/UniRx.Async/UniTaskExtensions.Shorthand.tt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9a75b5d7e55a5a34fb6476586df37c72 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/UniTaskObservableExtensions.cs b/Assets/UniRx.Async/UniTaskObservableExtensions.cs index 2276bd4..cb7dc03 100644 --- a/Assets/UniRx.Async/UniTaskObservableExtensions.cs +++ b/Assets/UniRx.Async/UniTaskObservableExtensions.cs @@ -86,12 +86,12 @@ namespace UniRx.Async } } - static async UniTaskVoid Fire(AsyncSubject subject, UniTask task) + static async UniTaskVoid Fire(AsyncSubject subject, UniTask task) { try { await task; - subject.OnNext(null); + subject.OnNext(AsyncUnit.Default); subject.OnCompleted(); } catch (Exception ex) diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs.meta b/Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs.meta new file mode 100644 index 0000000..6e45863 --- /dev/null +++ b/Assets/UniRx.Async/UnityAsyncExtensions.MonoBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2edd588bb09eb0a4695d039d6a1f02b2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index 285eda5..385581f 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -1,17 +1,20 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; using System.Runtime.CompilerServices; using System.Threading; -using UniRx.Async.Internal; using UnityEngine; +using UniRx.Async.Internal; +#if ENABLE_UNITYWEBREQUEST using UnityEngine.Networking; +#endif namespace UniRx.Async { public static partial class UnityAsyncExtensions { +#region AsyncOperation + public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); @@ -21,179 +24,25 @@ namespace UniRx.Async public static UniTask ToUniTask(this AsyncOperation asyncOperation) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); - return new UniTask(new AsyncOperationAwaiter(asyncOperation)); + + return new UniTask(AsyncOperationConfiguredSource.Create(asyncOperation, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token); } public static UniTask ConfigureAwait(this AsyncOperation asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); - var awaiter = new AsyncOperationConfiguredAwaiter(asyncOperation, progress, cancellation); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(timing, awaiter); - } - return new UniTask(awaiter); + return new UniTask(AsyncOperationConfiguredSource.Create(asyncOperation, timing, progress, cancellation, out var token), token); } - public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest resourceRequest) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - return new ResourceRequestAwaiter(resourceRequest); - } - - public static UniTask ToUniTask(this ResourceRequest resourceRequest) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - return new UniTask(new ResourceRequestAwaiter(resourceRequest)); - } - - public static UniTask ConfigureAwait(this ResourceRequest resourceRequest, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - - var awaiter = new ResourceRequestConfiguredAwaiter(resourceRequest, progress, cancellation); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(timing, awaiter); - } - return new UniTask(awaiter); - } - - public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest resourceRequest) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - return new AssetBundleRequestAwaiter(resourceRequest); - } - - public static UniTask ToUniTask(this AssetBundleRequest resourceRequest) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - return new UniTask(new AssetBundleRequestAwaiter(resourceRequest)); - } - - public static UniTask ConfigureAwait(this AssetBundleRequest resourceRequest, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - - var awaiter = new AssetBundleRequestConfiguredAwaiter(resourceRequest, progress, cancellation); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(timing, awaiter); - } - return new UniTask(awaiter); - } - - public static AssetBundleCreateRequestAwaiter GetAwaiter(this AssetBundleCreateRequest resourceRequest) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - return new AssetBundleCreateRequestAwaiter(resourceRequest); - } - - public static UniTask ToUniTask(this AssetBundleCreateRequest resourceRequest) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - return new UniTask(new AssetBundleCreateRequestAwaiter(resourceRequest)); - } - - public static UniTask ConfigureAwait(this AssetBundleCreateRequest resourceRequest, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) - { - Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest)); - - var awaiter = new AssetBundleCreateRequestConfiguredAwaiter(resourceRequest, progress, cancellation); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(timing, awaiter); - } - return new UniTask(awaiter); - } - -#if ENABLE_WWW - -#if UNITY_2018_3_OR_NEWER -#pragma warning disable CS0618 -#endif - - public static IAwaiter GetAwaiter(this WWW www) - { - Error.ThrowArgumentNullException(www, nameof(www)); - - var awaiter = new WWWConfiguredAwaiter(www, null, CancellationToken.None); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - } - return awaiter; - } - - public static UniTask ToUniTask(this WWW www) - { - Error.ThrowArgumentNullException(www, nameof(www)); - - var awaiter = new WWWConfiguredAwaiter(www, null, CancellationToken.None); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - } - return new UniTask(awaiter); - } - - public static UniTask ConfigureAwait(this WWW www, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) - { - Error.ThrowArgumentNullException(www, nameof(www)); - - var awaiter = new WWWConfiguredAwaiter(www, progress, cancellation); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(timing, awaiter); - } - return new UniTask(awaiter); - } - -#if UNITY_2018_3_OR_NEWER -#pragma warning restore CS0618 -#endif - -#endif - -#if ENABLE_UNITYWEBREQUEST - - public static UnityWebRequestAsyncOperationAwaiter GetAwaiter(this UnityWebRequestAsyncOperation asyncOperation) - { - Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); - return new UnityWebRequestAsyncOperationAwaiter(asyncOperation); - } - - public static UniTask ToUniTask(this UnityWebRequestAsyncOperation asyncOperation) - { - Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); - return new UniTask(new UnityWebRequestAsyncOperationAwaiter(asyncOperation)); - } - - public static UniTask ConfigureAwait(this UnityWebRequestAsyncOperation asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) - { - Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); - - var awaiter = new UnityWebRequestAsyncOperationConfiguredAwaiter(asyncOperation, progress, cancellation); - if (!awaiter.IsCompleted) - { - PlayerLoopHelper.AddAction(timing, awaiter); - } - return new UniTask(awaiter); - } - -#endif - public struct AsyncOperationAwaiter : ICriticalNotifyCompletion { AsyncOperation asyncOperation; Action continuationAction; - // UniTaskStatus status; public AsyncOperationAwaiter(AsyncOperation asyncOperation) { - this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; - this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; + this.asyncOperation = asyncOperation; this.continuationAction = null; } @@ -201,22 +50,6 @@ namespace UniRx.Async public void GetResult() { - //*/ if (status == UniTaskStatus.Succeeded) return; - /* - if (status == UniTaskStatus.Pending) - { - // first timing of call - if (asyncOperation.isDone) - { - status = UniTaskStatus.Succeeded; - } - else - { - Error.ThrowNotYetCompleted(); - } - } - */ - if (continuationAction != null) { asyncOperation.completed -= continuationAction; @@ -227,6 +60,7 @@ namespace UniRx.Async { asyncOperation = null; // remove reference. } + } public void OnCompleted(Action continuation) @@ -242,52 +76,77 @@ namespace UniRx.Async } } - class AsyncOperationConfiguredAwaiter : IAwaiter, IPlayerLoopItem + class AsyncOperationConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { + static readonly PromisePool pool = new PromisePool(); + AsyncOperation asyncOperation; IProgress progress; CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - public AsyncOperationConfiguredAwaiter(AsyncOperation asyncOperation, IProgress progress, CancellationToken cancellationToken) + UniTaskCompletionSourceCore core; + + AsyncOperationConfiguredSource() { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : asyncOperation.isDone ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; - if (this.status.IsCompleted()) return; - - this.asyncOperation = asyncOperation; - this.progress = progress; - this.cancellationToken = cancellationToken; - this.continuation = null; - - TaskTracker.TrackActiveTask(this, 2); } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; - - public void GetResult() + public static IUniTaskSource Create(AsyncOperation asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) { - if (status == UniTaskStatus.Succeeded) + if (cancellationToken.IsCancellationRequested) { - return; - } - else if (status == UniTaskStatus.Canceled) - { - Error.ThrowOperationCanceledException(); + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); } - Error.ThrowNotYetCompleted(); + var result = pool.TryRent() ?? new AsyncOperationConfiguredSource(); + + result.asyncOperation = asyncOperation; + result.progress = progress; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + + core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(UniTaskStatus.Canceled); + core.TrySetCanceled(cancellationToken); return false; } @@ -298,77 +157,71 @@ namespace UniRx.Async if (asyncOperation.isDone) { - InvokeContinuation(UniTaskStatus.Succeeded); + core.TrySetResult(AsyncUnit.Default); return false; } return true; } - void InvokeContinuation(UniTaskStatus status) + public void Reset() { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.progress = null; - this.asyncOperation = null; - - if (cont != null) cont.Invoke(); + core.Reset(); + asyncOperation = default; + progress = default; + cancellationToken = default; } - public void OnCompleted(Action continuation) + ~AsyncOperationConfiguredSource() { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } } } - public struct ResourceRequestAwaiter : IAwaiter +# endregion + +#region ResourceRequest + + public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + return new ResourceRequestAwaiter(asyncOperation); + } + + public static UniTask ToUniTask(this ResourceRequest asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new UniTask(ResourceRequestConfiguredSource.Create(asyncOperation, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token); + } + + public static UniTask ConfigureAwait(this ResourceRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new UniTask(ResourceRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellation, out var token), token); + } + + public struct ResourceRequestAwaiter : ICriticalNotifyCompletion { ResourceRequest asyncOperation; Action continuationAction; - UniTaskStatus status; UnityEngine.Object result; public ResourceRequestAwaiter(ResourceRequest asyncOperation) { - this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; - this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; - this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null; + this.asyncOperation = asyncOperation; this.continuationAction = null; + this.result = default; } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; + public bool IsCompleted => asyncOperation.isDone; public UnityEngine.Object GetResult() { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Pending) - { - // first timing of call - if (asyncOperation.isDone) - { - status = UniTaskStatus.Succeeded; - } - else - { - Error.ThrowNotYetCompleted(); - } - } - - this.result = asyncOperation.asset; - if (continuationAction != null) { asyncOperation.completed -= continuationAction; @@ -383,8 +236,6 @@ namespace UniRx.Async return this.result; } - void IAwaiter.GetResult() => GetResult(); - public void OnCompleted(Action continuation) { UnsafeOnCompleted(continuation); @@ -393,108 +244,11 @@ namespace UniRx.Async public void UnsafeOnCompleted(Action continuation) { Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction); - continuationAction = continuation.AsFuncOfT(); + continuationAction = continuation.AsFuncOfT(); // allocate delegate. asyncOperation.completed += continuationAction; } } - class ResourceRequestConfiguredAwaiter : IAwaiter, IPlayerLoopItem - { - ResourceRequest asyncOperation; - IProgress progress; - CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - UnityEngine.Object result; - - public ResourceRequestConfiguredAwaiter(ResourceRequest asyncOperation, IProgress progress, CancellationToken cancellationToken) - { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : asyncOperation.isDone ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; - - if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset; - if (this.status.IsCompleted()) return; - - this.asyncOperation = asyncOperation; - this.progress = progress; - this.cancellationToken = cancellationToken; - this.continuation = null; - this.result = null; - - TaskTracker.TrackActiveTask(this, 2); - } - - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; - void IAwaiter.GetResult() => GetResult(); - - public UnityEngine.Object GetResult() - { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Canceled) - { - Error.ThrowOperationCanceledException(); - } - - return Error.ThrowNotYetCompleted(); - } - - public bool MoveNext() - { - if (cancellationToken.IsCancellationRequested) - { - InvokeContinuation(UniTaskStatus.Canceled); - return false; - } - - if (progress != null) - { - progress.Report(asyncOperation.progress); - } - - if (asyncOperation.isDone) - { - this.result = asyncOperation.asset; - InvokeContinuation(UniTaskStatus.Succeeded); - return false; - } - - return true; - } - - void InvokeContinuation(UniTaskStatus status) - { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.progress = null; - this.asyncOperation = null; - - if (cont != null) cont.Invoke(); - } - - public void OnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } - } - - - - // TODO: try to check API. class ResourceRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { static readonly PromisePool pool = new PromisePool(); @@ -523,12 +277,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; -#if UNITY_EDITOR - // TODO:capture??? - //var capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(2); - // TODO:Add ActiveTask? - // TaskTracker.TrackActiveTask( -#endif + TaskTracker2.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -540,6 +289,8 @@ namespace UniRx.Async { try { + TaskTracker2.RemoveTracking(this); + return core.GetResult(token); } finally @@ -572,8 +323,6 @@ namespace UniRx.Async { if (cancellationToken.IsCancellationRequested) { - // TODO:Remove Tracking - // TaskTracker.RemoveTracking(); core.TrySetCanceled(cancellationToken); return false; } @@ -585,8 +334,6 @@ namespace UniRx.Async if (asyncOperation.isDone) { - // TODO:Remove Tracking - // TaskTracker.RemoveTracking(); core.TrySetResult(asyncOperation.asset); return false; } @@ -601,55 +348,57 @@ namespace UniRx.Async progress = default; cancellationToken = default; } + + ~ResourceRequestConfiguredSource() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } } +# endregion +#region AssetBundleRequest + public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + return new AssetBundleRequestAwaiter(asyncOperation); + } + public static UniTask ToUniTask(this AssetBundleRequest asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + return new UniTask(AssetBundleRequestConfiguredSource.Create(asyncOperation, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token); + } + public static UniTask ConfigureAwait(this AssetBundleRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + return new UniTask(AssetBundleRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellation, out var token), token); + } - - - - public struct AssetBundleRequestAwaiter : IAwaiter + public struct AssetBundleRequestAwaiter : ICriticalNotifyCompletion { AssetBundleRequest asyncOperation; Action continuationAction; - UniTaskStatus status; UnityEngine.Object result; public AssetBundleRequestAwaiter(AssetBundleRequest asyncOperation) { - this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; - this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; - this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null; + this.asyncOperation = asyncOperation; this.continuationAction = null; + this.result = default; } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; + public bool IsCompleted => asyncOperation.isDone; public UnityEngine.Object GetResult() { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Pending) - { - // first timing of call - if (asyncOperation.isDone) - { - status = UniTaskStatus.Succeeded; - } - else - { - Error.ThrowNotYetCompleted(); - } - } - - this.result = asyncOperation.asset; - if (continuationAction != null) { asyncOperation.completed -= continuationAction; @@ -664,8 +413,6 @@ namespace UniRx.Async return this.result; } - void IAwaiter.GetResult() => GetResult(); - public void OnCompleted(Action continuation) { UnsafeOnCompleted(continuation); @@ -674,59 +421,86 @@ namespace UniRx.Async public void UnsafeOnCompleted(Action continuation) { Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction); - continuationAction = continuation.AsFuncOfT(); + continuationAction = continuation.AsFuncOfT(); // allocate delegate. asyncOperation.completed += continuationAction; } } - class AssetBundleRequestConfiguredAwaiter : IAwaiter, IPlayerLoopItem + class AssetBundleRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { + static readonly PromisePool pool = new PromisePool(); + AssetBundleRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - UnityEngine.Object result; - public AssetBundleRequestConfiguredAwaiter(AssetBundleRequest asyncOperation, IProgress progress, CancellationToken cancellationToken) + UniTaskCompletionSourceCore core; + + AssetBundleRequestConfiguredSource() { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : asyncOperation.isDone ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; - if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset; - if (this.status.IsCompleted()) return; - - this.asyncOperation = asyncOperation; - this.progress = progress; - this.cancellationToken = cancellationToken; - this.continuation = null; - this.result = null; - - TaskTracker.TrackActiveTask(this, 2); } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; - void IAwaiter.GetResult() => GetResult(); - - public UnityEngine.Object GetResult() + public static IUniTaskSource Create(AssetBundleRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Canceled) + if (cancellationToken.IsCancellationRequested) { - Error.ThrowOperationCanceledException(); + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); } - return Error.ThrowNotYetCompleted(); + var result = pool.TryRent() ?? new AssetBundleRequestConfiguredSource(); + + result.asyncOperation = asyncOperation; + result.progress = progress; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public UnityEngine.Object GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + + return core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(UniTaskStatus.Canceled); + core.TrySetCanceled(cancellationToken); return false; } @@ -737,79 +511,71 @@ namespace UniRx.Async if (asyncOperation.isDone) { - this.result = asyncOperation.asset; - InvokeContinuation(UniTaskStatus.Succeeded); + core.TrySetResult(asyncOperation.asset); return false; } return true; } - void InvokeContinuation(UniTaskStatus status) + public void Reset() { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.progress = null; - this.asyncOperation = null; - - if (cont != null) cont.Invoke(); + core.Reset(); + asyncOperation = default; + progress = default; + cancellationToken = default; } - public void OnCompleted(Action continuation) + ~AssetBundleRequestConfiguredSource() { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } } } - public struct AssetBundleCreateRequestAwaiter : IAwaiter +# endregion + +#region AssetBundleCreateRequest + + public static AssetBundleCreateRequestAwaiter GetAwaiter(this AssetBundleCreateRequest asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + return new AssetBundleCreateRequestAwaiter(asyncOperation); + } + + public static UniTask ToUniTask(this AssetBundleCreateRequest asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new UniTask(AssetBundleCreateRequestConfiguredSource.Create(asyncOperation, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token); + } + + public static UniTask ConfigureAwait(this AssetBundleCreateRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new UniTask(AssetBundleCreateRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellation, out var token), token); + } + + public struct AssetBundleCreateRequestAwaiter : ICriticalNotifyCompletion { AssetBundleCreateRequest asyncOperation; Action continuationAction; - UniTaskStatus status; AssetBundle result; public AssetBundleCreateRequestAwaiter(AssetBundleCreateRequest asyncOperation) { - this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; - this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; - this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.assetBundle : null; + this.asyncOperation = asyncOperation; this.continuationAction = null; + this.result = default; } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; + public bool IsCompleted => asyncOperation.isDone; public AssetBundle GetResult() { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Pending) - { - // first timing of call - if (asyncOperation.isDone) - { - status = UniTaskStatus.Succeeded; - } - else - { - Error.ThrowNotYetCompleted(); - } - } - - this.result = asyncOperation.assetBundle; - if (continuationAction != null) { asyncOperation.completed -= continuationAction; @@ -824,8 +590,6 @@ namespace UniRx.Async return this.result; } - void IAwaiter.GetResult() => GetResult(); - public void OnCompleted(Action continuation) { UnsafeOnCompleted(continuation); @@ -834,59 +598,86 @@ namespace UniRx.Async public void UnsafeOnCompleted(Action continuation) { Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction); - continuationAction = continuation.AsFuncOfT(); + continuationAction = continuation.AsFuncOfT(); // allocate delegate. asyncOperation.completed += continuationAction; } } - class AssetBundleCreateRequestConfiguredAwaiter : IAwaiter, IPlayerLoopItem + class AssetBundleCreateRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { + static readonly PromisePool pool = new PromisePool(); + AssetBundleCreateRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - AssetBundle result; - public AssetBundleCreateRequestConfiguredAwaiter(AssetBundleCreateRequest asyncOperation, IProgress progress, CancellationToken cancellationToken) + UniTaskCompletionSourceCore core; + + AssetBundleCreateRequestConfiguredSource() { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : asyncOperation.isDone ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; - if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.assetBundle; - if (this.status.IsCompleted()) return; - - this.asyncOperation = asyncOperation; - this.progress = progress; - this.cancellationToken = cancellationToken; - this.continuation = null; - this.result = null; - - TaskTracker.TrackActiveTask(this, 2); } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; - void IAwaiter.GetResult() => GetResult(); - - public AssetBundle GetResult() + public static IUniTaskSource Create(AssetBundleCreateRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Canceled) + if (cancellationToken.IsCancellationRequested) { - Error.ThrowOperationCanceledException(); + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); } - return Error.ThrowNotYetCompleted(); + var result = pool.TryRent() ?? new AssetBundleCreateRequestConfiguredSource(); + + result.asyncOperation = asyncOperation; + result.progress = progress; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public AssetBundle GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + + return core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(UniTaskStatus.Canceled); + core.TrySetCanceled(cancellationToken); return false; } @@ -897,182 +688,72 @@ namespace UniRx.Async if (asyncOperation.isDone) { - this.result = asyncOperation.assetBundle; - InvokeContinuation(UniTaskStatus.Succeeded); + core.TrySetResult(asyncOperation.assetBundle); return false; } return true; } - void InvokeContinuation(UniTaskStatus status) + public void Reset() { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.progress = null; - this.asyncOperation = null; - - if (cont != null) cont.Invoke(); + core.Reset(); + asyncOperation = default; + progress = default; + cancellationToken = default; } - public void OnCompleted(Action continuation) + ~AssetBundleCreateRequestConfiguredSource() { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } - } -#if ENABLE_WWW - -#if UNITY_2018_3_OR_NEWER -#pragma warning disable CS0618 -#endif - - class WWWConfiguredAwaiter : IAwaiter, IPlayerLoopItem - { - WWW asyncOperation; - IProgress progress; - CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - - public WWWConfiguredAwaiter(WWW asyncOperation, IProgress progress, CancellationToken cancellationToken) - { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : asyncOperation.isDone ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; - - if (this.status.IsCompleted()) return; - - this.asyncOperation = asyncOperation; - this.progress = progress; - this.cancellationToken = cancellationToken; - this.continuation = null; - - TaskTracker.TrackActiveTask(this, 2); - } - - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; - - public void GetResult() - { - if (status == UniTaskStatus.Succeeded) + if (pool.TryReturn(this)) { - return; + GC.ReRegisterForFinalize(this); } - else if (status == UniTaskStatus.Canceled) - { - Error.ThrowOperationCanceledException(); - } - - Error.ThrowNotYetCompleted(); - } - - public bool MoveNext() - { - if (cancellationToken.IsCancellationRequested) - { - InvokeContinuation(UniTaskStatus.Canceled); - return false; - } - - if (progress != null) - { - progress.Report(asyncOperation.progress); - } - - if (asyncOperation.isDone) - { - InvokeContinuation(UniTaskStatus.Succeeded); - return false; - } - - return true; - } - - void InvokeContinuation(UniTaskStatus status) - { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.progress = null; - this.asyncOperation = null; - - if (cont != null) cont.Invoke(); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; } } -#if UNITY_2018_3_OR_NEWER -#pragma warning restore CS0618 -#endif - -#endif +# endregion #if ENABLE_UNITYWEBREQUEST +#region UnityWebRequestAsyncOperation - public struct UnityWebRequestAsyncOperationAwaiter : IAwaiter + public static UnityWebRequestAsyncOperationAwaiter GetAwaiter(this UnityWebRequestAsyncOperation asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + return new UnityWebRequestAsyncOperationAwaiter(asyncOperation); + } + + public static UniTask ToUniTask(this UnityWebRequestAsyncOperation asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new UniTask(UnityWebRequestAsyncOperationConfiguredSource.Create(asyncOperation, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token); + } + + public static UniTask ConfigureAwait(this UnityWebRequestAsyncOperation asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new UniTask(UnityWebRequestAsyncOperationConfiguredSource.Create(asyncOperation, timing, progress, cancellation, out var token), token); + } + + public struct UnityWebRequestAsyncOperationAwaiter : ICriticalNotifyCompletion { UnityWebRequestAsyncOperation asyncOperation; Action continuationAction; - UniTaskStatus status; UnityWebRequest result; public UnityWebRequestAsyncOperationAwaiter(UnityWebRequestAsyncOperation asyncOperation) { - this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending; - this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation; - this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.webRequest : null; + this.asyncOperation = asyncOperation; this.continuationAction = null; + this.result = default; } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; + public bool IsCompleted => asyncOperation.isDone; public UnityWebRequest GetResult() { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Pending) - { - // first timing of call - if (asyncOperation.isDone) - { - status = UniTaskStatus.Succeeded; - } - else - { - Error.ThrowNotYetCompleted(); - } - } - - this.result = asyncOperation.webRequest; - if (continuationAction != null) { asyncOperation.completed -= continuationAction; @@ -1084,12 +765,9 @@ namespace UniRx.Async asyncOperation = null; // remove reference. } - return this.result; } - void IAwaiter.GetResult() => GetResult(); - public void OnCompleted(Action continuation) { UnsafeOnCompleted(continuation); @@ -1098,59 +776,86 @@ namespace UniRx.Async public void UnsafeOnCompleted(Action continuation) { Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction); - continuationAction = continuation.AsFuncOfT(); + continuationAction = continuation.AsFuncOfT(); // allocate delegate. asyncOperation.completed += continuationAction; } } - class UnityWebRequestAsyncOperationConfiguredAwaiter : IAwaiter, IPlayerLoopItem + class UnityWebRequestAsyncOperationConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem { + static readonly PromisePool pool = new PromisePool(); + UnityWebRequestAsyncOperation asyncOperation; IProgress progress; CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - UnityWebRequest result; - public UnityWebRequestAsyncOperationConfiguredAwaiter(UnityWebRequestAsyncOperation asyncOperation, IProgress progress, CancellationToken cancellationToken) + UniTaskCompletionSourceCore core; + + UnityWebRequestAsyncOperationConfiguredSource() { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : asyncOperation.isDone ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; - if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.webRequest; - if (this.status.IsCompleted()) return; - - this.asyncOperation = asyncOperation; - this.progress = progress; - this.cancellationToken = cancellationToken; - this.continuation = null; - this.result = null; - - TaskTracker.TrackActiveTask(this, 2); } - public bool IsCompleted => status.IsCompleted(); - public UniTaskStatus Status => status; - void IAwaiter.GetResult() => GetResult(); - - public UnityWebRequest GetResult() + public static IUniTaskSource Create(UnityWebRequestAsyncOperation asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) { - if (status == UniTaskStatus.Succeeded) return this.result; - - if (status == UniTaskStatus.Canceled) + if (cancellationToken.IsCancellationRequested) { - Error.ThrowOperationCanceledException(); + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); } - return Error.ThrowNotYetCompleted(); + var result = pool.TryRent() ?? new UnityWebRequestAsyncOperationConfiguredSource(); + + result.asyncOperation = asyncOperation; + result.progress = progress; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public UnityWebRequest GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + + return core.GetResult(token); + } + finally + { + pool.TryReturn(this); + } + } + + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - InvokeContinuation(UniTaskStatus.Canceled); + core.TrySetCanceled(cancellationToken); return false; } @@ -1161,43 +866,32 @@ namespace UniRx.Async if (asyncOperation.isDone) { - this.result = asyncOperation.webRequest; - InvokeContinuation(UniTaskStatus.Succeeded); + core.TrySetResult(asyncOperation.webRequest); return false; } return true; } - void InvokeContinuation(UniTaskStatus status) + public void Reset() { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.progress = null; - this.asyncOperation = null; - - if (cont != null) cont.Invoke(); + core.Reset(); + asyncOperation = default; + progress = default; + cancellationToken = default; } - public void OnCompleted(Action continuation) + ~UnityWebRequestAsyncOperationConfiguredSource() { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } } } +# endregion #endif + } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.tt b/Assets/UniRx.Async/UnityAsyncExtensions.tt new file mode 100644 index 0000000..e4d6e27 --- /dev/null +++ b/Assets/UniRx.Async/UnityAsyncExtensions.tt @@ -0,0 +1,234 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +<# + var types = new (string typeName, string returnType, string returnField)[] + { + ("AsyncOperation", "void", null), + ("ResourceRequest", "UnityEngine.Object", "asset"), + ("AssetBundleRequest", "UnityEngine.Object", "asset"), // allAssets? + ("AssetBundleCreateRequest", "AssetBundle", "assetBundle"), + ("UnityWebRequestAsyncOperation", "UnityWebRequest", "webRequest") // -> #if ENABLE_UNITYWEBREQUEST + }; + + Func ToUniTaskReturnType = x => (x == "void") ? "UniTask" : $"UniTask<{x}>"; + Func ToIUniTaskSourceReturnType = x => (x == "void") ? "IUniTaskSource" : $"IUniTaskSource<{x}>"; + Func<(string typeName, string returnType, string returnField), bool> IsVoid = x => x.returnType == "void"; +#> +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +using System; +using System.Runtime.CompilerServices; +using System.Threading; +using UnityEngine; +using UniRx.Async.Internal; +#if ENABLE_UNITYWEBREQUEST +using UnityEngine.Networking; +#endif + +namespace UniRx.Async +{ + public static partial class UnityAsyncExtensions + { +<# foreach(var t in types) { #> +<# if(t.returnType == "UnityWebRequest") { #> +#if ENABLE_UNITYWEBREQUEST +<# } #> +#region <#= t.typeName #> + + public static <#= t.typeName #>Awaiter GetAwaiter(this <#= t.typeName #> asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + return new <#= t.typeName #>Awaiter(asyncOperation); + } + + public static <#= ToUniTaskReturnType(t.returnType) #> ToUniTask(this <#= t.typeName #> asyncOperation) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new <#= ToUniTaskReturnType(t.returnType) #>(<#= t.typeName #>ConfiguredSource.Create(asyncOperation, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token); + } + + public static <#= ToUniTaskReturnType(t.returnType) #> ConfigureAwait(this <#= t.typeName #> asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken)) + { + Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); + + return new <#= ToUniTaskReturnType(t.returnType) #>(<#= t.typeName #>ConfiguredSource.Create(asyncOperation, timing, progress, cancellation, out var token), token); + } + + public struct <#= t.typeName #>Awaiter : ICriticalNotifyCompletion + { + <#= t.typeName #> asyncOperation; + Action continuationAction; +<# if (!IsVoid(t)) { #> + <#= t.returnType #> result; +<# } #> + + public <#= t.typeName #>Awaiter(<#= t.typeName #> asyncOperation) + { + this.asyncOperation = asyncOperation; + this.continuationAction = null; +<# if (!IsVoid(t)) { #> + this.result = default; +<# } #> + } + + public bool IsCompleted => asyncOperation.isDone; + + public <#= t.returnType #> GetResult() + { + if (continuationAction != null) + { + asyncOperation.completed -= continuationAction; + asyncOperation = null; // remove reference. + continuationAction = null; + } + else + { + asyncOperation = null; // remove reference. + } + +<# if (!IsVoid(t)) { #> + return this.result; +<# } #> + } + + public void OnCompleted(Action continuation) + { + UnsafeOnCompleted(continuation); + } + + public void UnsafeOnCompleted(Action continuation) + { + Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction); + continuationAction = continuation.AsFuncOfT(); // allocate delegate. + asyncOperation.completed += continuationAction; + } + } + + class <#= t.typeName #>ConfiguredSource : <#= ToIUniTaskSourceReturnType(t.returnType) #>, IPlayerLoopItem, IPromisePoolItem + { + static readonly PromisePool<<#= t.typeName #>ConfiguredSource> pool = new PromisePool<<#= t.typeName #>ConfiguredSource>(); + + <#= t.typeName #> asyncOperation; + IProgress progress; + CancellationToken cancellationToken; + + UniTaskCompletionSourceCore<<#= IsVoid(t) ? "AsyncUnit" : t.returnType #>> core; + + <#= t.typeName #>ConfiguredSource() + { + + } + + public static <#= ToIUniTaskSourceReturnType(t.returnType) #> Create(<#= t.typeName #> asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource<#= IsVoid(t) ? "" : $"<{t.returnType}>" #>.CreateFromCanceled(cancellationToken, out token); + } + + var result = pool.TryRent() ?? new <#= t.typeName #>ConfiguredSource(); + + result.asyncOperation = asyncOperation; + result.progress = progress; + result.cancellationToken = cancellationToken; + + TaskTracker2.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public <#= t.returnType #> GetResult(short token) + { + try + { + TaskTracker2.RemoveTracking(this); + +<# if (!IsVoid(t)) { #> + return core.GetResult(token); +<# } else { #> + core.GetResult(token); +<# } #> + } + finally + { + pool.TryReturn(this); + } + } + +<# if (!IsVoid(t)) { #> + void IUniTaskSource.GetResult(short token) + { + GetResult(token); + } +<# } #> + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + return false; + } + + if (progress != null) + { + progress.Report(asyncOperation.progress); + } + + if (asyncOperation.isDone) + { + core.TrySetResult(<#= IsVoid(t) ? "AsyncUnit.Default" : $"asyncOperation.{t.returnField}" #>); + return false; + } + + return true; + } + + public void Reset() + { + core.Reset(); + asyncOperation = default; + progress = default; + cancellationToken = default; + } + + ~<#= t.typeName #>ConfiguredSource() + { + if (pool.TryReturn(this)) + { + GC.ReRegisterForFinalize(this); + } + } + } + +# endregion +<# if(t.returnType == "UnityWebRequest") { #> +#endif +<# } #> + +<# } #> + } +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs index 45d9da9..09658f7 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs @@ -1,14 +1,11 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; -using System.Runtime.CompilerServices; using System.Threading; using UniRx.Async.Internal; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; -using UniRx.Async.Triggers; namespace UniRx.Async { @@ -168,86 +165,72 @@ namespace UniRx.Async public interface IAsyncClickEventHandler : IDisposable { UniTask OnClickAsync(); - UniTask OnClickAsyncSuppressCancellationThrow(); } public interface IAsyncValueChangedEventHandler : IDisposable { UniTask OnValueChangedAsync(); - UniTask<(bool IsCanceled, T Result)> OnValueChangedAsyncSuppressCancellationThrow(); } public interface IAsyncEndEditEventHandler : IDisposable { UniTask OnEndEditAsync(); - UniTask<(bool IsCanceled, T Result)> OnEndEditAsyncSuppressCancellationThrow(); } - // event handler is reusable when callOnce = false. - public class AsyncUnityEventHandler : IAwaiter, IDisposable, IAsyncClickEventHandler + public class AsyncUnityEventHandler : IUniTaskSource, IDisposable, IAsyncClickEventHandler { static Action cancellationCallback = CancellationCallback; readonly UnityAction action; readonly UnityEvent unityEvent; - Action continuation; + + CancellationToken cancellationToken; CancellationTokenRegistration registration; bool isDisposed; bool callOnce; - UniTask? suppressCancellationThrowTask; + + UniTaskCompletionSourceCore core; public AsyncUnityEventHandler(UnityEvent unityEvent, CancellationToken cancellationToken, bool callOnce) { - this.callOnce = callOnce; - if (cancellationToken.IsCancellationRequested) { isDisposed = true; return; } - action = Invoke; - unityEvent.AddListener(action); + this.action = Invoke; this.unityEvent = unityEvent; + this.cancellationToken = cancellationToken; + this.callOnce = callOnce; + + unityEvent.AddListener(action); if (cancellationToken.CanBeCanceled) { registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); } - TaskTracker.TrackActiveTask(this, 3); + TaskTracker2.TrackActiveTask(this, 3); } public UniTask OnInvokeAsync() { - // zero allocation wait handler. - return new UniTask(this); - } - - public UniTask OnInvokeAsyncSuppressCancellationThrow() - { - if (suppressCancellationThrowTask == null) - { - suppressCancellationThrowTask = OnInvokeAsync().SuppressCancellationThrow(); - } - return suppressCancellationThrowTask.Value; + core.Reset(); + return new UniTask(this, core.Version); } void Invoke() { - var c = continuation; - continuation = null; - if (c != null) - { - c.Invoke(); - } + core.TrySetResult(AsyncUnit.Default); } static void CancellationCallback(object state) { var self = (AsyncUnityEventHandler)state; self.Dispose(); - self.Invoke(); // call continuation if exists yet(GetResult -> throw OperationCanceledException). + + self.core.TrySetCanceled(self.cancellationToken); } public void Dispose() @@ -255,7 +238,7 @@ namespace UniRx.Async if (!isDisposed) { isDisposed = true; - TaskTracker.RemoveTracking(this); + TaskTracker2.RemoveTracking(this); registration.Dispose(); if (unityEvent != null) { @@ -264,106 +247,96 @@ namespace UniRx.Async } } - bool IAwaiter.IsCompleted => isDisposed ? true : false; - UniTaskStatus IAwaiter.Status => isDisposed ? UniTaskStatus.Canceled : UniTaskStatus.Pending; - void IAwaiter.GetResult() - { - if (isDisposed) throw new OperationCanceledException(); - if (callOnce) Dispose(); - } - - void INotifyCompletion.OnCompleted(Action action) - { - ((ICriticalNotifyCompletion)this).UnsafeOnCompleted(action); - } - - void ICriticalNotifyCompletion.UnsafeOnCompleted(Action action) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = action; - } - - // Interface events. - UniTask IAsyncClickEventHandler.OnClickAsync() { return OnInvokeAsync(); } - UniTask IAsyncClickEventHandler.OnClickAsyncSuppressCancellationThrow() + void IUniTaskSource.GetResult(short token) { - return OnInvokeAsyncSuppressCancellationThrow(); + try + { + core.GetResult(token); + } + finally + { + if (callOnce) + { + Dispose(); + } + } + } + + UniTaskStatus IUniTaskSource.GetStatus(short token) + { + return core.GetStatus(token); + } + + UniTaskStatus IUniTaskSource.UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } } - // event handler is reusable when callOnce = false. - public class AsyncUnityEventHandler : IAwaiter, IDisposable, IAsyncValueChangedEventHandler, IAsyncEndEditEventHandler + public class AsyncUnityEventHandler : IUniTaskSource, IDisposable, IAsyncValueChangedEventHandler, IAsyncEndEditEventHandler { static Action cancellationCallback = CancellationCallback; readonly UnityAction action; readonly UnityEvent unityEvent; - Action continuation; + + CancellationToken cancellationToken; CancellationTokenRegistration registration; bool isDisposed; - T eventValue; bool callOnce; - UniTask<(bool, T)>? suppressCancellationThrowTask; + + UniTaskCompletionSourceCore core; public AsyncUnityEventHandler(UnityEvent unityEvent, CancellationToken cancellationToken, bool callOnce) { - this.callOnce = callOnce; - if (cancellationToken.IsCancellationRequested) { isDisposed = true; return; } - action = Invoke; - unityEvent.AddListener(action); + this.action = Invoke; this.unityEvent = unityEvent; + this.cancellationToken = cancellationToken; + this.callOnce = callOnce; + + unityEvent.AddListener(action); if (cancellationToken.CanBeCanceled) { registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); } - TaskTracker.TrackActiveTask(this, 3); + TaskTracker2.TrackActiveTask(this, 3); } public UniTask OnInvokeAsync() { - // zero allocation wait handler. - return new UniTask(this); + core.Reset(); + return new UniTask(this, core.Version); } - public UniTask<(bool IsCanceled, T Result)> OnInvokeAsyncSuppressCancellationThrow() + void Invoke(T result) { - if (suppressCancellationThrowTask == null) - { - suppressCancellationThrowTask = OnInvokeAsync().SuppressCancellationThrow(); - } - return suppressCancellationThrowTask.Value; - } - - void Invoke(T value) - { - this.eventValue = value; - - var c = continuation; - continuation = null; - if (c != null) - { - c.Invoke(); - } + core.TrySetResult(result); } static void CancellationCallback(object state) { var self = (AsyncUnityEventHandler)state; self.Dispose(); - self.Invoke(default(T)); // call continuation if exists yet(GetResult -> throw OperationCanceledException). + + self.core.TrySetCanceled(self.cancellationToken); } public void Dispose() @@ -371,7 +344,7 @@ namespace UniRx.Async if (!isDisposed) { isDisposed = true; - TaskTracker.RemoveTracking(this); + TaskTracker2.RemoveTracking(this); registration.Dispose(); if (unityEvent != null) { @@ -380,55 +353,49 @@ namespace UniRx.Async } } - bool IAwaiter.IsCompleted => isDisposed ? true : false; - UniTaskStatus IAwaiter.Status => isDisposed ? UniTaskStatus.Canceled : UniTaskStatus.Pending; - - T IAwaiter.GetResult() - { - if (isDisposed) throw new OperationCanceledException(); - if (callOnce) Dispose(); - return eventValue; - } - - void IAwaiter.GetResult() - { - if (isDisposed) throw new OperationCanceledException(); - if (callOnce) Dispose(); - } - - void INotifyCompletion.OnCompleted(Action action) - { - ((ICriticalNotifyCompletion)this).UnsafeOnCompleted(action); - } - - void ICriticalNotifyCompletion.UnsafeOnCompleted(Action action) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = action; - } - - // Interface events. - UniTask IAsyncValueChangedEventHandler.OnValueChangedAsync() { return OnInvokeAsync(); } - UniTask<(bool IsCanceled, T Result)> IAsyncValueChangedEventHandler.OnValueChangedAsyncSuppressCancellationThrow() - { - return OnInvokeAsyncSuppressCancellationThrow(); - } - UniTask IAsyncEndEditEventHandler.OnEndEditAsync() { return OnInvokeAsync(); } - UniTask<(bool IsCanceled, T Result)> IAsyncEndEditEventHandler.OnEndEditAsyncSuppressCancellationThrow() + T IUniTaskSource.GetResult(short token) { - return OnInvokeAsyncSuppressCancellationThrow(); + try + { + return core.GetResult(token); + } + finally + { + if (callOnce) + { + Dispose(); + } + } + } + + void IUniTaskSource.GetResult(short token) + { + ((IUniTaskSource)this).GetResult(token); + } + + UniTaskStatus IUniTaskSource.GetStatus(short token) + { + return core.GetStatus(token); + } + + UniTaskStatus IUniTaskSource.UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } } -} - -#endif \ No newline at end of file +} \ No newline at end of file From b8d1a092248cd42dd0b6e1ad297ce7d18f112713 Mon Sep 17 00:00:00 2001 From: neuecc Date: Tue, 5 May 2020 04:08:53 +0900 Subject: [PATCH 014/173] complete implementation(triggers and etc...) --- Assets/Tests/AsyncTest.cs | 27 +- Assets/Tests/Editor/AsyncTestEditor.cs | 25 +- .../CancellationTokenSourceExtensions.cs | 6 +- .../Editor/UniTaskTrackerTreeView.cs | 2 +- .../Editor/UniTaskTrackerWindow.cs | 197 - .../UniRx.Async/EnumeratorAsyncExtensions.cs | 4 +- Assets/UniRx.Async/IUniTaskSource.cs | 8 +- Assets/UniRx.Async/Internal/ArrayPoolUtil.cs | 7 +- .../Internal/CancellationTokenHelper.cs | 32 - .../Internal/CancellationTokenHelper.cs.meta | 11 - Assets/UniRx.Async/Internal/MinimumQueue.cs | 11 +- Assets/UniRx.Async/Internal/PromiseHelper.cs | 34 - .../Internal/PromiseHelper.cs.meta | 11 - Assets/UniRx.Async/Internal/TaskTracker.cs | 142 +- .../Triggers/AsyncAnimatorTrigger.cs | 54 - .../Triggers/AsyncAnimatorTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncAwakeTrigger.cs | 30 +- .../Triggers/AsyncBeginDragTrigger.cs | 41 - .../Triggers/AsyncBeginDragTrigger.cs.meta | 11 - .../Triggers/AsyncCancelTrigger.cs | 41 - .../Triggers/AsyncCancelTrigger.cs.meta | 11 - .../AsyncCanvasGroupChangedTrigger.cs | 41 - .../AsyncCanvasGroupChangedTrigger.cs.meta | 11 - .../Triggers/AsyncCollision2DTrigger.cs | 69 - .../Triggers/AsyncCollision2DTrigger.cs.meta | 11 - .../Triggers/AsyncCollisionTrigger.cs | 69 - .../Triggers/AsyncCollisionTrigger.cs.meta | 11 - .../Triggers/AsyncDeselectTrigger.cs | 41 - .../Triggers/AsyncDeselectTrigger.cs.meta | 11 - .../Triggers/AsyncDestroyTrigger.cs | 95 +- .../UniRx.Async/Triggers/AsyncDragTrigger.cs | 41 - .../Triggers/AsyncDragTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncDropTrigger.cs | 41 - .../Triggers/AsyncDropTrigger.cs.meta | 11 - .../Triggers/AsyncEnableDisableTrigger.cs | 55 - .../AsyncEnableDisableTrigger.cs.meta | 11 - .../Triggers/AsyncEndDragTrigger.cs | 41 - .../Triggers/AsyncEndDragTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncEventTrigger.cs | 264 - .../Triggers/AsyncEventTrigger.cs.meta | 11 - .../Triggers/AsyncFixedUpdateTrigger.cs | 41 - .../Triggers/AsyncFixedUpdateTrigger.cs.meta | 11 - .../AsyncInitializePotentialDragTrigger.cs | 41 - ...syncInitializePotentialDragTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncJointTrigger.cs | 55 - .../Triggers/AsyncJointTrigger.cs.meta | 11 - .../Triggers/AsyncLateUpdateTrigger.cs | 41 - .../Triggers/AsyncLateUpdateTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncMouseTrigger.cs | 129 - .../Triggers/AsyncMouseTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncMoveTrigger.cs | 41 - .../Triggers/AsyncMoveTrigger.cs.meta | 11 - .../Triggers/AsyncParticleTrigger.cs | 41 - .../Triggers/AsyncParticleTrigger.cs.meta | 11 - .../Triggers/AsyncPointerClickTrigger.cs | 41 - .../Triggers/AsyncPointerClickTrigger.cs.meta | 11 - .../Triggers/AsyncPointerDownTrigger.cs | 41 - .../Triggers/AsyncPointerDownTrigger.cs.meta | 11 - .../Triggers/AsyncPointerEnterTrigger.cs | 41 - .../Triggers/AsyncPointerEnterTrigger.cs.meta | 11 - .../Triggers/AsyncPointerExitTrigger.cs | 41 - .../Triggers/AsyncPointerExitTrigger.cs.meta | 11 - .../Triggers/AsyncPointerUpTrigger.cs | 41 - .../Triggers/AsyncPointerUpTrigger.cs.meta | 11 - .../Triggers/AsyncRectTransformTrigger.cs | 55 - .../AsyncRectTransformTrigger.cs.meta | 11 - .../Triggers/AsyncScrollTrigger.cs | 41 - .../Triggers/AsyncScrollTrigger.cs.meta | 11 - .../Triggers/AsyncSelectTrigger.cs | 41 - .../Triggers/AsyncSelectTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncStartTrigger.cs | 33 +- .../Triggers/AsyncSubmitTrigger.cs | 41 - .../Triggers/AsyncSubmitTrigger.cs.meta | 11 - .../Triggers/AsyncTransformChangedTrigger.cs | 69 - .../AsyncTransformChangedTrigger.cs.meta | 11 - .../Triggers/AsyncTrigger2DTrigger.cs | 69 - .../Triggers/AsyncTrigger2DTrigger.cs.meta | 11 - .../UniRx.Async/Triggers/AsyncTriggerBase.cs | 524 +- .../Triggers/AsyncTriggerExtensions.cs | 440 +- .../Triggers/AsyncTriggerTrigger.cs | 69 - .../Triggers/AsyncTriggerTrigger.cs.meta | 11 - .../Triggers/AsyncUpdateSelectedTrigger.cs | 41 - .../AsyncUpdateSelectedTrigger.cs.meta | 11 - .../Triggers/AsyncUpdateTrigger.cs | 200 - .../Triggers/AsyncUpdateTrigger.cs.meta | 11 - .../Triggers/AsyncVisibleTrigger.cs | 55 - .../Triggers/AsyncVisibleTrigger.cs.meta | 11 - .../Triggers/MonoBehaviourMessagesTriggers.cs | 4525 +++++++++++++++++ .../Triggers/MonoBehaviourMessagesTriggers.tt | 186 + Assets/UniRx.Async/UniTask.Delay.cs | 16 +- Assets/UniRx.Async/UniTask.WaitUntil.cs | 16 +- .../UniRx.Async/UniTask.WhenAll.Generated.cs | 56 +- Assets/UniRx.Async/UniTask.WhenAll.cs | 12 +- .../UniRx.Async/UniTask.WhenAny.Generated.cs | 56 +- Assets/UniRx.Async/UniTask.WhenAny.cs | 16 +- Assets/UniRx.Async/UniTaskCompletionSource.cs | 20 +- .../UniRx.Async/UnityAsyncExtensions.Jobs.cs | 137 +- Assets/UniRx.Async/UnityAsyncExtensions.cs | 20 +- Assets/UniRx.Async/UnityAsyncExtensions.tt | 4 +- .../UniRx.Async/UnityAsyncExtensions.uGUI.cs | 8 +- 100 files changed, 5364 insertions(+), 3794 deletions(-) delete mode 100644 Assets/UniRx.Async/Internal/CancellationTokenHelper.cs delete mode 100644 Assets/UniRx.Async/Internal/CancellationTokenHelper.cs.meta delete mode 100644 Assets/UniRx.Async/Internal/PromiseHelper.cs delete mode 100644 Assets/UniRx.Async/Internal/PromiseHelper.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs.meta delete mode 100644 Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs delete mode 100644 Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs.meta create mode 100644 Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs create mode 100644 Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt diff --git a/Assets/Tests/AsyncTest.cs b/Assets/Tests/AsyncTest.cs index 248ebad..12546a8 100644 --- a/Assets/Tests/AsyncTest.cs +++ b/Assets/Tests/AsyncTest.cs @@ -101,12 +101,12 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (a2, b2, c2) = await UniTask.WhenAll(a, b, c); a2.Should().Be(999); b2.Should().Be(AsyncUnit.Default); - c2.Should().Be(99); + c2.Should().Be(AsyncUnit.Default); }); [UnityTest] @@ -114,14 +114,11 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (win, a2, b2, c2) = await UniTask.WhenAny(a, b, c); win.Should().Be(0); - a2.hasResult.Should().Be(true); - a2.result0.Should().Be(999); - b2.hasResult.Should().Be(false); - c2.hasResult.Should().Be(false); + a2.Should().Be(999); }); [UnityTest] @@ -151,7 +148,7 @@ namespace UniRx.AsyncTests { bool t = false; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = true).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = true).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntil(() => t, PlayerLoopTiming.EarlyUpdate); @@ -165,7 +162,7 @@ namespace UniRx.AsyncTests { bool t = true; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = false).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = false).Forget(); var startFrame = Time.frameCount; await UniTask.WaitWhile(() => t, PlayerLoopTiming.EarlyUpdate); @@ -179,7 +176,7 @@ namespace UniRx.AsyncTests { var v = new MyMyClass { MyProperty = 99 }; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => v.MyProperty = 1000).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = 1000).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntilValueChanged(v, x => x.MyProperty, PlayerLoopTiming.EarlyUpdate); @@ -269,10 +266,10 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); var first = Time.frameCount; - var (canceled, value) = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); + var canceled = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); (Time.frameCount - first).Should().Be(11); // 10 frame canceled canceled.Should().Be(true); @@ -283,12 +280,12 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); bool occur = false; try { - var value = await UniTask.DelayFrame(100, cancellationToken: cts.Token); + await UniTask.DelayFrame(100, cancellationToken: cts.Token); } catch (OperationCanceledException) { @@ -407,7 +404,7 @@ namespace UniRx.AsyncTests completedTaskObserver.OnCompletedCalled.Should().BeTrue(); completedTaskObserver.OnErrorCalled.Should().BeFalse(); - var delayFrameTaskObserver = new ToObservableObserver(); + var delayFrameTaskObserver = new ToObservableObserver(); UniTask.DelayFrame(1).ToObservable().Subscribe(delayFrameTaskObserver); delayFrameTaskObserver.OnNextCalled.Should().BeFalse(); delayFrameTaskObserver.OnCompletedCalled.Should().BeFalse(); diff --git a/Assets/Tests/Editor/AsyncTestEditor.cs b/Assets/Tests/Editor/AsyncTestEditor.cs index a86271f..69720f4 100644 --- a/Assets/Tests/Editor/AsyncTestEditor.cs +++ b/Assets/Tests/Editor/AsyncTestEditor.cs @@ -101,12 +101,12 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (a2, b2, c2) = await UniTask.WhenAll(a, b, c); a2.Should().Be(999); b2.Should().Be(AsyncUnit.Default); - c2.Should().Be(99); + c2.Should().Be(AsyncUnit.Default); }); [UnityTest] @@ -114,14 +114,11 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (win, a2, b2, c2) = await UniTask.WhenAny(a, b, c); win.Should().Be(0); - a2.hasResult.Should().Be(true); - a2.result0.Should().Be(999); - b2.hasResult.Should().Be(false); - c2.hasResult.Should().Be(false); + a2.Should().Be(999); }); [UnityTest] @@ -153,7 +150,7 @@ namespace UniRx.AsyncTests await UniTask.Yield(PlayerLoopTiming.PostLateUpdate); - UniTask.DelayFrame(10,PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = true).Forget(); + UniTask.DelayFrame(10,PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = true).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntil(() => t, PlayerLoopTiming.EarlyUpdate); @@ -167,7 +164,7 @@ namespace UniRx.AsyncTests { bool t = true; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = false).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = false).Forget(); var startFrame = Time.frameCount; await UniTask.WaitWhile(() => t, PlayerLoopTiming.EarlyUpdate); @@ -181,7 +178,7 @@ namespace UniRx.AsyncTests { var v = new MyMyClass { MyProperty = 99 }; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => v.MyProperty = 1000).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = 1000).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntilValueChanged(v, x => x.MyProperty, PlayerLoopTiming.EarlyUpdate); @@ -271,10 +268,10 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); var first = Time.frameCount; - var (canceled, value) = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); + var canceled = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); (Time.frameCount - first).Should().Be(11); // 10 frame canceled canceled.Should().Be(true); @@ -285,12 +282,12 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); bool occur = false; try { - var value = await UniTask.DelayFrame(100, cancellationToken: cts.Token); + await UniTask.DelayFrame(100, cancellationToken: cts.Token); } catch (OperationCanceledException) { diff --git a/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs b/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs index 96cc03b..4b943b0 100644 --- a/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs +++ b/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs @@ -40,7 +40,11 @@ namespace UniRx.Async public static void RegisterRaiseCancelOnDestroy(this CancellationTokenSource cts, GameObject gameObject) { var trigger = gameObject.GetAsyncDestroyTrigger(); - trigger.AddCancellationTriggerOnDestroy(cts); + trigger.CancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var cts2 = (CancellationTokenSource)state; + cts2.Cancel(); + }, cts); } } } diff --git a/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs b/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs index 7e5e3cd..661b4c0 100644 --- a/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs +++ b/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs @@ -132,7 +132,7 @@ namespace UniRx.Async.Editor var children = new List(); - TaskTracker2.ForEachActiveTask((trackingId, awaiterType, status, created, stackTrace) => + TaskTracker.ForEachActiveTask((trackingId, awaiterType, status, created, stackTrace) => { children.Add(new UniTaskTrackerViewItem(trackingId) { TaskType = awaiterType, Status = status.ToString(), Elapsed = (DateTime.UtcNow - created).TotalSeconds.ToString("00.00"), Position = stackTrace }); }); diff --git a/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs b/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs index f35e1f8..9f5447e 100644 --- a/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs +++ b/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs @@ -12,7 +12,6 @@ using UniRx.Async.Internal; namespace UniRx.Async.Editor { - // TODO:Remove public class UniTaskTrackerWindow : EditorWindow { static int interval; @@ -171,202 +170,6 @@ namespace UniRx.Async.Editor static GUIStyle detailsStyle; Vector2 detailsScroll; - void RenderDetailsPanel() - { - if (detailsStyle == null) - { - detailsStyle = new GUIStyle(EditorStyles.wordWrappedLabel); - detailsStyle.wordWrap = false; - detailsStyle.stretchHeight = true; - detailsStyle.margin.right = 15; - } - - string message = ""; - var selected = treeView.state.selectedIDs; - if (selected.Count > 0) - { - var first = selected[0]; - var item = treeView.CurrentBindingItems.FirstOrDefault(x => x.id == first) as UniTaskTrackerViewItem; - if (item != null) - { - message = item.Position; - } - } - - detailsScroll = EditorGUILayout.BeginScrollView(this.detailsScroll, EmptyLayoutOption); - var vector = detailsStyle.CalcSize(new GUIContent(message)); - EditorGUILayout.SelectableLabel(message, detailsStyle, new GUILayoutOption[] - { - GUILayout.ExpandHeight(true), - GUILayout.ExpandWidth(true), - GUILayout.MinWidth(vector.x), - GUILayout.MinHeight(vector.y) - }); - EditorGUILayout.EndScrollView(); - } - - #endregion - } - - public class UniTaskTrackerWindow2 : EditorWindow - { - static int interval; - - static UniTaskTrackerWindow2 window; - - // TODO:Remove 2 - [MenuItem("Window/UniTask Tracker 2")] - public static void OpenWindow() - { - if (window != null) - { - window.Close(); - } - - // will called OnEnable(singleton instance will be set). - GetWindow("UniTask Tracker").Show(); - } - - static readonly GUILayoutOption[] EmptyLayoutOption = new GUILayoutOption[0]; - - UniTaskTrackerTreeView treeView; - object splitterState; - - void OnEnable() - { - window = this; // set singleton. - splitterState = SplitterGUILayout.CreateSplitterState(new float[] { 75f, 25f }, new int[] { 32, 32 }, null); - treeView = new UniTaskTrackerTreeView(); - TaskTracker2.EditorEnableState.EnableAutoReload = EditorPrefs.GetBool(TaskTracker2.EnableAutoReloadKey, false); - TaskTracker2.EditorEnableState.EnableTracking = EditorPrefs.GetBool(TaskTracker2.EnableTrackingKey, false); - TaskTracker2.EditorEnableState.EnableStackTrace = EditorPrefs.GetBool(TaskTracker2.EnableStackTraceKey, false); - } - - void OnGUI() - { - // Head - RenderHeadPanel(); - - // Splittable - SplitterGUILayout.BeginVerticalSplit(this.splitterState, EmptyLayoutOption); - { - // Column Tabble - RenderTable(); - - // StackTrace details - RenderDetailsPanel(); - } - SplitterGUILayout.EndVerticalSplit(); - } - - #region HeadPanel - - public static bool EnableAutoReload => TaskTracker2.EditorEnableState.EnableAutoReload; - public static bool EnableTracking => TaskTracker2.EditorEnableState.EnableTracking; - public static bool EnableStackTrace => TaskTracker2.EditorEnableState.EnableStackTrace; - static readonly GUIContent EnableAutoReloadHeadContent = EditorGUIUtility.TrTextContent("Enable AutoReload", "Reload automatically.", (Texture)null); - static readonly GUIContent ReloadHeadContent = EditorGUIUtility.TrTextContent("Reload", "Reload View.", (Texture)null); - static readonly GUIContent GCHeadContent = EditorGUIUtility.TrTextContent("GC.Collect", "Invoke GC.Collect.", (Texture)null); - static readonly GUIContent EnableTrackingHeadContent = EditorGUIUtility.TrTextContent("Enable Tracking", "Start to track async/await UniTask. Performance impact: low", (Texture)null); - static readonly GUIContent EnableStackTraceHeadContent = EditorGUIUtility.TrTextContent("Enable StackTrace", "Capture StackTrace when task is started. Performance impact: high", (Texture)null); - - // [Enable Tracking] | [Enable StackTrace] - void RenderHeadPanel() - { - EditorGUILayout.BeginVertical(EmptyLayoutOption); - EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, EmptyLayoutOption); - - if (GUILayout.Toggle(EnableAutoReload, EnableAutoReloadHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableAutoReload) - { - TaskTracker2.EditorEnableState.EnableAutoReload = !EnableAutoReload; - } - - if (GUILayout.Toggle(EnableTracking, EnableTrackingHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableTracking) - { - TaskTracker2.EditorEnableState.EnableTracking = !EnableTracking; - } - - if (GUILayout.Toggle(EnableStackTrace, EnableStackTraceHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableStackTrace) - { - TaskTracker2.EditorEnableState.EnableStackTrace = !EnableStackTrace; - } - - GUILayout.FlexibleSpace(); - - if (GUILayout.Button(ReloadHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption)) - { - TaskTracker2.CheckAndResetDirty(); - treeView.ReloadAndSort(); - Repaint(); - } - - if (GUILayout.Button(GCHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption)) - { - GC.Collect(0); - } - - EditorGUILayout.EndHorizontal(); - EditorGUILayout.EndVertical(); - } - - #endregion - - #region TableColumn - - Vector2 tableScroll; - GUIStyle tableListStyle; - - void RenderTable() - { - if (tableListStyle == null) - { - tableListStyle = new GUIStyle("CN Box"); - tableListStyle.margin.top = 0; - tableListStyle.padding.left = 3; - } - - EditorGUILayout.BeginVertical(tableListStyle, EmptyLayoutOption); - - this.tableScroll = EditorGUILayout.BeginScrollView(this.tableScroll, new GUILayoutOption[] - { - GUILayout.ExpandWidth(true), - GUILayout.MaxWidth(2000f) - }); - var controlRect = EditorGUILayout.GetControlRect(new GUILayoutOption[] - { - GUILayout.ExpandHeight(true), - GUILayout.ExpandWidth(true) - }); - - - treeView?.OnGUI(controlRect); - - EditorGUILayout.EndScrollView(); - EditorGUILayout.EndVertical(); - } - - private void Update() - { - if (EnableAutoReload) - { - if (interval++ % 120 == 0) - { - if (TaskTracker2.CheckAndResetDirty()) - { - treeView.ReloadAndSort(); - Repaint(); - } - } - } - } - - #endregion - - #region Details - - static GUIStyle detailsStyle; - Vector2 detailsScroll; - void RenderDetailsPanel() { if (detailsStyle == null) diff --git a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs index f5f4b33..4c66bbb 100644 --- a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs +++ b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs @@ -53,7 +53,7 @@ namespace UniRx.Async result.innerEnumerator = ConsumeEnumerator(innerEnumerator); result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -65,7 +65,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/IUniTaskSource.cs b/Assets/UniRx.Async/IUniTaskSource.cs index 2aa12a4..d346b36 100644 --- a/Assets/UniRx.Async/IUniTaskSource.cs +++ b/Assets/UniRx.Async/IUniTaskSource.cs @@ -35,28 +35,28 @@ namespace UniRx.Async public static class UniTaskStatusExtensions { - /// != Pending. + /// status != Pending. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCompleted(this UniTaskStatus status) { return status != UniTaskStatus.Pending; } - /// == Succeeded. + /// status == Succeeded. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCompletedSuccessfully(this UniTaskStatus status) { return status == UniTaskStatus.Succeeded; } - /// == Canceled. + /// status == Canceled. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCanceled(this UniTaskStatus status) { return status == UniTaskStatus.Canceled; } - /// == Faulted. + /// status == Faulted. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFaulted(this UniTaskStatus status) { diff --git a/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs b/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs index ee58010..2112582 100644 --- a/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs +++ b/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs @@ -33,13 +33,8 @@ namespace UniRx.Async.Internal } } - public static RentArray Materialize(IEnumerable source) + public static RentArray CopyToRentArray(IEnumerable source) { - if (source is T[] array) - { - return new RentArray(array, array.Length, null); - } - var defaultCount = 32; if (source is ICollection coll) { diff --git a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs b/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs deleted file mode 100644 index 26bad0f..0000000 --- a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs +++ /dev/null @@ -1,32 +0,0 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Threading; - -namespace UniRx.Async.Internal -{ - internal static class CancellationTokenHelper - { - public static bool TrySetOrLinkCancellationToken(ref CancellationToken field, CancellationToken newCancellationToken) - { - if (newCancellationToken == CancellationToken.None) - { - return false; - } - else if (field == CancellationToken.None) - { - field = newCancellationToken; - return true; - } - else if (field == newCancellationToken) - { - return false; - } - - field = CancellationTokenSource.CreateLinkedTokenSource(field, newCancellationToken).Token; - return true; - } - } -} - -#endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs.meta b/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs.meta deleted file mode 100644 index bf09591..0000000 --- a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 53d1b536fc7e2d4458294ee2c7d9b743 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Internal/MinimumQueue.cs b/Assets/UniRx.Async/Internal/MinimumQueue.cs index 5f3b589..8638a47 100644 --- a/Assets/UniRx.Async/Internal/MinimumQueue.cs +++ b/Assets/UniRx.Async/Internal/MinimumQueue.cs @@ -8,8 +8,7 @@ using System.Runtime.CompilerServices; namespace UniRx.Async.Internal { // optimized version of Standard Queue. - // TODO: to internal. - public class MinimumQueue + internal class MinimumQueue { const int MinimumGrow = 4; const int GrowFactor = 200; @@ -28,9 +27,7 @@ namespace UniRx.Async.Internal public int Count { -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif get { return size; } } @@ -40,9 +37,7 @@ namespace UniRx.Async.Internal return array[head]; } -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public void Enqueue(T item) { if (size == array.Length) @@ -55,9 +50,7 @@ namespace UniRx.Async.Internal size++; } -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public T Dequeue() { if (size == 0) ThrowForEmptyQueue(); @@ -102,9 +95,7 @@ namespace UniRx.Async.Internal tail = (size == capacity) ? 0 : size; } -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif void MoveNext(ref int index) { int tmp = index + 1; diff --git a/Assets/UniRx.Async/Internal/PromiseHelper.cs b/Assets/UniRx.Async/Internal/PromiseHelper.cs deleted file mode 100644 index a303b11..0000000 --- a/Assets/UniRx.Async/Internal/PromiseHelper.cs +++ /dev/null @@ -1,34 +0,0 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; - -namespace UniRx.Async.Internal -{ - internal static class PromiseHelper - { - internal static void TrySetResultAll(IEnumerable source, T value) - where TPromise : class, IResolvePromise - { - var rentArray = ArrayPoolUtil.Materialize(source); - var clearArray = true; - try - { - var array = rentArray.Array; - var len = rentArray.Length; - for (int i = 0; i < len; i++) - { - array[i].TrySetResult(value); - array[i] = null; - } - clearArray = false; - } - finally - { - rentArray.DisposeManually(clearArray); - } - } - } -} - -#endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Internal/PromiseHelper.cs.meta b/Assets/UniRx.Async/Internal/PromiseHelper.cs.meta deleted file mode 100644 index dfc1c50..0000000 --- a/Assets/UniRx.Async/Internal/PromiseHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 173f9b763911bf847b7dfbf31ee87fc4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Internal/TaskTracker.cs b/Assets/UniRx.Async/Internal/TaskTracker.cs index e69df26..2ef81bb 100644 --- a/Assets/UniRx.Async/Internal/TaskTracker.cs +++ b/Assets/UniRx.Async/Internal/TaskTracker.cs @@ -5,12 +5,12 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; +using UniRx.Async.Internal; -namespace UniRx.Async.Internal +namespace UniRx.Async { // public for add user custom. - // TODO: Remove public static class TaskTracker { #if UNITY_EDITOR @@ -60,144 +60,6 @@ namespace UniRx.Async.Internal #endif - static List> listPool = new List>(); - - static readonly WeakDictionary tracking = new WeakDictionary(); - - [Conditional("UNITY_EDITOR")] - public static void TrackActiveTask(IAwaiter task, int skipFrame = 1) - { -#if UNITY_EDITOR - dirty = true; - if (!EditorEnableState.EnableTracking) return; - var stackTrace = EditorEnableState.EnableStackTrace ? new StackTrace(skipFrame, true).CleanupAsyncStackTrace() : ""; - tracking.TryAdd(task, (Interlocked.Increment(ref trackingId), DateTime.UtcNow, stackTrace)); -#endif - } - - [Conditional("UNITY_EDITOR")] - public static void TrackActiveTask(IAwaiter task, string stackTrace) - { -#if UNITY_EDITOR - dirty = true; - if (!EditorEnableState.EnableTracking) return; - var success = tracking.TryAdd(task, (Interlocked.Increment(ref trackingId), DateTime.UtcNow, stackTrace)); -#endif - } - - public static string CaptureStackTrace(int skipFrame) - { -#if UNITY_EDITOR - if (!EditorEnableState.EnableTracking) return ""; - var stackTrace = EditorEnableState.EnableStackTrace ? new StackTrace(skipFrame + 1, true).CleanupAsyncStackTrace() : ""; - return stackTrace; -#else - return null; -#endif - } - - [Conditional("UNITY_EDITOR")] - public static void RemoveTracking(IAwaiter task) - { -#if UNITY_EDITOR - dirty = true; - if (!EditorEnableState.EnableTracking) return; - var success = tracking.TryRemove(task); -#endif - } - - static bool dirty; - - public static bool CheckAndResetDirty() - { - var current = dirty; - dirty = false; - return current; - } - - /// (trackingId, awaiterType, awaiterStatus, createdTime, stackTrace) - public static void ForEachActiveTask(Action action) - { - lock (listPool) - { - var count = tracking.ToList(ref listPool, clear: false); - try - { - for (int i = 0; i < count; i++) - { - string typeName = null; - var keyType = listPool[i].Key.GetType(); - if (keyType.IsNested) - { - typeName = keyType.DeclaringType.Name + "." + keyType.Name; - } - else - { - typeName = keyType.Name; - } - - action(listPool[i].Value.trackingId, typeName, listPool[i].Key.Status, listPool[i].Value.addTime, listPool[i].Value.stackTrace); - listPool[i] = new KeyValuePair(null, (0, default(DateTime), null)); // clear - } - } - catch - { - listPool.Clear(); - throw; - } - } - } - } - - public static class TaskTracker2 - { -#if UNITY_EDITOR - - static int trackingId = 0; - - public const string EnableAutoReloadKey = "UniTaskTrackerWindow_EnableAutoReloadKey"; - public const string EnableTrackingKey = "UniTaskTrackerWindow_EnableTrackingKey"; - public const string EnableStackTraceKey = "UniTaskTrackerWindow_EnableStackTraceKey"; - - public static class EditorEnableState - { - static bool enableAutoReload; - public static bool EnableAutoReload - { - get { return enableAutoReload; } - set - { - enableAutoReload = value; - UnityEditor.EditorPrefs.SetBool(EnableAutoReloadKey, value); - } - } - - static bool enableTracking; - public static bool EnableTracking - { - get { return enableTracking; } - set - { - enableTracking = value; - UnityEditor.EditorPrefs.SetBool(EnableTrackingKey, value); - } - } - - static bool enableStackTrace; - public static bool EnableStackTrace - { - get { return enableStackTrace; } - set - { - enableStackTrace = value; - UnityEditor.EditorPrefs.SetBool(EnableStackTraceKey, value); - } - } - } - -#endif - - static List> listPool = new List>(); static readonly WeakDictionary tracking = new WeakDictionary(); diff --git a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs deleted file mode 100644 index 2a294d7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs +++ /dev/null @@ -1,54 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncAnimatorTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onAnimatorIK; - AsyncTriggerPromiseDictionary onAnimatorIKs; - AsyncTriggerPromise onAnimatorMove; - AsyncTriggerPromiseDictionary onAnimatorMoves; - - - protected override IEnumerable GetPromises() - { - return Concat(onAnimatorIK, onAnimatorIKs, onAnimatorMove, onAnimatorMoves); - } - - - void OnAnimatorIK(int layerIndex) - { - TrySetResult(onAnimatorIK, onAnimatorIKs, layerIndex); - } - - - public UniTask OnAnimatorIKAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onAnimatorIK, ref onAnimatorIKs, cancellationToken); - } - - - void OnAnimatorMove() - { - TrySetResult(onAnimatorMove, onAnimatorMoves, AsyncUnit.Default); - } - - - public UniTask OnAnimatorMoveAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onAnimatorMove, ref onAnimatorMoves, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs.meta deleted file mode 100644 index 29b2826..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ae912c37ac7f4cd42b25f22452435103 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs index 0710dcb..82661b2 100644 --- a/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs +++ b/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs @@ -1,32 +1,54 @@ #if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System.Threading; using UnityEngine; namespace UniRx.Async.Triggers { + public static partial class AsyncTriggerExtensions + { + public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this Component component) + { + return component.gameObject.GetAsyncAwakeTrigger(); + } + } + [DisallowMultipleComponent] public class AsyncAwakeTrigger : MonoBehaviour { bool called = false; - UniTaskCompletionSource promise; + TriggerEvent triggerEvent; void Awake() { called = true; - promise?.TrySetResult(); + triggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent = null; } public UniTask AwakeAsync() { if (called) return UniTask.CompletedTask; + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - return new UniTask(promise ?? (promise = new UniTaskCompletionSource())); + + if (triggerEvent == null) + { + triggerEvent = new TriggerEvent(); + } + + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); } private void OnDestroy() { - promise?.TrySetCanceled(); + triggerEvent?.TrySetCanceled(CancellationToken.None); } class AwakeMonitor : IPlayerLoopItem diff --git a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs deleted file mode 100644 index bbecbea..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler - { - AsyncTriggerPromise onBeginDrag; - AsyncTriggerPromiseDictionary onBeginDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onBeginDrag, onBeginDrags); - } - - - void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) - { - TrySetResult(onBeginDrag, onBeginDrags, eventData); - } - - - public UniTask OnBeginDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBeginDrag, ref onBeginDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs.meta deleted file mode 100644 index d4a44e9..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 171fd2191eb22af4fbd92b51815ca757 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs deleted file mode 100644 index 9b14689..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler - { - AsyncTriggerPromise onCancel; - AsyncTriggerPromiseDictionary onCancels; - - - protected override IEnumerable GetPromises() - { - return Concat(onCancel, onCancels); - } - - - void ICancelHandler.OnCancel(BaseEventData eventData) - { - TrySetResult(onCancel, onCancels, eventData); - } - - - public UniTask OnCancelAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCancel, ref onCancels, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs.meta deleted file mode 100644 index 285efd5..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 291886b6e5f2d044a85b2a4dedcaca97 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs deleted file mode 100644 index 98fb776..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCanvasGroupChangedTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onCanvasGroupChanged; - AsyncTriggerPromiseDictionary onCanvasGroupChangeds; - - - protected override IEnumerable GetPromises() - { - return Concat(onCanvasGroupChanged, onCanvasGroupChangeds); - } - - - void OnCanvasGroupChanged() - { - TrySetResult(onCanvasGroupChanged, onCanvasGroupChangeds, AsyncUnit.Default); - } - - - public UniTask OnCanvasGroupChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCanvasGroupChanged, ref onCanvasGroupChangeds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs.meta deleted file mode 100644 index d0ebc56..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: eddba832648f83046a320ffcacfc771d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs deleted file mode 100644 index 0f0b747..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCollision2DTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onCollisionEnter2D; - AsyncTriggerPromiseDictionary onCollisionEnter2Ds; - AsyncTriggerPromise onCollisionExit2D; - AsyncTriggerPromiseDictionary onCollisionExit2Ds; - AsyncTriggerPromise onCollisionStay2D; - AsyncTriggerPromiseDictionary onCollisionStay2Ds; - - - protected override IEnumerable GetPromises() - { - return Concat(onCollisionEnter2D, onCollisionEnter2Ds, onCollisionExit2D, onCollisionExit2Ds, onCollisionStay2D, onCollisionStay2Ds); - } - - - void OnCollisionEnter2D(Collision2D coll) - { - TrySetResult(onCollisionEnter2D, onCollisionEnter2Ds, coll); - } - - - public UniTask OnCollisionEnter2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionEnter2D, ref onCollisionEnter2Ds, cancellationToken); - } - - - void OnCollisionExit2D(Collision2D coll) - { - TrySetResult(onCollisionExit2D, onCollisionExit2Ds, coll); - } - - - public UniTask OnCollisionExit2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionExit2D, ref onCollisionExit2Ds, cancellationToken); - } - - - void OnCollisionStay2D(Collision2D coll) - { - TrySetResult(onCollisionStay2D, onCollisionStay2Ds, coll); - } - - - public UniTask OnCollisionStay2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionStay2D, ref onCollisionStay2Ds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs.meta deleted file mode 100644 index ad81300..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fbeb63f69bedec44f8003730887f914b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs deleted file mode 100644 index 71306df..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCollisionTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onCollisionEnter; - AsyncTriggerPromiseDictionary onCollisionEnters; - AsyncTriggerPromise onCollisionExit; - AsyncTriggerPromiseDictionary onCollisionExits; - AsyncTriggerPromise onCollisionStay; - AsyncTriggerPromiseDictionary onCollisionStays; - - - protected override IEnumerable GetPromises() - { - return Concat(onCollisionEnter, onCollisionEnters, onCollisionExit, onCollisionExits, onCollisionStay, onCollisionStays); - } - - - void OnCollisionEnter(Collision collision) - { - TrySetResult(onCollisionEnter, onCollisionEnters, collision); - } - - - public UniTask OnCollisionEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionEnter, ref onCollisionEnters, cancellationToken); - } - - - void OnCollisionExit(Collision collisionInfo) - { - TrySetResult(onCollisionExit, onCollisionExits, collisionInfo); - } - - - public UniTask OnCollisionExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionExit, ref onCollisionExits, cancellationToken); - } - - - void OnCollisionStay(Collision collisionInfo) - { - TrySetResult(onCollisionStay, onCollisionStays, collisionInfo); - } - - - public UniTask OnCollisionStayAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionStay, ref onCollisionStays, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs.meta deleted file mode 100644 index ebcc28e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 72db4a683be8f6a428823502599014a9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs deleted file mode 100644 index a76b421..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler - { - AsyncTriggerPromise onDeselect; - AsyncTriggerPromiseDictionary onDeselects; - - - protected override IEnumerable GetPromises() - { - return Concat(onDeselect, onDeselects); - } - - - void IDeselectHandler.OnDeselect(BaseEventData eventData) - { - TrySetResult(onDeselect, onDeselects, eventData); - } - - - public UniTask OnDeselectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDeselect, ref onDeselects, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs.meta deleted file mode 100644 index 9509524..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 30faa9be5bd883e488bdc52f4825c4da -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs index 245126f..2eaf42b 100644 --- a/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs +++ b/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs @@ -2,18 +2,30 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System.Threading; -using UniRx.Async.Internal; using UnityEngine; namespace UniRx.Async.Triggers { + public static partial class AsyncTriggerExtensions + { + public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this Component component) + { + return component.gameObject.GetAsyncDestroyTrigger(); + } + } + [DisallowMultipleComponent] public class AsyncDestroyTrigger : MonoBehaviour { + bool awakeCalled = false; bool called = false; - UniTaskCompletionSource promise; - CancellationTokenSource cancellationTokenSource; // main cancellation - object canellationTokenSourceOrQueue; // external from AddCancellationTriggerOnDestroy + TriggerEvent triggerEvent; + CancellationTokenSource cancellationTokenSource; public CancellationToken CancellationToken { @@ -27,64 +39,57 @@ namespace UniRx.Async.Triggers } } - /// This function is called when the MonoBehaviour will be destroyed. + void Awake() + { + awakeCalled = true; + } + void OnDestroy() { called = true; - promise?.TrySetResult(); + + triggerEvent?.TrySetResult(AsyncUnit.Default); cancellationTokenSource?.Cancel(); cancellationTokenSource?.Dispose(); - if (canellationTokenSourceOrQueue != null) - { - if (canellationTokenSourceOrQueue is CancellationTokenSource cts) - { - cts.Cancel(); - cts.Dispose(); - } - else - { - var q = (MinimumQueue)canellationTokenSourceOrQueue; - while (q.Count != 0) - { - var c = q.Dequeue(); - c.Cancel(); - c.Dispose(); - } - } - canellationTokenSourceOrQueue = null; - } + + triggerEvent = null; } - /// This function is called when the MonoBehaviour will be destroyed. public UniTask OnDestroyAsync() { if (called) return UniTask.CompletedTask; - return new UniTask(promise ?? (promise = new UniTaskCompletionSource())); + + if (!awakeCalled) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + + if (triggerEvent == null) + { + triggerEvent = new TriggerEvent(); + } + + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); } - /// Add Cancellation Triggers on destroy - public void AddCancellationTriggerOnDestroy(CancellationTokenSource cts) + class AwakeMonitor : IPlayerLoopItem { - if (called) + readonly AsyncDestroyTrigger trigger; + + public AwakeMonitor(AsyncDestroyTrigger trigger) { - cts.Cancel(); - cts.Dispose(); + this.trigger = trigger; } - if (canellationTokenSourceOrQueue == null) + public bool MoveNext() { - canellationTokenSourceOrQueue = cts; - } - else if (canellationTokenSourceOrQueue is CancellationTokenSource c) - { - var q = new MinimumQueue(4); - q.Enqueue(c); - q.Enqueue(cts); - canellationTokenSourceOrQueue = q; - } - else - { - ((MinimumQueue)canellationTokenSourceOrQueue).Enqueue(cts); + if (trigger.called) return false; + if (trigger == null) + { + trigger.OnDestroy(); + return false; + } + return true; } } } diff --git a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs deleted file mode 100644 index 0a36282..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncDragTrigger : AsyncTriggerBase, IDragHandler - { - AsyncTriggerPromise onDrag; - AsyncTriggerPromiseDictionary onDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onDrag, onDrags); - } - - - void IDragHandler.OnDrag(PointerEventData eventData) - { - TrySetResult(onDrag, onDrags, eventData); - } - - - public UniTask OnDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrag, ref onDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs.meta deleted file mode 100644 index d259f40..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 52242547ba60ea74f8a2e3bbab5fcdfa -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs deleted file mode 100644 index 25b6217..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncDropTrigger : AsyncTriggerBase, IDropHandler - { - AsyncTriggerPromise onDrop; - AsyncTriggerPromiseDictionary onDrops; - - - protected override IEnumerable GetPromises() - { - return Concat(onDrop, onDrops); - } - - - void IDropHandler.OnDrop(PointerEventData eventData) - { - TrySetResult(onDrop, onDrops, eventData); - } - - - public UniTask OnDropAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrop, ref onDrops, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs.meta deleted file mode 100644 index 2a15847..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 42d65fd5e4be25f41a927eca25b0acf7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs deleted file mode 100644 index 092b97f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncEnableDisableTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onEnable; - AsyncTriggerPromiseDictionary onEnables; - AsyncTriggerPromise onDisable; - AsyncTriggerPromiseDictionary onDisables; - - - protected override IEnumerable GetPromises() - { - return Concat(onEnable, onEnables, onDisable, onDisables); - } - - - void OnEnable() - { - TrySetResult(onEnable, onEnables, AsyncUnit.Default); - } - - - public UniTask OnEnableAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onEnable, ref onEnables, cancellationToken); - } - - - void OnDisable() - { - TrySetResult(onDisable, onDisables, AsyncUnit.Default); - } - - - public UniTask OnDisableAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDisable, ref onDisables, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs.meta deleted file mode 100644 index 8e61a0f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d0bf9142b63b4cb43b693f0b83b3dbe7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs deleted file mode 100644 index 0e8f27c..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler - { - AsyncTriggerPromise onEndDrag; - AsyncTriggerPromiseDictionary onEndDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onEndDrag, onEndDrags); - } - - - void IEndDragHandler.OnEndDrag(PointerEventData eventData) - { - TrySetResult(onEndDrag, onEndDrags, eventData); - } - - - public UniTask OnEndDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onEndDrag, ref onEndDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs.meta deleted file mode 100644 index 98f67b8..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8298d43de348acc4aa4e7dbf30472dbf -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs deleted file mode 100644 index 17568d2..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs +++ /dev/null @@ -1,264 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncEventTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onDeselect; - AsyncTriggerPromiseDictionary onDeselects; - AsyncTriggerPromise onMove; - AsyncTriggerPromiseDictionary onMoves; - AsyncTriggerPromise onPointerDown; - AsyncTriggerPromiseDictionary onPointerDowns; - AsyncTriggerPromise onPointerEnter; - AsyncTriggerPromiseDictionary onPointerEnters; - AsyncTriggerPromise onPointerExit; - AsyncTriggerPromiseDictionary onPointerExits; - AsyncTriggerPromise onPointerUp; - AsyncTriggerPromiseDictionary onPointerUps; - AsyncTriggerPromise onSelect; - AsyncTriggerPromiseDictionary onSelects; - AsyncTriggerPromise onPointerClick; - AsyncTriggerPromiseDictionary onPointerClicks; - AsyncTriggerPromise onSubmit; - AsyncTriggerPromiseDictionary onSubmits; - AsyncTriggerPromise onDrag; - AsyncTriggerPromiseDictionary onDrags; - AsyncTriggerPromise onBeginDrag; - AsyncTriggerPromiseDictionary onBeginDrags; - AsyncTriggerPromise onEndDrag; - AsyncTriggerPromiseDictionary onEndDrags; - AsyncTriggerPromise onDrop; - AsyncTriggerPromiseDictionary onDrops; - AsyncTriggerPromise onUpdateSelected; - AsyncTriggerPromiseDictionary onUpdateSelecteds; - AsyncTriggerPromise onInitializePotentialDrag; - AsyncTriggerPromiseDictionary onInitializePotentialDrags; - AsyncTriggerPromise onCancel; - AsyncTriggerPromiseDictionary onCancels; - AsyncTriggerPromise onScroll; - AsyncTriggerPromiseDictionary onScrolls; - - - protected override IEnumerable GetPromises() - { - return Concat(onDeselect, onDeselects, onMove, onMoves, onPointerDown, onPointerDowns, onPointerEnter, onPointerEnters, onPointerExit, onPointerExits, onPointerUp, onPointerUps, onSelect, onSelects, onPointerClick, onPointerClicks, onSubmit, onSubmits, onDrag, onDrags, onBeginDrag, onBeginDrags, onEndDrag, onEndDrags, onDrop, onDrops, onUpdateSelected, onUpdateSelecteds, onInitializePotentialDrag, onInitializePotentialDrags, onCancel, onCancels, onScroll, onScrolls); - } - - void OnDeselect(BaseEventData eventData) - { - TrySetResult(onDeselect, onDeselects, eventData); - } - - - public UniTask OnDeselectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDeselect, ref onDeselects, cancellationToken); - } - - - void OnMove(AxisEventData eventData) - { - TrySetResult(onMove, onMoves, eventData); - } - - - public UniTask OnMoveAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMove, ref onMoves, cancellationToken); - } - - - void OnPointerDown(PointerEventData eventData) - { - TrySetResult(onPointerDown, onPointerDowns, eventData); - } - - - public UniTask OnPointerDownAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerDown, ref onPointerDowns, cancellationToken); - } - - - void OnPointerEnter(PointerEventData eventData) - { - TrySetResult(onPointerEnter, onPointerEnters, eventData); - } - - - public UniTask OnPointerEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerEnter, ref onPointerEnters, cancellationToken); - } - - - void OnPointerExit(PointerEventData eventData) - { - TrySetResult(onPointerExit, onPointerExits, eventData); - } - - - public UniTask OnPointerExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerExit, ref onPointerExits, cancellationToken); - } - - - void OnPointerUp(PointerEventData eventData) - { - TrySetResult(onPointerUp, onPointerUps, eventData); - } - - - public UniTask OnPointerUpAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerUp, ref onPointerUps, cancellationToken); - } - - - void OnSelect(BaseEventData eventData) - { - TrySetResult(onSelect, onSelects, eventData); - } - - - public UniTask OnSelectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSelect, ref onSelects, cancellationToken); - } - - - void OnPointerClick(PointerEventData eventData) - { - TrySetResult(onPointerClick, onPointerClicks, eventData); - } - - - public UniTask OnPointerClickAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerClick, ref onPointerClicks, cancellationToken); - } - - - void OnSubmit(BaseEventData eventData) - { - TrySetResult(onSubmit, onSubmits, eventData); - } - - - public UniTask OnSubmitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSubmit, ref onSubmits, cancellationToken); - } - - - void OnDrag(PointerEventData eventData) - { - TrySetResult(onDrag, onDrags, eventData); - } - - - public UniTask OnDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrag, ref onDrags, cancellationToken); - } - - - void OnBeginDrag(PointerEventData eventData) - { - TrySetResult(onBeginDrag, onBeginDrags, eventData); - } - - - public UniTask OnBeginDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBeginDrag, ref onBeginDrags, cancellationToken); - } - - - void OnEndDrag(PointerEventData eventData) - { - TrySetResult(onEndDrag, onEndDrags, eventData); - } - - - public UniTask OnEndDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onEndDrag, ref onEndDrags, cancellationToken); - } - - - void OnDrop(PointerEventData eventData) - { - TrySetResult(onDrop, onDrops, eventData); - } - - - public UniTask OnDropAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrop, ref onDrops, cancellationToken); - } - - - void OnUpdateSelected(BaseEventData eventData) - { - TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData); - } - - - public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onUpdateSelected, ref onUpdateSelecteds, cancellationToken); - } - - - void OnInitializePotentialDrag(PointerEventData eventData) - { - TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData); - } - - - public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onInitializePotentialDrag, ref onInitializePotentialDrags, cancellationToken); - } - - - void OnCancel(BaseEventData eventData) - { - TrySetResult(onCancel, onCancels, eventData); - } - - - public UniTask OnCancelAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCancel, ref onCancels, cancellationToken); - } - - - void OnScroll(PointerEventData eventData) - { - TrySetResult(onScroll, onScrolls, eventData); - } - - - public UniTask OnScrollAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onScroll, ref onScrolls, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs.meta deleted file mode 100644 index c901478..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 89997820797ad6d43b17971a8bd0d8fe -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs deleted file mode 100644 index 8cfc821..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncFixedUpdateTrigger : AsyncTriggerBase - { - AsyncTriggerPromise fixedUpdate; - AsyncTriggerPromiseDictionary fixedUpdates; - - - protected override IEnumerable GetPromises() - { - return Concat(fixedUpdate, fixedUpdates); - } - - - void FixedUpdate() - { - TrySetResult(fixedUpdate, fixedUpdates, AsyncUnit.Default); - } - - - public UniTask FixedUpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref fixedUpdate, ref fixedUpdates, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs.meta deleted file mode 100644 index 7154af6..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c74b906c4294aaa4e900f6e7f8b36df6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs deleted file mode 100644 index 8dda82a..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler - { - AsyncTriggerPromise onInitializePotentialDrag; - AsyncTriggerPromiseDictionary onInitializePotentialDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onInitializePotentialDrag, onInitializePotentialDrags); - } - - - void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData) - { - TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData); - } - - - public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onInitializePotentialDrag, ref onInitializePotentialDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs.meta deleted file mode 100644 index 0df8a5b..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ae0733adc239a324f8b934ffb119abd8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs deleted file mode 100644 index bf33407..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncJointTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onJointBreak; - AsyncTriggerPromiseDictionary onJointBreaks; - AsyncTriggerPromise onJointBreak2D; - AsyncTriggerPromiseDictionary onJointBreak2Ds; - - - protected override IEnumerable GetPromises() - { - return Concat(onJointBreak, onJointBreaks, onJointBreak2D, onJointBreak2Ds); - } - - - void OnJointBreak(float breakForce) - { - TrySetResult(onJointBreak, onJointBreaks, breakForce); - } - - - public UniTask OnJointBreakAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onJointBreak, ref onJointBreaks, cancellationToken); - } - - - void OnJointBreak2D(Joint2D brokenJoint) - { - TrySetResult(onJointBreak2D, onJointBreak2Ds, brokenJoint); - } - - - public UniTask OnJointBreak2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onJointBreak2D, ref onJointBreak2Ds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs.meta deleted file mode 100644 index 8220736..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 04dc74e7b2368094f9153921804a1fb7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs deleted file mode 100644 index e88dfd8..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncLateUpdateTrigger : AsyncTriggerBase - { - AsyncTriggerPromise lateUpdate; - AsyncTriggerPromiseDictionary lateUpdates; - - - protected override IEnumerable GetPromises() - { - return Concat(lateUpdate, lateUpdates); - } - - - void LateUpdate() - { - TrySetResult(lateUpdate, lateUpdates, AsyncUnit.Default); - } - - - public UniTask LateUpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref lateUpdate, ref lateUpdates, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs.meta deleted file mode 100644 index 391059d..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a4fb2b4c09cb4ec4a82b934f2038eb36 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs deleted file mode 100644 index 243fb00..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs +++ /dev/null @@ -1,129 +0,0 @@ - -#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO) - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncMouseTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onMouseDown; - AsyncTriggerPromiseDictionary onMouseDowns; - AsyncTriggerPromise onMouseDrag; - AsyncTriggerPromiseDictionary onMouseDrags; - AsyncTriggerPromise onMouseEnter; - AsyncTriggerPromiseDictionary onMouseEnters; - AsyncTriggerPromise onMouseExit; - AsyncTriggerPromiseDictionary onMouseExits; - AsyncTriggerPromise onMouseOver; - AsyncTriggerPromiseDictionary onMouseOvers; - AsyncTriggerPromise onMouseUp; - AsyncTriggerPromiseDictionary onMouseUps; - AsyncTriggerPromise onMouseUpAsButton; - AsyncTriggerPromiseDictionary onMouseUpAsButtons; - - - protected override IEnumerable GetPromises() - { - return Concat(onMouseDown, onMouseDowns, onMouseDrag, onMouseDrags, onMouseEnter, onMouseEnters, onMouseExit, onMouseExits, onMouseOver, onMouseOvers, onMouseUp, onMouseUps, onMouseUpAsButton, onMouseUpAsButtons); - } - - - void OnMouseDown() - { - TrySetResult(onMouseDown, onMouseDowns, AsyncUnit.Default); - } - - - public UniTask OnMouseDownAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseDown, ref onMouseDowns, cancellationToken); - } - - - void OnMouseDrag() - { - TrySetResult(onMouseDrag, onMouseDrags, AsyncUnit.Default); - } - - - public UniTask OnMouseDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseDrag, ref onMouseDrags, cancellationToken); - } - - - void OnMouseEnter() - { - TrySetResult(onMouseEnter, onMouseEnters, AsyncUnit.Default); - } - - - public UniTask OnMouseEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseEnter, ref onMouseEnters, cancellationToken); - } - - - void OnMouseExit() - { - TrySetResult(onMouseExit, onMouseExits, AsyncUnit.Default); - } - - - public UniTask OnMouseExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseExit, ref onMouseExits, cancellationToken); - } - - - void OnMouseOver() - { - TrySetResult(onMouseOver, onMouseOvers, AsyncUnit.Default); - } - - - public UniTask OnMouseOverAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseOver, ref onMouseOvers, cancellationToken); - } - - - void OnMouseUp() - { - TrySetResult(onMouseUp, onMouseUps, AsyncUnit.Default); - } - - - public UniTask OnMouseUpAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseUp, ref onMouseUps, cancellationToken); - } - - - void OnMouseUpAsButton() - { - TrySetResult(onMouseUpAsButton, onMouseUpAsButtons, AsyncUnit.Default); - } - - - public UniTask OnMouseUpAsButtonAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseUpAsButton, ref onMouseUpAsButtons, cancellationToken); - } - - - } -} - -#endif - - -#endif diff --git a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs.meta deleted file mode 100644 index 9e8706f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 57ad5120e9c4d424484c963791467272 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs deleted file mode 100644 index 19d0f56..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler - { - AsyncTriggerPromise onMove; - AsyncTriggerPromiseDictionary onMoves; - - - protected override IEnumerable GetPromises() - { - return Concat(onMove, onMoves); - } - - - void IMoveHandler.OnMove(AxisEventData eventData) - { - TrySetResult(onMove, onMoves, eventData); - } - - - public UniTask OnMoveAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMove, ref onMoves, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs.meta deleted file mode 100644 index 2ea01b7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1699926e875c24d4aa34bc8817f96f0e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs deleted file mode 100644 index 284461a..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncParticleTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onParticleCollision; - AsyncTriggerPromiseDictionary onParticleCollisions; - - - protected override IEnumerable GetPromises() - { - return Concat(onParticleCollision, onParticleCollisions); - } - - - void OnParticleCollision(GameObject other) - { - TrySetResult(onParticleCollision, onParticleCollisions, other); - } - - - public UniTask OnParticleCollisionAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onParticleCollision, ref onParticleCollisions, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs.meta deleted file mode 100644 index 4a162c7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 27d3f2efd47fb1d4fb2e9130f97ea8aa -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs deleted file mode 100644 index b4ed576..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler - { - AsyncTriggerPromise onPointerClick; - AsyncTriggerPromiseDictionary onPointerClicks; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerClick, onPointerClicks); - } - - - void IPointerClickHandler.OnPointerClick(PointerEventData eventData) - { - TrySetResult(onPointerClick, onPointerClicks, eventData); - } - - - public UniTask OnPointerClickAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerClick, ref onPointerClicks, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs.meta deleted file mode 100644 index 67447a7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9f8865abf2db3d248b3730cdb18bb8b7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs deleted file mode 100644 index aa6bc36..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler - { - AsyncTriggerPromise onPointerDown; - AsyncTriggerPromiseDictionary onPointerDowns; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerDown, onPointerDowns); - } - - - void IPointerDownHandler.OnPointerDown(PointerEventData eventData) - { - TrySetResult(onPointerDown, onPointerDowns, eventData); - } - - - public UniTask OnPointerDownAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerDown, ref onPointerDowns, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs.meta deleted file mode 100644 index 851cfe4..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7c5132395605eaa498a7efedee5acdd7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs deleted file mode 100644 index 179766d..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler - { - AsyncTriggerPromise onPointerEnter; - AsyncTriggerPromiseDictionary onPointerEnters; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerEnter, onPointerEnters); - } - - - void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) - { - TrySetResult(onPointerEnter, onPointerEnters, eventData); - } - - - public UniTask OnPointerEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerEnter, ref onPointerEnters, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs.meta deleted file mode 100644 index 9a01b93..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 18887d476d48533498efd14224a2f651 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs deleted file mode 100644 index 4d0051e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler - { - AsyncTriggerPromise onPointerExit; - AsyncTriggerPromiseDictionary onPointerExits; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerExit, onPointerExits); - } - - - void IPointerExitHandler.OnPointerExit(PointerEventData eventData) - { - TrySetResult(onPointerExit, onPointerExits, eventData); - } - - - public UniTask OnPointerExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerExit, ref onPointerExits, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs.meta deleted file mode 100644 index 39ab381..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9e3ed09876a11a84794795809ebee243 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs deleted file mode 100644 index 11e5d66..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler - { - AsyncTriggerPromise onPointerUp; - AsyncTriggerPromiseDictionary onPointerUps; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerUp, onPointerUps); - } - - - void IPointerUpHandler.OnPointerUp(PointerEventData eventData) - { - TrySetResult(onPointerUp, onPointerUps, eventData); - } - - - public UniTask OnPointerUpAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerUp, ref onPointerUps, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs.meta deleted file mode 100644 index 7be4e27..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7a0493ea32f81314cbbaf2b635ba3167 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs deleted file mode 100644 index 4fab679..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncRectTransformTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onRectTransformDimensionsChange; - AsyncTriggerPromiseDictionary onRectTransformDimensionsChanges; - AsyncTriggerPromise onRectTransformRemoved; - AsyncTriggerPromiseDictionary onRectTransformRemoveds; - - - protected override IEnumerable GetPromises() - { - return Concat(onRectTransformDimensionsChange, onRectTransformDimensionsChanges, onRectTransformRemoved, onRectTransformRemoveds); - } - - - void OnRectTransformDimensionsChange() - { - TrySetResult(onRectTransformDimensionsChange, onRectTransformDimensionsChanges, AsyncUnit.Default); - } - - - public UniTask OnRectTransformDimensionsChangeAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onRectTransformDimensionsChange, ref onRectTransformDimensionsChanges, cancellationToken); - } - - - void OnRectTransformRemoved() - { - TrySetResult(onRectTransformRemoved, onRectTransformRemoveds, AsyncUnit.Default); - } - - - public UniTask OnRectTransformRemovedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onRectTransformRemoved, ref onRectTransformRemoveds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs.meta deleted file mode 100644 index 98c4f70..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: dfe3470221c66c84397c0783c62b24e7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs deleted file mode 100644 index 6908ff9..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler - { - AsyncTriggerPromise onScroll; - AsyncTriggerPromiseDictionary onScrolls; - - - protected override IEnumerable GetPromises() - { - return Concat(onScroll, onScrolls); - } - - - void IScrollHandler.OnScroll(PointerEventData eventData) - { - TrySetResult(onScroll, onScrolls, eventData); - } - - - public UniTask OnScrollAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onScroll, ref onScrolls, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs.meta deleted file mode 100644 index 541bdbe..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7c751e9d3deb97d4d8691a8a583c2afd -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs deleted file mode 100644 index ad4e99f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler - { - AsyncTriggerPromise onSelect; - AsyncTriggerPromiseDictionary onSelects; - - - protected override IEnumerable GetPromises() - { - return Concat(onSelect, onSelects); - } - - - void ISelectHandler.OnSelect(BaseEventData eventData) - { - TrySetResult(onSelect, onSelects, eventData); - } - - - public UniTask OnSelectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSelect, ref onSelects, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs.meta deleted file mode 100644 index dd4563b..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fcc2347251a4fc5498a03f0c17382920 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs index 4c65c8c..53a859e 100644 --- a/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs +++ b/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs @@ -1,16 +1,30 @@ #if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System.Threading; using UnityEngine; namespace UniRx.Async.Triggers { + public static partial class AsyncTriggerExtensions + { + public static AsyncStartTrigger GetAsyncStartTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncStartTrigger GetAsyncStartTrigger(this Component component) + { + return component.gameObject.GetAsyncStartTrigger(); + } + } + [DisallowMultipleComponent] public class AsyncStartTrigger : MonoBehaviour { bool awakeCalled = false; bool called = false; - UniTaskCompletionSource promise; + TriggerEvent triggerEvent; void Awake() { @@ -20,22 +34,30 @@ namespace UniRx.Async.Triggers void Start() { called = true; - promise?.TrySetResult(); + triggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent = null; } public UniTask StartAsync() { if (called) return UniTask.CompletedTask; + if (!awakeCalled) { PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); } - return new UniTask(promise ?? (promise = new UniTaskCompletionSource())); + + if (triggerEvent == null) + { + triggerEvent = new TriggerEvent(); + } + + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); } private void OnDestroy() { - promise?.TrySetCanceled(); + triggerEvent?.TrySetCanceled(CancellationToken.None); } class AwakeMonitor : IPlayerLoopItem @@ -49,7 +71,7 @@ namespace UniRx.Async.Triggers public bool MoveNext() { - if (trigger.awakeCalled) return false; + if (trigger.called) return false; if (trigger == null) { trigger.OnDestroy(); @@ -59,6 +81,7 @@ namespace UniRx.Async.Triggers } } } + } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs deleted file mode 100644 index 22a00fa..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler - { - AsyncTriggerPromise onSubmit; - AsyncTriggerPromiseDictionary onSubmits; - - - protected override IEnumerable GetPromises() - { - return Concat(onSubmit, onSubmits); - } - - - void ISubmitHandler.OnSubmit(BaseEventData eventData) - { - TrySetResult(onSubmit, onSubmits, eventData); - } - - - public UniTask OnSubmitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSubmit, ref onSubmits, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs.meta deleted file mode 100644 index 16b6b05..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 97e85abc2d7ec0c44adfbe5ee971aad3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs deleted file mode 100644 index acad97e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncTransformChangedTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onBeforeTransformParentChanged; - AsyncTriggerPromiseDictionary onBeforeTransformParentChangeds; - AsyncTriggerPromise onTransformParentChanged; - AsyncTriggerPromiseDictionary onTransformParentChangeds; - AsyncTriggerPromise onTransformChildrenChanged; - AsyncTriggerPromiseDictionary onTransformChildrenChangeds; - - - protected override IEnumerable GetPromises() - { - return Concat(onBeforeTransformParentChanged, onBeforeTransformParentChangeds, onTransformParentChanged, onTransformParentChangeds, onTransformChildrenChanged, onTransformChildrenChangeds); - } - - - void OnBeforeTransformParentChanged() - { - TrySetResult(onBeforeTransformParentChanged, onBeforeTransformParentChangeds, AsyncUnit.Default); - } - - - public UniTask OnBeforeTransformParentChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBeforeTransformParentChanged, ref onBeforeTransformParentChangeds, cancellationToken); - } - - - void OnTransformParentChanged() - { - TrySetResult(onTransformParentChanged, onTransformParentChangeds, AsyncUnit.Default); - } - - - public UniTask OnTransformParentChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTransformParentChanged, ref onTransformParentChangeds, cancellationToken); - } - - - void OnTransformChildrenChanged() - { - TrySetResult(onTransformChildrenChanged, onTransformChildrenChangeds, AsyncUnit.Default); - } - - - public UniTask OnTransformChildrenChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTransformChildrenChanged, ref onTransformChildrenChangeds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs.meta deleted file mode 100644 index 60b6c38..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 053f983cd760f5e4394be8fd657243c1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs deleted file mode 100644 index fb3cfe5..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncTrigger2DTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onTriggerEnter2D; - AsyncTriggerPromiseDictionary onTriggerEnter2Ds; - AsyncTriggerPromise onTriggerExit2D; - AsyncTriggerPromiseDictionary onTriggerExit2Ds; - AsyncTriggerPromise onTriggerStay2D; - AsyncTriggerPromiseDictionary onTriggerStay2Ds; - - - protected override IEnumerable GetPromises() - { - return Concat(onTriggerEnter2D, onTriggerEnter2Ds, onTriggerExit2D, onTriggerExit2Ds, onTriggerStay2D, onTriggerStay2Ds); - } - - - void OnTriggerEnter2D(Collider2D other) - { - TrySetResult(onTriggerEnter2D, onTriggerEnter2Ds, other); - } - - - public UniTask OnTriggerEnter2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerEnter2D, ref onTriggerEnter2Ds, cancellationToken); - } - - - void OnTriggerExit2D(Collider2D other) - { - TrySetResult(onTriggerExit2D, onTriggerExit2Ds, other); - } - - - public UniTask OnTriggerExit2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerExit2D, ref onTriggerExit2Ds, cancellationToken); - } - - - void OnTriggerStay2D(Collider2D other) - { - TrySetResult(onTriggerStay2D, onTriggerStay2Ds, other); - } - - - public UniTask OnTriggerStay2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerStay2D, ref onTriggerStay2Ds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs.meta deleted file mode 100644 index 8d88bad..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 102f8eba36bc2a54e878e67aca9686e5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs index a7b0d7a..a1294a6 100644 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs +++ b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs @@ -9,202 +9,47 @@ using UnityEngine; namespace UniRx.Async.Triggers { - public interface ICancelablePromise - { - CancellationToken RegisteredCancellationToken { get; } - bool TrySetCanceled(); - } - - - public interface ICancellationTokenKeyDictionary - { - void Remove(CancellationToken token); - } - - public class AsyncTriggerPromiseDictionary : - Dictionary>, - ICancellationTokenKeyDictionary, - IEnumerable - { - public AsyncTriggerPromiseDictionary() - : base(CancellationTokenEqualityComparer.Default) - { - } - - IEnumerator IEnumerable.GetEnumerator() - { - // TODO: - throw new NotImplementedException(); - //return Values.GetEnumerator(); - } - - void ICancellationTokenKeyDictionary.Remove(CancellationToken token) - { - this.Remove(token); - } - } - public abstract class AsyncTriggerBase : MonoBehaviour { - static readonly Action Callback = CancelCallback; - - bool calledAwake = false; - bool destroyCalled = false; - CancellationTokenRegistration[] registeredCancellations; - int registeredCancellationsCount; - - protected abstract IEnumerable GetPromises(); - - static protected IEnumerable Concat(ICancelablePromise p1, IEnumerable p1s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - } - - static protected IEnumerable Concat( - ICancelablePromise p1, IEnumerable p1s, - ICancelablePromise p2, IEnumerable p2s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - if (p2 != null) yield return p2; - if (p2s != null) foreach (var item in p2s) yield return item; - } - - static protected IEnumerable Concat( - ICancelablePromise p1, IEnumerable p1s, - ICancelablePromise p2, IEnumerable p2s, - ICancelablePromise p3, IEnumerable p3s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - if (p2 != null) yield return p2; - if (p2s != null) foreach (var item in p2s) yield return item; - if (p3 != null) yield return p3; - if (p3s != null) foreach (var item in p3s) yield return item; - } - - static protected IEnumerable Concat( - ICancelablePromise p1, IEnumerable p1s, - ICancelablePromise p2, IEnumerable p2s, - ICancelablePromise p3, IEnumerable p3s, - ICancelablePromise p4, IEnumerable p4s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - if (p2 != null) yield return p2; - if (p2s != null) foreach (var item in p2s) yield return item; - if (p3 != null) yield return p3; - if (p3s != null) foreach (var item in p3s) yield return item; - if (p4 != null) yield return p4; - if (p4s != null) foreach (var item in p4s) yield return item; - } - - // otherwise... - static protected IEnumerable Concat(params object[] promises) - { - foreach (var item in promises) - { - if (item is ICancelablePromise p) - { - yield return p; - } - else if (item is IEnumerable ps) - { - foreach (var p2 in ps) - { - yield return p2; - } - } - } - } - - protected UniTask GetOrAddPromise(ref AsyncTriggerPromise promise, ref AsyncTriggerPromiseDictionary promises, CancellationToken cancellationToken) - { - if (destroyCalled) return UniTask.FromCanceled(); - - if (!cancellationToken.CanBeCanceled) - { - if (promise == null) - { - promise = new AsyncTriggerPromise(); - if (!calledAwake) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - } - return promise.Task; - } - - if (promises == null) promises = new AsyncTriggerPromiseDictionary(); - - if (promises.TryGetValue(cancellationToken, out var cancellablePromise)) - { - return cancellablePromise.Task; - } - - cancellablePromise = new AsyncTriggerPromise(); - promises.Add(cancellationToken, cancellablePromise); - if (!calledAwake) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - - var registrationToken = cancellationToken.RegisterWithoutCaptureExecutionContext(Callback, Tuple.Create((ICancellationTokenKeyDictionary)promises, (ICancelablePromise)cancellablePromise)); - if (registeredCancellations == null) - { - registeredCancellations = ArrayPool.Shared.Rent(4); - } - ArrayPoolUtil.EnsureCapacity(ref registeredCancellations, registeredCancellationsCount + 1, ArrayPool.Shared); - registeredCancellations[registeredCancellationsCount++] = registrationToken; - - return cancellablePromise.Task; - } - - static void CancelCallback(object state) - { - var tuple = (Tuple)state; - var dict = tuple.Item1; - var promise = tuple.Item2; - - promise.TrySetCanceled(); - dict.Remove(promise.RegisteredCancellationToken); - } - - protected void TrySetResult(ReusablePromise promise, AsyncTriggerPromiseDictionary promises, T value) - { - if (promise != null) - { - promise.TrySetResult(value); - } - if (promises != null) - { - PromiseHelper.TrySetResultAll(promises.Values, value); - } - } + bool calledAwake; + bool calledDestroy; + ICancelPromise triggerSlot; void Awake() { calledAwake = true; } + protected TriggerEvent SetTriggerEvent(ref TriggerEvent field) + { + if (field == null) + { + field = new TriggerEvent(); + if (triggerSlot == null) + { + triggerSlot = field; + } + else + { + throw new InvalidOperationException("triggerSlot is already filled."); + } + } + + if (!calledAwake) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + + return field; + } + void OnDestroy() { - if (destroyCalled) return; - destroyCalled = true; - foreach (var item in GetPromises()) - { - item.TrySetCanceled(); - } - if (registeredCancellations != null) - { - for (int i = 0; i < registeredCancellationsCount; i++) - { - registeredCancellations[i].Dispose(); - registeredCancellations[i] = default(CancellationTokenRegistration); - } - ArrayPool.Shared.Return(registeredCancellations); - } + if (calledDestroy) return; + calledDestroy = true; + + triggerSlot?.TrySetCanceled(); + triggerSlot = null; } class AwakeMonitor : IPlayerLoopItem @@ -228,6 +73,313 @@ namespace UniRx.Async.Triggers } } } + + public interface IAsyncOneShotTrigger + { + UniTask OneShotAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOneShotTrigger + { + UniTask IAsyncOneShotTrigger.OneShotAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)this, core.Version); + } + } + + public sealed partial class AsyncTriggerHandler : IUniTaskSource, IResolvePromise, ICancelPromise, IDisposable + { + static Action cancellationCallback = CancellationCallback; + + readonly TriggerEvent trigger; + + CancellationToken cancellationToken; + CancellationTokenRegistration registration; + bool isDisposed; + bool callOnce; + + UniTaskCompletionSourceCore core; + + internal CancellationToken CancellationToken => cancellationToken; + + public AsyncTriggerHandler(TriggerEvent trigger, bool callOnce) + { + if (cancellationToken.IsCancellationRequested) + { + isDisposed = true; + return; + } + + this.trigger = trigger; + this.cancellationToken = default; + this.registration = default; + this.callOnce = callOnce; + + trigger.Add(this); + + TaskTracker.TrackActiveTask(this, 3); + } + + public AsyncTriggerHandler(TriggerEvent trigger, CancellationToken cancellationToken, bool callOnce) + { + if (cancellationToken.IsCancellationRequested) + { + isDisposed = true; + return; + } + + this.trigger = trigger; + this.cancellationToken = cancellationToken; + this.callOnce = callOnce; + + trigger.Add(this); + + if (cancellationToken.CanBeCanceled) + { + registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); + } + + TaskTracker.TrackActiveTask(this, 3); + } + + static void CancellationCallback(object state) + { + var self = (AsyncTriggerHandler)state; + self.Dispose(); + + self.core.TrySetCanceled(self.cancellationToken); + } + + public void Dispose() + { + if (!isDisposed) + { + isDisposed = true; + TaskTracker.RemoveTracking(this); + registration.Dispose(); + trigger.Remove(this); + } + } + + T IUniTaskSource.GetResult(short token) + { + try + { + return core.GetResult(token); + } + finally + { + if (callOnce) + { + Dispose(); + } + } + } + + bool IResolvePromise.TrySetResult(T result) + { + return core.TrySetResult(result); + } + + bool ICancelPromise.TrySetCanceled(CancellationToken cancellationToken) + { + return core.TrySetCanceled(cancellationToken); + } + + void IUniTaskSource.GetResult(short token) + { + ((IUniTaskSource)this).GetResult(token); + } + + UniTaskStatus IUniTaskSource.GetStatus(short token) + { + return core.GetStatus(token); + } + + UniTaskStatus IUniTaskSource.UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + } + + public sealed class TriggerEvent : IResolvePromise, ICancelPromise + { + // optimize: many cases, handler is single. + AsyncTriggerHandler singleHandler; + + List> handlers; + + public bool TrySetResult(T value) + { + List exceptions = null; + + if (singleHandler != null) + { + try + { + ((IResolvePromise)singleHandler).TrySetResult(value); + } + catch (Exception ex) + { + if (handlers == null) + { + throw; + } + else + { + exceptions = new List(); + exceptions.Add(ex); + } + } + } + + if (handlers != null) + { + // make snapshot + var rentArray = ArrayPoolUtil.CopyToRentArray(handlers); + var clearArray = true; + try + { + var array = rentArray.Array; + var len = rentArray.Length; + for (int i = 0; i < len; i++) + { + try + { + ((IResolvePromise)array[i]).TrySetResult(value); + } + catch (Exception ex) + { + if (exceptions == null) + { + exceptions = new List(); + } + exceptions.Add(ex); + } + finally + { + array[i] = null; + } + } + } + finally + { + rentArray.DisposeManually(clearArray); + } + } + + if (exceptions != null) + { + throw new AggregateException(exceptions); + } + + return true; + } + + public bool TrySetCanceled(CancellationToken cancellationToken) + { + List exceptions = null; + + if (singleHandler != null) + { + try + { + ((ICancelPromise)singleHandler).TrySetCanceled(cancellationToken); + } + catch (Exception ex) + { + if (handlers == null) + { + throw; + } + else + { + exceptions = new List(); + exceptions.Add(ex); + } + } + } + + if (handlers != null) + { + // make snapshot + var rentArray = ArrayPoolUtil.CopyToRentArray(handlers); + var clearArray = true; + try + { + var array = rentArray.Array; + var len = rentArray.Length; + for (int i = 0; i < len; i++) + { + try + { + ((ICancelPromise)array[i]).TrySetCanceled(cancellationToken); + } + catch (Exception ex) + { + if (exceptions == null) + { + exceptions = new List(); + } + exceptions.Add(ex); + } + finally + { + array[i] = null; + } + } + } + finally + { + rentArray.DisposeManually(clearArray); + } + } + + if (exceptions != null) + { + throw new AggregateException(exceptions); + } + + return true; + } + + public void Add(AsyncTriggerHandler handler) + { + if (singleHandler == null) + { + singleHandler = handler; + } + else + { + if (handlers != null) + { + handlers = new List>(); + handlers.Add(handler); + } + } + } + + public void Remove(AsyncTriggerHandler handler) + { + if (singleHandler == handler) + { + singleHandler = null; + } + else + { + if (handlers != null) + { + handlers.Remove(handler); + } + } + } + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs index e3dab78..8516cd9 100644 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs +++ b/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs @@ -25,7 +25,7 @@ namespace UniRx.Async namespace UniRx.Async.Triggers { - public static class AsyncTriggerExtensions + public static partial class AsyncTriggerExtensions { // Util. @@ -74,444 +74,6 @@ namespace UniRx.Async.Triggers { return component.GetAsyncAwakeTrigger().AwakeAsync(); } - - // Get Triggers. - - /// Get for OnAnimatorIKAsync | OnAnimatorMoveAsync. - public static AsyncAnimatorTrigger GetAsyncAnimatorTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnAnimatorIKAsync | OnAnimatorMoveAsync. - public static AsyncAnimatorTrigger GetAsyncAnimatorTrigger(this Component component) - { - return component.gameObject.GetAsyncAnimatorTrigger(); - } - - /// Get for AwakeAsync. - public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for AwakeAsync. - public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this Component component) - { - return component.gameObject.GetAsyncAwakeTrigger(); - } - - /// Get for OnBeginDragAsync. - public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnBeginDragAsync. - public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this Component component) - { - return component.gameObject.GetAsyncBeginDragTrigger(); - } - - /// Get for OnCancelAsync. - public static AsyncCancelTrigger GetAsyncCancelTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCancelAsync. - public static AsyncCancelTrigger GetAsyncCancelTrigger(this Component component) - { - return component.gameObject.GetAsyncCancelTrigger(); - } - - /// Get for OnCanvasGroupChangedAsync. - public static AsyncCanvasGroupChangedTrigger GetAsyncCanvasGroupChangedTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCanvasGroupChangedAsync. - public static AsyncCanvasGroupChangedTrigger GetAsyncCanvasGroupChangedTrigger(this Component component) - { - return component.gameObject.GetAsyncCanvasGroupChangedTrigger(); - } - - /// Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync. - public static AsyncCollision2DTrigger GetAsyncCollision2DTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync. - public static AsyncCollision2DTrigger GetAsyncCollision2DTrigger(this Component component) - { - return component.gameObject.GetAsyncCollision2DTrigger(); - } - - /// Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync. - public static AsyncCollisionTrigger GetAsyncCollisionTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync. - public static AsyncCollisionTrigger GetAsyncCollisionTrigger(this Component component) - { - return component.gameObject.GetAsyncCollisionTrigger(); - } - - /// Get for OnDeselectAsync. - public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDeselectAsync. - public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this Component component) - { - return component.gameObject.GetAsyncDeselectTrigger(); - } - - /// Get for OnDestroyAsync. - public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDestroyAsync. - public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this Component component) - { - return component.gameObject.GetAsyncDestroyTrigger(); - } - - /// Get for OnDragAsync. - public static AsyncDragTrigger GetAsyncDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDragAsync. - public static AsyncDragTrigger GetAsyncDragTrigger(this Component component) - { - return component.gameObject.GetAsyncDragTrigger(); - } - - /// Get for OnDropAsync. - public static AsyncDropTrigger GetAsyncDropTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDropAsync. - public static AsyncDropTrigger GetAsyncDropTrigger(this Component component) - { - return component.gameObject.GetAsyncDropTrigger(); - } - - /// Get for OnEnableAsync | OnDisableAsync. - public static AsyncEnableDisableTrigger GetAsyncEnableDisableTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnEnableAsync | OnDisableAsync. - public static AsyncEnableDisableTrigger GetAsyncEnableDisableTrigger(this Component component) - { - return component.gameObject.GetAsyncEnableDisableTrigger(); - } - - /// Get for OnEndDragAsync. - public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnEndDragAsync. - public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this Component component) - { - return component.gameObject.GetAsyncEndDragTrigger(); - } - - /// Get for FixedUpdateAsync. - public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for FixedUpdateAsync. - public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this Component component) - { - return component.gameObject.GetAsyncFixedUpdateTrigger(); - } - - /// Get for OnInitializePotentialDragAsync. - public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnInitializePotentialDragAsync. - public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this Component component) - { - return component.gameObject.GetAsyncInitializePotentialDragTrigger(); - } - - /// Get for OnJointBreakAsync. - public static AsyncJointTrigger GetAsyncJointTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnJointBreakAsync. - public static AsyncJointTrigger GetAsyncJointTrigger(this Component component) - { - return component.gameObject.GetAsyncJointTrigger(); - } - - /// Get for LateUpdateAsync. - public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for LateUpdateAsync. - public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this Component component) - { - return component.gameObject.GetAsyncLateUpdateTrigger(); - } - -#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO) - - /// Get for OnMouseDownAsync | OnMouseDragAsync | OnMouseEnterAsync | OnMouseExitAsync | OnMouseOverAsync | OnMouseUpAsync | OnMouseUpAsButtonAsync. - public static AsyncMouseTrigger GetAsyncMouseTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnMouseDownAsync | OnMouseDragAsync | OnMouseEnterAsync | OnMouseExitAsync | OnMouseOverAsync | OnMouseUpAsync | OnMouseUpAsButtonAsync. - public static AsyncMouseTrigger GetAsyncMouseTrigger(this Component component) - { - return component.gameObject.GetAsyncMouseTrigger(); - } - -#endif - - /// Get for OnMoveAsync. - public static AsyncMoveTrigger GetAsyncMoveTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnMoveAsync. - public static AsyncMoveTrigger GetAsyncMoveTrigger(this Component component) - { - return component.gameObject.GetAsyncMoveTrigger(); - } - - /// Get for OnParticleCollisionAsync | OnParticleTriggerAsync. - public static AsyncParticleTrigger GetAsyncParticleTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnParticleCollisionAsync | OnParticleTriggerAsync. - public static AsyncParticleTrigger GetAsyncParticleTrigger(this Component component) - { - return component.gameObject.GetAsyncParticleTrigger(); - } - - /// Get for OnPointerClickAsync. - public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerClickAsync. - public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerClickTrigger(); - } - - /// Get for OnPointerDownAsync. - public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerDownAsync. - public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerDownTrigger(); - } - - /// Get for OnPointerEnterAsync. - public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerEnterAsync. - public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerEnterTrigger(); - } - - /// Get for OnPointerExitAsync. - public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerExitAsync. - public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerExitTrigger(); - } - - /// Get for OnPointerUpAsync. - public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerUpAsync. - public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerUpTrigger(); - } - - /// Get for OnRectTransformDimensionsChange | OnRectTransformDimensionsChangeAsync | OnRectTransformRemoved | OnRectTransformRemovedAsync. - public static AsyncRectTransformTrigger GetAsyncRectTransformTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnRectTransformDimensionsChange | OnRectTransformDimensionsChangeAsync | OnRectTransformRemoved | OnRectTransformRemovedAsync. - public static AsyncRectTransformTrigger GetAsyncRectTransformTrigger(this Component component) - { - return component.gameObject.GetAsyncRectTransformTrigger(); - } - - /// Get for OnScrollAsync. - public static AsyncScrollTrigger GetAsyncScrollTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnScrollAsync. - public static AsyncScrollTrigger GetAsyncScrollTrigger(this Component component) - { - return component.gameObject.GetAsyncScrollTrigger(); - } - - /// Get for OnSelectAsync. - public static AsyncSelectTrigger GetAsyncSelectTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnSelectAsync. - public static AsyncSelectTrigger GetAsyncSelectTrigger(this Component component) - { - return component.gameObject.GetAsyncSelectTrigger(); - } - - /// Get for StartAsync. - public static AsyncStartTrigger GetAsyncStartTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for StartAsync. - public static AsyncStartTrigger GetAsyncStartTrigger(this Component component) - { - return component.gameObject.GetAsyncStartTrigger(); - } - - /// Get for OnSubmitAsync. - public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnSubmitAsync. - public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this Component component) - { - return component.gameObject.GetAsyncSubmitTrigger(); - } - - /// Get for OnBeforeTransformParentChangedAsync | OnTransformParentChangedAsync | OnTransformChildrenChangedAsync. - public static AsyncTransformChangedTrigger GetAsyncTransformChangedTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnBeforeTransformParentChangedAsync | OnTransformParentChangedAsync | OnTransformChildrenChangedAsync. - public static AsyncTransformChangedTrigger GetAsyncTransformChangedTrigger(this Component component) - { - return component.gameObject.GetAsyncTransformChangedTrigger(); - } - - /// Get for OnTriggerEnter2DAsync | OnTriggerExit2DAsync | OnTriggerStay2DAsync. - public static AsyncTrigger2DTrigger GetAsyncTrigger2DTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnTriggerEnter2DAsync | OnTriggerExit2DAsync | OnTriggerStay2DAsync. - public static AsyncTrigger2DTrigger GetAsyncTrigger2DTrigger(this Component component) - { - return component.gameObject.GetAsyncTrigger2DTrigger(); - } - - /// Get for OnTriggerEnterAsync | OnTriggerExitAsync | OnTriggerStayAsync. - public static AsyncTriggerTrigger GetAsyncTriggerTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnTriggerEnterAsync | OnTriggerExitAsync | OnTriggerStayAsync. - public static AsyncTriggerTrigger GetAsyncTriggerTrigger(this Component component) - { - return component.gameObject.GetAsyncTriggerTrigger(); - } - - /// Get for OnUpdateSelectedAsync. - public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnUpdateSelectedAsync. - public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this Component component) - { - return component.gameObject.GetAsyncUpdateSelectedTrigger(); - } - - /// Get for UpdateAsync. - public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for UpdateAsync. - public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this Component component) - { - return component.gameObject.GetAsyncUpdateTrigger(); - } - - /// Get for OnBecameInvisibleAsync | OnBecameVisibleAsync. - public static AsyncVisibleTrigger GetAsyncVisibleTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnBecameInvisibleAsync | OnBecameVisibleAsync. - public static AsyncVisibleTrigger GetAsyncVisibleTrigger(this Component component) - { - return component.gameObject.GetAsyncVisibleTrigger(); - } } } diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs deleted file mode 100644 index 8ee5d62..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncTriggerTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onTriggerEnter; - AsyncTriggerPromiseDictionary onTriggerEnters; - AsyncTriggerPromise onTriggerExit; - AsyncTriggerPromiseDictionary onTriggerExits; - AsyncTriggerPromise onTriggerStay; - AsyncTriggerPromiseDictionary onTriggerStays; - - - protected override IEnumerable GetPromises() - { - return Concat(onTriggerEnter, onTriggerEnters, onTriggerExit, onTriggerExits, onTriggerStay, onTriggerStays); - } - - - void OnTriggerEnter(Collider other) - { - TrySetResult(onTriggerEnter, onTriggerEnters, other); - } - - - public UniTask OnTriggerEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerEnter, ref onTriggerEnters, cancellationToken); - } - - - void OnTriggerExit(Collider other) - { - TrySetResult(onTriggerExit, onTriggerExits, other); - } - - - public UniTask OnTriggerExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerExit, ref onTriggerExits, cancellationToken); - } - - - void OnTriggerStay(Collider other) - { - TrySetResult(onTriggerStay, onTriggerStays, other); - } - - - public UniTask OnTriggerStayAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerStay, ref onTriggerStays, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs.meta deleted file mode 100644 index b9f7efb..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 46bbbbaa910762c4786906e10b6b7b8e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs deleted file mode 100644 index 025242c..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler - { - AsyncTriggerPromise onUpdateSelected; - AsyncTriggerPromiseDictionary onUpdateSelecteds; - - - protected override IEnumerable GetPromises() - { - return Concat(onUpdateSelected, onUpdateSelecteds); - } - - - void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData) - { - TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData); - } - - - public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onUpdateSelected, ref onUpdateSelecteds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs.meta deleted file mode 100644 index 395b43c..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ba5b0a4234e164e41b85f10b709d72e9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs deleted file mode 100644 index 20df476..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs +++ /dev/null @@ -1,200 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using UniRx.Async.Internal; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncUpdateTrigger : AsyncTriggerBase - { - AsyncTriggerPromise update; - AsyncTriggerPromiseDictionary updates; - - - protected override IEnumerable GetPromises() - { - return Concat(update, updates); - } - - - void Update() - { - TrySetResult(update, updates, AsyncUnit.Default); - } - - - public UniTask UpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref update, ref updates, cancellationToken); - } - - - } - - - - // TODO:remove 2. - public abstract class AsyncTriggerBase2 : MonoBehaviour - { - static readonly Action Callback = CancelCallback; - - bool calledAwake = false; - bool destroyCalled = false; - CancellationTokenRegistration[] registeredCancellations; - int registeredCancellationsCount; - - protected abstract IEnumerable GetPromises(); - - void Awake() - { - calledAwake = true; - } - - void OnDestroy() - { - if (destroyCalled) return; - destroyCalled = true; - foreach (var item in GetPromises()) - { - item.TrySetCanceled(); - } - if (registeredCancellations != null) - { - for (int i = 0; i < registeredCancellationsCount; i++) - { - registeredCancellations[i].Dispose(); - registeredCancellations[i] = default(CancellationTokenRegistration); - } - ArrayPool.Shared.Return(registeredCancellations); - } - } - - protected void TrySetResult(MinimumQueue> promise, AsyncTriggerPromiseDictionary promises, T result) - { - if (promise != null) - { - // TODO: - } - - if (promises != null) - { - PromiseHelper.TrySetResultAll(promises.Values, result); - } - } - - public UniTask CreatePromise(ref MinimumQueue> promise, ref AsyncTriggerPromiseDictionary promises, CancellationToken cancellationToken) - { - if (destroyCalled) return UniTask.FromCanceled(); - - if (!calledAwake) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - - if (!cancellationToken.CanBeCanceled) - { - if (promise == null) - { - promise = new MinimumQueue>(4); // kakko kari.(ArrayPool?) - } - - var tcs = AutoResetUniTaskCompletionSource.Create(); - promise.Enqueue(tcs); - return tcs.Task; - } - - - CancellationTokenRegistration registrationToken = default; - // TODO:atode. - // var registrationToken = cancellationToken.RegisterWithoutCaptureExecutionContext(Callback, Tuple.Create((ICancellationTokenKeyDictionary)promises, (ICancelablePromise)cancellablePromise)); - if (registeredCancellations == null) - { - registeredCancellations = ArrayPool.Shared.Rent(4); - } - - ArrayPoolUtil.EnsureCapacity(ref registeredCancellations, registeredCancellationsCount + 1, ArrayPool.Shared); - registeredCancellations[registeredCancellationsCount++] = registrationToken; - - // TODO:use at registration - { - if (promises == null) - { - promises = new AsyncTriggerPromiseDictionary(); - } - - var tcs = AutoResetUniTaskCompletionSource.Create(); - promises.Add(cancellationToken, tcs); - return tcs.Task; - } - } - - static void CancelCallback(object state) - { - // TODO:nantokasuru. - - //var tuple = (Tuple)state; - //var dict = tuple.Item1; - //var promise = tuple.Item2; - - //promise.TrySetCanceled(); - //dict.Remove(promise.RegisteredCancellationToken); - } - - class AwakeMonitor : IPlayerLoopItem - { - readonly AsyncTriggerBase2 trigger; - - public AwakeMonitor(AsyncTriggerBase2 trigger) - { - this.trigger = trigger; - } - - public bool MoveNext() - { - if (trigger.calledAwake) return false; - if (trigger == null) - { - trigger.OnDestroy(); - return false; - } - return true; - } - } - } - - - // TODO:remove 2. - [DisallowMultipleComponent] - public class AsyncUpdateTrigger2 : AsyncTriggerBase2 - { - MinimumQueue> promise; - AsyncTriggerPromiseDictionary promises; - - protected override IEnumerable GetPromises() - { - // TODO: - throw new NotImplementedException(); - } - - void Update() - { - // TrySetResult - } - - public UniTask UpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return CreatePromise(ref promise, ref promises, cancellationToken).AsUniTask(); - } - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs.meta deleted file mode 100644 index d2277f7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c6053bbe25af0d6439712f7c5fc4afc7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs deleted file mode 100644 index df9596e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncVisibleTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onBecameInvisible; - AsyncTriggerPromiseDictionary onBecameInvisibles; - AsyncTriggerPromise onBecameVisible; - AsyncTriggerPromiseDictionary onBecameVisibles; - - - protected override IEnumerable GetPromises() - { - return Concat(onBecameInvisible, onBecameInvisibles, onBecameVisible, onBecameVisibles); - } - - - void OnBecameInvisible() - { - TrySetResult(onBecameInvisible, onBecameInvisibles, AsyncUnit.Default); - } - - - public UniTask OnBecameInvisibleAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBecameInvisible, ref onBecameInvisibles, cancellationToken); - } - - - void OnBecameVisible() - { - TrySetResult(onBecameVisible, onBecameVisibles, AsyncUnit.Default); - } - - - public UniTask OnBecameVisibleAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBecameVisible, ref onBecameVisibles, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs.meta deleted file mode 100644 index 24b33ec..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 57ebfef2a87c49c46ad6454db136f3ef -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs new file mode 100644 index 0000000..1eb35a8 --- /dev/null +++ b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs @@ -0,0 +1,4525 @@ +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +using System.Threading; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace UniRx.Async.Triggers +{ +#region FixedUpdate + + public interface IAsyncFixedUpdateHandler + { + UniTask FixedUpdateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncFixedUpdateHandler + { + UniTask IAsyncFixedUpdateHandler.FixedUpdateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this Component component) + { + return component.gameObject.GetAsyncFixedUpdateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncFixedUpdateTrigger : AsyncTriggerBase + { + TriggerEvent fixedUpdateTriggerEvent; + + void FixedUpdate() + { + fixedUpdateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), false); + } + + public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), cancellationToken, false); + } + + public UniTask FixedUpdateAsync() + { + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), true)).FixedUpdateAsync(); + } + + public UniTask FixedUpdateAsync(CancellationToken cancellationToken) + { + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), cancellationToken, true)).FixedUpdateAsync(); + } + } +#endregion + +#region LateUpdate + + public interface IAsyncLateUpdateHandler + { + UniTask LateUpdateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncLateUpdateHandler + { + UniTask IAsyncLateUpdateHandler.LateUpdateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this Component component) + { + return component.gameObject.GetAsyncLateUpdateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncLateUpdateTrigger : AsyncTriggerBase + { + TriggerEvent lateUpdateTriggerEvent; + + void LateUpdate() + { + lateUpdateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), false); + } + + public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), cancellationToken, false); + } + + public UniTask LateUpdateAsync() + { + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), true)).LateUpdateAsync(); + } + + public UniTask LateUpdateAsync(CancellationToken cancellationToken) + { + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), cancellationToken, true)).LateUpdateAsync(); + } + } +#endregion + +#region AnimatorIK + + public interface IAsyncOnAnimatorIKHandler + { + UniTask OnAnimatorIKAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnAnimatorIKHandler + { + UniTask IAsyncOnAnimatorIKHandler.OnAnimatorIKAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncAnimatorIKTrigger GetAsyncAnimatorIKTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAnimatorIKTrigger GetAsyncAnimatorIKTrigger(this Component component) + { + return component.gameObject.GetAsyncAnimatorIKTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncAnimatorIKTrigger : AsyncTriggerBase + { + TriggerEvent onAnimatorIKTriggerEvent; + + void OnAnimatorIK(int layerIndex) + { + onAnimatorIKTriggerEvent?.TrySetResult((layerIndex)); + } + + public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), false); + } + + public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), cancellationToken, false); + } + + public UniTask OnAnimatorIKAsync() + { + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), true)).OnAnimatorIKAsync(); + } + + public UniTask OnAnimatorIKAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), cancellationToken, true)).OnAnimatorIKAsync(); + } + } +#endregion + +#region AnimatorMove + + public interface IAsyncOnAnimatorMoveHandler + { + UniTask OnAnimatorMoveAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnAnimatorMoveHandler + { + UniTask IAsyncOnAnimatorMoveHandler.OnAnimatorMoveAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncAnimatorMoveTrigger GetAsyncAnimatorMoveTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAnimatorMoveTrigger GetAsyncAnimatorMoveTrigger(this Component component) + { + return component.gameObject.GetAsyncAnimatorMoveTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncAnimatorMoveTrigger : AsyncTriggerBase + { + TriggerEvent onAnimatorMoveTriggerEvent; + + void OnAnimatorMove() + { + onAnimatorMoveTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), false); + } + + public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), cancellationToken, false); + } + + public UniTask OnAnimatorMoveAsync() + { + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), true)).OnAnimatorMoveAsync(); + } + + public UniTask OnAnimatorMoveAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), cancellationToken, true)).OnAnimatorMoveAsync(); + } + } +#endregion + +#region ApplicationFocus + + public interface IAsyncOnApplicationFocusHandler + { + UniTask OnApplicationFocusAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnApplicationFocusHandler + { + UniTask IAsyncOnApplicationFocusHandler.OnApplicationFocusAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncApplicationFocusTrigger GetAsyncApplicationFocusTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncApplicationFocusTrigger GetAsyncApplicationFocusTrigger(this Component component) + { + return component.gameObject.GetAsyncApplicationFocusTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncApplicationFocusTrigger : AsyncTriggerBase + { + TriggerEvent onApplicationFocusTriggerEvent; + + void OnApplicationFocus(bool hasFocus) + { + onApplicationFocusTriggerEvent?.TrySetResult((hasFocus)); + } + + public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), false); + } + + public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), cancellationToken, false); + } + + public UniTask OnApplicationFocusAsync() + { + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), true)).OnApplicationFocusAsync(); + } + + public UniTask OnApplicationFocusAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), cancellationToken, true)).OnApplicationFocusAsync(); + } + } +#endregion + +#region ApplicationPause + + public interface IAsyncOnApplicationPauseHandler + { + UniTask OnApplicationPauseAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnApplicationPauseHandler + { + UniTask IAsyncOnApplicationPauseHandler.OnApplicationPauseAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncApplicationPauseTrigger GetAsyncApplicationPauseTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncApplicationPauseTrigger GetAsyncApplicationPauseTrigger(this Component component) + { + return component.gameObject.GetAsyncApplicationPauseTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncApplicationPauseTrigger : AsyncTriggerBase + { + TriggerEvent onApplicationPauseTriggerEvent; + + void OnApplicationPause(bool pauseStatus) + { + onApplicationPauseTriggerEvent?.TrySetResult((pauseStatus)); + } + + public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), false); + } + + public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), cancellationToken, false); + } + + public UniTask OnApplicationPauseAsync() + { + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), true)).OnApplicationPauseAsync(); + } + + public UniTask OnApplicationPauseAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), cancellationToken, true)).OnApplicationPauseAsync(); + } + } +#endregion + +#region ApplicationQuit + + public interface IAsyncOnApplicationQuitHandler + { + UniTask OnApplicationQuitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnApplicationQuitHandler + { + UniTask IAsyncOnApplicationQuitHandler.OnApplicationQuitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncApplicationQuitTrigger GetAsyncApplicationQuitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncApplicationQuitTrigger GetAsyncApplicationQuitTrigger(this Component component) + { + return component.gameObject.GetAsyncApplicationQuitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncApplicationQuitTrigger : AsyncTriggerBase + { + TriggerEvent onApplicationQuitTriggerEvent; + + void OnApplicationQuit() + { + onApplicationQuitTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), false); + } + + public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), cancellationToken, false); + } + + public UniTask OnApplicationQuitAsync() + { + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), true)).OnApplicationQuitAsync(); + } + + public UniTask OnApplicationQuitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), cancellationToken, true)).OnApplicationQuitAsync(); + } + } +#endregion + +#region AudioFilterRead + + public interface IAsyncOnAudioFilterReadHandler + { + UniTask<(float[] data, int channels)> OnAudioFilterReadAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnAudioFilterReadHandler + { + UniTask<(float[] data, int channels)> IAsyncOnAudioFilterReadHandler.OnAudioFilterReadAsync() + { + core.Reset(); + return new UniTask<(float[] data, int channels)>((IUniTaskSource<(float[] data, int channels)>)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncAudioFilterReadTrigger GetAsyncAudioFilterReadTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAudioFilterReadTrigger GetAsyncAudioFilterReadTrigger(this Component component) + { + return component.gameObject.GetAsyncAudioFilterReadTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncAudioFilterReadTrigger : AsyncTriggerBase + { + TriggerEvent<(float[] data, int channels)> onAudioFilterReadTriggerEvent; + + void OnAudioFilterRead(float[] data, int channels) + { + onAudioFilterReadTriggerEvent?.TrySetResult((data, channels)); + } + + public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler() + { + return new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), false); + } + + public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), cancellationToken, false); + } + + public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync() + { + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), true)).OnAudioFilterReadAsync(); + } + + public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), cancellationToken, true)).OnAudioFilterReadAsync(); + } + } +#endregion + +#region BecameInvisible + + public interface IAsyncOnBecameInvisibleHandler + { + UniTask OnBecameInvisibleAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBecameInvisibleHandler + { + UniTask IAsyncOnBecameInvisibleHandler.OnBecameInvisibleAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBecameInvisibleTrigger GetAsyncBecameInvisibleTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBecameInvisibleTrigger GetAsyncBecameInvisibleTrigger(this Component component) + { + return component.gameObject.GetAsyncBecameInvisibleTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBecameInvisibleTrigger : AsyncTriggerBase + { + TriggerEvent onBecameInvisibleTriggerEvent; + + void OnBecameInvisible() + { + onBecameInvisibleTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), false); + } + + public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), cancellationToken, false); + } + + public UniTask OnBecameInvisibleAsync() + { + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), true)).OnBecameInvisibleAsync(); + } + + public UniTask OnBecameInvisibleAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), cancellationToken, true)).OnBecameInvisibleAsync(); + } + } +#endregion + +#region BecameVisible + + public interface IAsyncOnBecameVisibleHandler + { + UniTask OnBecameVisibleAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBecameVisibleHandler + { + UniTask IAsyncOnBecameVisibleHandler.OnBecameVisibleAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBecameVisibleTrigger GetAsyncBecameVisibleTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBecameVisibleTrigger GetAsyncBecameVisibleTrigger(this Component component) + { + return component.gameObject.GetAsyncBecameVisibleTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBecameVisibleTrigger : AsyncTriggerBase + { + TriggerEvent onBecameVisibleTriggerEvent; + + void OnBecameVisible() + { + onBecameVisibleTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), false); + } + + public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), cancellationToken, false); + } + + public UniTask OnBecameVisibleAsync() + { + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), true)).OnBecameVisibleAsync(); + } + + public UniTask OnBecameVisibleAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), cancellationToken, true)).OnBecameVisibleAsync(); + } + } +#endregion + +#region BeforeTransformParentChanged + + public interface IAsyncOnBeforeTransformParentChangedHandler + { + UniTask OnBeforeTransformParentChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBeforeTransformParentChangedHandler + { + UniTask IAsyncOnBeforeTransformParentChangedHandler.OnBeforeTransformParentChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBeforeTransformParentChangedTrigger GetAsyncBeforeTransformParentChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBeforeTransformParentChangedTrigger GetAsyncBeforeTransformParentChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncBeforeTransformParentChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBeforeTransformParentChangedTrigger : AsyncTriggerBase + { + TriggerEvent onBeforeTransformParentChangedTriggerEvent; + + void OnBeforeTransformParentChanged() + { + onBeforeTransformParentChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), false); + } + + public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnBeforeTransformParentChangedAsync() + { + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), true)).OnBeforeTransformParentChangedAsync(); + } + + public UniTask OnBeforeTransformParentChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), cancellationToken, true)).OnBeforeTransformParentChangedAsync(); + } + } +#endregion + +#region OnCanvasGroupChanged + + public interface IAsyncOnCanvasGroupChangedHandler + { + UniTask OnCanvasGroupChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCanvasGroupChangedHandler + { + UniTask IAsyncOnCanvasGroupChangedHandler.OnCanvasGroupChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncOnCanvasGroupChangedTrigger GetAsyncOnCanvasGroupChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncOnCanvasGroupChangedTrigger GetAsyncOnCanvasGroupChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncOnCanvasGroupChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncOnCanvasGroupChangedTrigger : AsyncTriggerBase + { + TriggerEvent onCanvasGroupChangedTriggerEvent; + + void OnCanvasGroupChanged() + { + onCanvasGroupChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), false); + } + + public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnCanvasGroupChangedAsync() + { + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), true)).OnCanvasGroupChangedAsync(); + } + + public UniTask OnCanvasGroupChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), cancellationToken, true)).OnCanvasGroupChangedAsync(); + } + } +#endregion + +#region CollisionEnter + + public interface IAsyncOnCollisionEnterHandler + { + UniTask OnCollisionEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionEnterHandler + { + UniTask IAsyncOnCollisionEnterHandler.OnCollisionEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionEnterTrigger GetAsyncCollisionEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionEnterTrigger GetAsyncCollisionEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionEnterTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionEnterTriggerEvent; + + void OnCollisionEnter(Collision coll) + { + onCollisionEnterTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), false); + } + + public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionEnterAsync() + { + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), true)).OnCollisionEnterAsync(); + } + + public UniTask OnCollisionEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), cancellationToken, true)).OnCollisionEnterAsync(); + } + } +#endregion + +#region CollisionEnter2D + + public interface IAsyncOnCollisionEnter2DHandler + { + UniTask OnCollisionEnter2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionEnter2DHandler + { + UniTask IAsyncOnCollisionEnter2DHandler.OnCollisionEnter2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionEnter2DTrigger GetAsyncCollisionEnter2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionEnter2DTrigger GetAsyncCollisionEnter2DTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionEnter2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionEnter2DTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionEnter2DTriggerEvent; + + void OnCollisionEnter2D(Collision2D coll) + { + onCollisionEnter2DTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), false); + } + + public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionEnter2DAsync() + { + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), true)).OnCollisionEnter2DAsync(); + } + + public UniTask OnCollisionEnter2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), cancellationToken, true)).OnCollisionEnter2DAsync(); + } + } +#endregion + +#region CollisionExit + + public interface IAsyncOnCollisionExitHandler + { + UniTask OnCollisionExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionExitHandler + { + UniTask IAsyncOnCollisionExitHandler.OnCollisionExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionExitTrigger GetAsyncCollisionExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionExitTrigger GetAsyncCollisionExitTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionExitTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionExitTriggerEvent; + + void OnCollisionExit(Collision coll) + { + onCollisionExitTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), false); + } + + public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionExitAsync() + { + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), true)).OnCollisionExitAsync(); + } + + public UniTask OnCollisionExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), cancellationToken, true)).OnCollisionExitAsync(); + } + } +#endregion + +#region CollisionExit2D + + public interface IAsyncOnCollisionExit2DHandler + { + UniTask OnCollisionExit2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionExit2DHandler + { + UniTask IAsyncOnCollisionExit2DHandler.OnCollisionExit2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionExit2DTrigger GetAsyncCollisionExit2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionExit2DTrigger GetAsyncCollisionExit2DTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionExit2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionExit2DTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionExit2DTriggerEvent; + + void OnCollisionExit2D(Collision2D coll) + { + onCollisionExit2DTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), false); + } + + public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionExit2DAsync() + { + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), true)).OnCollisionExit2DAsync(); + } + + public UniTask OnCollisionExit2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), cancellationToken, true)).OnCollisionExit2DAsync(); + } + } +#endregion + +#region CollisionStay + + public interface IAsyncOnCollisionStayHandler + { + UniTask OnCollisionStayAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionStayHandler + { + UniTask IAsyncOnCollisionStayHandler.OnCollisionStayAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionStayTrigger GetAsyncCollisionStayTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionStayTrigger GetAsyncCollisionStayTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionStayTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionStayTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionStayTriggerEvent; + + void OnCollisionStay(Collision coll) + { + onCollisionStayTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), false); + } + + public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionStayAsync() + { + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), true)).OnCollisionStayAsync(); + } + + public UniTask OnCollisionStayAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), cancellationToken, true)).OnCollisionStayAsync(); + } + } +#endregion + +#region CollisionStay2D + + public interface IAsyncOnCollisionStay2DHandler + { + UniTask OnCollisionStay2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionStay2DHandler + { + UniTask IAsyncOnCollisionStay2DHandler.OnCollisionStay2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionStay2DTrigger GetAsyncCollisionStay2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionStay2DTrigger GetAsyncCollisionStay2DTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionStay2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionStay2DTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionStay2DTriggerEvent; + + void OnCollisionStay2D(Collision2D coll) + { + onCollisionStay2DTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), false); + } + + public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionStay2DAsync() + { + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), true)).OnCollisionStay2DAsync(); + } + + public UniTask OnCollisionStay2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), cancellationToken, true)).OnCollisionStay2DAsync(); + } + } +#endregion + +#region ControllerColliderHit + + public interface IAsyncOnControllerColliderHitHandler + { + UniTask OnControllerColliderHitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnControllerColliderHitHandler + { + UniTask IAsyncOnControllerColliderHitHandler.OnControllerColliderHitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncControllerColliderHitTrigger GetAsyncControllerColliderHitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncControllerColliderHitTrigger GetAsyncControllerColliderHitTrigger(this Component component) + { + return component.gameObject.GetAsyncControllerColliderHitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncControllerColliderHitTrigger : AsyncTriggerBase + { + TriggerEvent onControllerColliderHitTriggerEvent; + + void OnControllerColliderHit(ControllerColliderHit hit) + { + onControllerColliderHitTriggerEvent?.TrySetResult((hit)); + } + + public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), false); + } + + public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), cancellationToken, false); + } + + public UniTask OnControllerColliderHitAsync() + { + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), true)).OnControllerColliderHitAsync(); + } + + public UniTask OnControllerColliderHitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), cancellationToken, true)).OnControllerColliderHitAsync(); + } + } +#endregion + +#region Disable + + public interface IAsyncOnDisableHandler + { + UniTask OnDisableAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDisableHandler + { + UniTask IAsyncOnDisableHandler.OnDisableAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDisableTrigger GetAsyncDisableTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDisableTrigger GetAsyncDisableTrigger(this Component component) + { + return component.gameObject.GetAsyncDisableTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDisableTrigger : AsyncTriggerBase + { + TriggerEvent onDisableTriggerEvent; + + void OnDisable() + { + onDisableTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnDisableHandler GetOnDisableAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), false); + } + + public IAsyncOnDisableHandler GetOnDisableAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), cancellationToken, false); + } + + public UniTask OnDisableAsync() + { + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), true)).OnDisableAsync(); + } + + public UniTask OnDisableAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), cancellationToken, true)).OnDisableAsync(); + } + } +#endregion + +#region DrawGizmos + + public interface IAsyncOnDrawGizmosHandler + { + UniTask OnDrawGizmosAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDrawGizmosHandler + { + UniTask IAsyncOnDrawGizmosHandler.OnDrawGizmosAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDrawGizmosTrigger GetAsyncDrawGizmosTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDrawGizmosTrigger GetAsyncDrawGizmosTrigger(this Component component) + { + return component.gameObject.GetAsyncDrawGizmosTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDrawGizmosTrigger : AsyncTriggerBase + { + TriggerEvent onDrawGizmosTriggerEvent; + + void OnDrawGizmos() + { + onDrawGizmosTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), false); + } + + public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), cancellationToken, false); + } + + public UniTask OnDrawGizmosAsync() + { + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), true)).OnDrawGizmosAsync(); + } + + public UniTask OnDrawGizmosAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), cancellationToken, true)).OnDrawGizmosAsync(); + } + } +#endregion + +#region DrawGizmosSelected + + public interface IAsyncOnDrawGizmosSelectedHandler + { + UniTask OnDrawGizmosSelectedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDrawGizmosSelectedHandler + { + UniTask IAsyncOnDrawGizmosSelectedHandler.OnDrawGizmosSelectedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDrawGizmosSelectedTrigger GetAsyncDrawGizmosSelectedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDrawGizmosSelectedTrigger GetAsyncDrawGizmosSelectedTrigger(this Component component) + { + return component.gameObject.GetAsyncDrawGizmosSelectedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDrawGizmosSelectedTrigger : AsyncTriggerBase + { + TriggerEvent onDrawGizmosSelectedTriggerEvent; + + void OnDrawGizmosSelected() + { + onDrawGizmosSelectedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), false); + } + + public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), cancellationToken, false); + } + + public UniTask OnDrawGizmosSelectedAsync() + { + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), true)).OnDrawGizmosSelectedAsync(); + } + + public UniTask OnDrawGizmosSelectedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), cancellationToken, true)).OnDrawGizmosSelectedAsync(); + } + } +#endregion + +#region Enable + + public interface IAsyncOnEnableHandler + { + UniTask OnEnableAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnEnableHandler + { + UniTask IAsyncOnEnableHandler.OnEnableAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncEnableTrigger GetAsyncEnableTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncEnableTrigger GetAsyncEnableTrigger(this Component component) + { + return component.gameObject.GetAsyncEnableTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncEnableTrigger : AsyncTriggerBase + { + TriggerEvent onEnableTriggerEvent; + + void OnEnable() + { + onEnableTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnEnableHandler GetOnEnableAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), false); + } + + public IAsyncOnEnableHandler GetOnEnableAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), cancellationToken, false); + } + + public UniTask OnEnableAsync() + { + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), true)).OnEnableAsync(); + } + + public UniTask OnEnableAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), cancellationToken, true)).OnEnableAsync(); + } + } +#endregion + +#region GUI + + public interface IAsyncOnGUIHandler + { + UniTask OnGUIAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnGUIHandler + { + UniTask IAsyncOnGUIHandler.OnGUIAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncGUITrigger GetAsyncGUITrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncGUITrigger GetAsyncGUITrigger(this Component component) + { + return component.gameObject.GetAsyncGUITrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncGUITrigger : AsyncTriggerBase + { + TriggerEvent onGUITriggerEvent; + + void OnGUI() + { + onGUITriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnGUIHandler GetOnGUIAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), false); + } + + public IAsyncOnGUIHandler GetOnGUIAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), cancellationToken, false); + } + + public UniTask OnGUIAsync() + { + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), true)).OnGUIAsync(); + } + + public UniTask OnGUIAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), cancellationToken, true)).OnGUIAsync(); + } + } +#endregion + +#region JointBreak + + public interface IAsyncOnJointBreakHandler + { + UniTask OnJointBreakAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnJointBreakHandler + { + UniTask IAsyncOnJointBreakHandler.OnJointBreakAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncJointBreakTrigger GetAsyncJointBreakTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncJointBreakTrigger GetAsyncJointBreakTrigger(this Component component) + { + return component.gameObject.GetAsyncJointBreakTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncJointBreakTrigger : AsyncTriggerBase + { + TriggerEvent onJointBreakTriggerEvent; + + void OnJointBreak(float breakForce) + { + onJointBreakTriggerEvent?.TrySetResult((breakForce)); + } + + public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), false); + } + + public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), cancellationToken, false); + } + + public UniTask OnJointBreakAsync() + { + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), true)).OnJointBreakAsync(); + } + + public UniTask OnJointBreakAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), cancellationToken, true)).OnJointBreakAsync(); + } + } +#endregion + +#region JointBreak2D + + public interface IAsyncOnJointBreak2DHandler + { + UniTask OnJointBreak2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnJointBreak2DHandler + { + UniTask IAsyncOnJointBreak2DHandler.OnJointBreak2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncJointBreak2DTrigger GetAsyncJointBreak2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncJointBreak2DTrigger GetAsyncJointBreak2DTrigger(this Component component) + { + return component.gameObject.GetAsyncJointBreak2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncJointBreak2DTrigger : AsyncTriggerBase + { + TriggerEvent onJointBreak2DTriggerEvent; + + void OnJointBreak2D(Joint2D brokenJoint) + { + onJointBreak2DTriggerEvent?.TrySetResult((brokenJoint)); + } + + public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), false); + } + + public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnJointBreak2DAsync() + { + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), true)).OnJointBreak2DAsync(); + } + + public UniTask OnJointBreak2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), cancellationToken, true)).OnJointBreak2DAsync(); + } + } +#endregion + +#region MouseDown + + public interface IAsyncOnMouseDownHandler + { + UniTask OnMouseDownAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseDownHandler + { + UniTask IAsyncOnMouseDownHandler.OnMouseDownAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseDownTrigger GetAsyncMouseDownTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseDownTrigger GetAsyncMouseDownTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseDownTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseDownTrigger : AsyncTriggerBase + { + TriggerEvent onMouseDownTriggerEvent; + + void OnMouseDown() + { + onMouseDownTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), false); + } + + public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseDownAsync() + { + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), true)).OnMouseDownAsync(); + } + + public UniTask OnMouseDownAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), cancellationToken, true)).OnMouseDownAsync(); + } + } +#endregion + +#region MouseDrag + + public interface IAsyncOnMouseDragHandler + { + UniTask OnMouseDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseDragHandler + { + UniTask IAsyncOnMouseDragHandler.OnMouseDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseDragTrigger GetAsyncMouseDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseDragTrigger GetAsyncMouseDragTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseDragTrigger : AsyncTriggerBase + { + TriggerEvent onMouseDragTriggerEvent; + + void OnMouseDrag() + { + onMouseDragTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), false); + } + + public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseDragAsync() + { + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), true)).OnMouseDragAsync(); + } + + public UniTask OnMouseDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), cancellationToken, true)).OnMouseDragAsync(); + } + } +#endregion + +#region MouseEnter + + public interface IAsyncOnMouseEnterHandler + { + UniTask OnMouseEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseEnterHandler + { + UniTask IAsyncOnMouseEnterHandler.OnMouseEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseEnterTrigger GetAsyncMouseEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseEnterTrigger GetAsyncMouseEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseEnterTrigger : AsyncTriggerBase + { + TriggerEvent onMouseEnterTriggerEvent; + + void OnMouseEnter() + { + onMouseEnterTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), false); + } + + public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseEnterAsync() + { + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), true)).OnMouseEnterAsync(); + } + + public UniTask OnMouseEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), cancellationToken, true)).OnMouseEnterAsync(); + } + } +#endregion + +#region MouseExit + + public interface IAsyncOnMouseExitHandler + { + UniTask OnMouseExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseExitHandler + { + UniTask IAsyncOnMouseExitHandler.OnMouseExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseExitTrigger GetAsyncMouseExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseExitTrigger GetAsyncMouseExitTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseExitTrigger : AsyncTriggerBase + { + TriggerEvent onMouseExitTriggerEvent; + + void OnMouseExit() + { + onMouseExitTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), false); + } + + public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseExitAsync() + { + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), true)).OnMouseExitAsync(); + } + + public UniTask OnMouseExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), cancellationToken, true)).OnMouseExitAsync(); + } + } +#endregion + +#region MouseOver + + public interface IAsyncOnMouseOverHandler + { + UniTask OnMouseOverAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseOverHandler + { + UniTask IAsyncOnMouseOverHandler.OnMouseOverAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseOverTrigger GetAsyncMouseOverTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseOverTrigger GetAsyncMouseOverTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseOverTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseOverTrigger : AsyncTriggerBase + { + TriggerEvent onMouseOverTriggerEvent; + + void OnMouseOver() + { + onMouseOverTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), false); + } + + public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseOverAsync() + { + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), true)).OnMouseOverAsync(); + } + + public UniTask OnMouseOverAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), cancellationToken, true)).OnMouseOverAsync(); + } + } +#endregion + +#region MouseUp + + public interface IAsyncOnMouseUpHandler + { + UniTask OnMouseUpAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseUpHandler + { + UniTask IAsyncOnMouseUpHandler.OnMouseUpAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseUpTrigger GetAsyncMouseUpTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseUpTrigger GetAsyncMouseUpTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseUpTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseUpTrigger : AsyncTriggerBase + { + TriggerEvent onMouseUpTriggerEvent; + + void OnMouseUp() + { + onMouseUpTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), false); + } + + public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseUpAsync() + { + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), true)).OnMouseUpAsync(); + } + + public UniTask OnMouseUpAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), cancellationToken, true)).OnMouseUpAsync(); + } + } +#endregion + +#region MouseUpAsButton + + public interface IAsyncOnMouseUpAsButtonHandler + { + UniTask OnMouseUpAsButtonAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseUpAsButtonHandler + { + UniTask IAsyncOnMouseUpAsButtonHandler.OnMouseUpAsButtonAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseUpAsButtonTrigger GetAsyncMouseUpAsButtonTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseUpAsButtonTrigger GetAsyncMouseUpAsButtonTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseUpAsButtonTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseUpAsButtonTrigger : AsyncTriggerBase + { + TriggerEvent onMouseUpAsButtonTriggerEvent; + + void OnMouseUpAsButton() + { + onMouseUpAsButtonTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), false); + } + + public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseUpAsButtonAsync() + { + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), true)).OnMouseUpAsButtonAsync(); + } + + public UniTask OnMouseUpAsButtonAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), cancellationToken, true)).OnMouseUpAsButtonAsync(); + } + } +#endregion + +#region ParticleCollision + + public interface IAsyncOnParticleCollisionHandler + { + UniTask OnParticleCollisionAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleCollisionHandler + { + UniTask IAsyncOnParticleCollisionHandler.OnParticleCollisionAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleCollisionTrigger GetAsyncParticleCollisionTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleCollisionTrigger GetAsyncParticleCollisionTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleCollisionTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleCollisionTrigger : AsyncTriggerBase + { + TriggerEvent onParticleCollisionTriggerEvent; + + void OnParticleCollision(GameObject other) + { + onParticleCollisionTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), false); + } + + public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleCollisionAsync() + { + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), true)).OnParticleCollisionAsync(); + } + + public UniTask OnParticleCollisionAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), cancellationToken, true)).OnParticleCollisionAsync(); + } + } +#endregion + +#region ParticleSystemStopped + + public interface IAsyncOnParticleSystemStoppedHandler + { + UniTask OnParticleSystemStoppedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleSystemStoppedHandler + { + UniTask IAsyncOnParticleSystemStoppedHandler.OnParticleSystemStoppedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleSystemStoppedTrigger GetAsyncParticleSystemStoppedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleSystemStoppedTrigger GetAsyncParticleSystemStoppedTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleSystemStoppedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleSystemStoppedTrigger : AsyncTriggerBase + { + TriggerEvent onParticleSystemStoppedTriggerEvent; + + void OnParticleSystemStopped() + { + onParticleSystemStoppedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), false); + } + + public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleSystemStoppedAsync() + { + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), true)).OnParticleSystemStoppedAsync(); + } + + public UniTask OnParticleSystemStoppedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), cancellationToken, true)).OnParticleSystemStoppedAsync(); + } + } +#endregion + +#region ParticleTrigger + + public interface IAsyncOnParticleTriggerHandler + { + UniTask OnParticleTriggerAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleTriggerHandler + { + UniTask IAsyncOnParticleTriggerHandler.OnParticleTriggerAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleTriggerTrigger GetAsyncParticleTriggerTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleTriggerTrigger GetAsyncParticleTriggerTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleTriggerTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleTriggerTrigger : AsyncTriggerBase + { + TriggerEvent onParticleTriggerTriggerEvent; + + void OnParticleTrigger() + { + onParticleTriggerTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), false); + } + + public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleTriggerAsync() + { + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), true)).OnParticleTriggerAsync(); + } + + public UniTask OnParticleTriggerAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), cancellationToken, true)).OnParticleTriggerAsync(); + } + } +#endregion + +#region ParticleUpdateJobScheduled +#if UNITY_2019_3_OR_NEWER + + public interface IAsyncOnParticleUpdateJobScheduledHandler + { + UniTask OnParticleUpdateJobScheduledAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleUpdateJobScheduledHandler + { + UniTask IAsyncOnParticleUpdateJobScheduledHandler.OnParticleUpdateJobScheduledAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleUpdateJobScheduledTrigger GetAsyncParticleUpdateJobScheduledTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleUpdateJobScheduledTrigger GetAsyncParticleUpdateJobScheduledTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleUpdateJobScheduledTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleUpdateJobScheduledTrigger : AsyncTriggerBase + { + TriggerEvent onParticleUpdateJobScheduledTriggerEvent; + + void OnParticleUpdateJobScheduled(UnityEngine.ParticleSystemJobs.ParticleSystemJobData particles) + { + onParticleUpdateJobScheduledTriggerEvent?.TrySetResult((particles)); + } + + public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), false); + } + + public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleUpdateJobScheduledAsync() + { + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), true)).OnParticleUpdateJobScheduledAsync(); + } + + public UniTask OnParticleUpdateJobScheduledAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), cancellationToken, true)).OnParticleUpdateJobScheduledAsync(); + } + } +#endif +#endregion + +#region PostRender + + public interface IAsyncOnPostRenderHandler + { + UniTask OnPostRenderAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPostRenderHandler + { + UniTask IAsyncOnPostRenderHandler.OnPostRenderAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPostRenderTrigger GetAsyncPostRenderTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPostRenderTrigger GetAsyncPostRenderTrigger(this Component component) + { + return component.gameObject.GetAsyncPostRenderTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPostRenderTrigger : AsyncTriggerBase + { + TriggerEvent onPostRenderTriggerEvent; + + void OnPostRender() + { + onPostRenderTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), false); + } + + public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), cancellationToken, false); + } + + public UniTask OnPostRenderAsync() + { + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), true)).OnPostRenderAsync(); + } + + public UniTask OnPostRenderAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), cancellationToken, true)).OnPostRenderAsync(); + } + } +#endregion + +#region PreCull + + public interface IAsyncOnPreCullHandler + { + UniTask OnPreCullAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPreCullHandler + { + UniTask IAsyncOnPreCullHandler.OnPreCullAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPreCullTrigger GetAsyncPreCullTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPreCullTrigger GetAsyncPreCullTrigger(this Component component) + { + return component.gameObject.GetAsyncPreCullTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPreCullTrigger : AsyncTriggerBase + { + TriggerEvent onPreCullTriggerEvent; + + void OnPreCull() + { + onPreCullTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), false); + } + + public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), cancellationToken, false); + } + + public UniTask OnPreCullAsync() + { + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), true)).OnPreCullAsync(); + } + + public UniTask OnPreCullAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), cancellationToken, true)).OnPreCullAsync(); + } + } +#endregion + +#region PreRender + + public interface IAsyncOnPreRenderHandler + { + UniTask OnPreRenderAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPreRenderHandler + { + UniTask IAsyncOnPreRenderHandler.OnPreRenderAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPreRenderTrigger GetAsyncPreRenderTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPreRenderTrigger GetAsyncPreRenderTrigger(this Component component) + { + return component.gameObject.GetAsyncPreRenderTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPreRenderTrigger : AsyncTriggerBase + { + TriggerEvent onPreRenderTriggerEvent; + + void OnPreRender() + { + onPreRenderTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), false); + } + + public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), cancellationToken, false); + } + + public UniTask OnPreRenderAsync() + { + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), true)).OnPreRenderAsync(); + } + + public UniTask OnPreRenderAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), cancellationToken, true)).OnPreRenderAsync(); + } + } +#endregion + +#region RectTransformDimensionsChange + + public interface IAsyncOnRectTransformDimensionsChangeHandler + { + UniTask OnRectTransformDimensionsChangeAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRectTransformDimensionsChangeHandler + { + UniTask IAsyncOnRectTransformDimensionsChangeHandler.OnRectTransformDimensionsChangeAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRectTransformDimensionsChangeTrigger GetAsyncRectTransformDimensionsChangeTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRectTransformDimensionsChangeTrigger GetAsyncRectTransformDimensionsChangeTrigger(this Component component) + { + return component.gameObject.GetAsyncRectTransformDimensionsChangeTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRectTransformDimensionsChangeTrigger : AsyncTriggerBase + { + TriggerEvent onRectTransformDimensionsChangeTriggerEvent; + + void OnRectTransformDimensionsChange() + { + onRectTransformDimensionsChangeTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), false); + } + + public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), cancellationToken, false); + } + + public UniTask OnRectTransformDimensionsChangeAsync() + { + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), true)).OnRectTransformDimensionsChangeAsync(); + } + + public UniTask OnRectTransformDimensionsChangeAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), cancellationToken, true)).OnRectTransformDimensionsChangeAsync(); + } + } +#endregion + +#region RectTransformRemoved + + public interface IAsyncOnRectTransformRemovedHandler + { + UniTask OnRectTransformRemovedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRectTransformRemovedHandler + { + UniTask IAsyncOnRectTransformRemovedHandler.OnRectTransformRemovedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRectTransformRemovedTrigger GetAsyncRectTransformRemovedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRectTransformRemovedTrigger GetAsyncRectTransformRemovedTrigger(this Component component) + { + return component.gameObject.GetAsyncRectTransformRemovedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRectTransformRemovedTrigger : AsyncTriggerBase + { + TriggerEvent onRectTransformRemovedTriggerEvent; + + void OnRectTransformRemoved() + { + onRectTransformRemovedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), false); + } + + public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), cancellationToken, false); + } + + public UniTask OnRectTransformRemovedAsync() + { + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), true)).OnRectTransformRemovedAsync(); + } + + public UniTask OnRectTransformRemovedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), cancellationToken, true)).OnRectTransformRemovedAsync(); + } + } +#endregion + +#region RenderImage + + public interface IAsyncOnRenderImageHandler + { + UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRenderImageHandler + { + UniTask<(RenderTexture source, RenderTexture destination)> IAsyncOnRenderImageHandler.OnRenderImageAsync() + { + core.Reset(); + return new UniTask<(RenderTexture source, RenderTexture destination)>((IUniTaskSource<(RenderTexture source, RenderTexture destination)>)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRenderImageTrigger GetAsyncRenderImageTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRenderImageTrigger GetAsyncRenderImageTrigger(this Component component) + { + return component.gameObject.GetAsyncRenderImageTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRenderImageTrigger : AsyncTriggerBase + { + TriggerEvent<(RenderTexture source, RenderTexture destination)> onRenderImageTriggerEvent; + + void OnRenderImage(RenderTexture source, RenderTexture destination) + { + onRenderImageTriggerEvent?.TrySetResult((source, destination)); + } + + public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler() + { + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), false); + } + + public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), cancellationToken, false); + } + + public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync() + { + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), true)).OnRenderImageAsync(); + } + + public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), cancellationToken, true)).OnRenderImageAsync(); + } + } +#endregion + +#region RenderObject + + public interface IAsyncOnRenderObjectHandler + { + UniTask OnRenderObjectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRenderObjectHandler + { + UniTask IAsyncOnRenderObjectHandler.OnRenderObjectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRenderObjectTrigger GetAsyncRenderObjectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRenderObjectTrigger GetAsyncRenderObjectTrigger(this Component component) + { + return component.gameObject.GetAsyncRenderObjectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRenderObjectTrigger : AsyncTriggerBase + { + TriggerEvent onRenderObjectTriggerEvent; + + void OnRenderObject() + { + onRenderObjectTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), false); + } + + public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), cancellationToken, false); + } + + public UniTask OnRenderObjectAsync() + { + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), true)).OnRenderObjectAsync(); + } + + public UniTask OnRenderObjectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), cancellationToken, true)).OnRenderObjectAsync(); + } + } +#endregion + +#region ServerInitialized + + public interface IAsyncOnServerInitializedHandler + { + UniTask OnServerInitializedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnServerInitializedHandler + { + UniTask IAsyncOnServerInitializedHandler.OnServerInitializedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncServerInitializedTrigger GetAsyncServerInitializedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncServerInitializedTrigger GetAsyncServerInitializedTrigger(this Component component) + { + return component.gameObject.GetAsyncServerInitializedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncServerInitializedTrigger : AsyncTriggerBase + { + TriggerEvent onServerInitializedTriggerEvent; + + void OnServerInitialized() + { + onServerInitializedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), false); + } + + public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), cancellationToken, false); + } + + public UniTask OnServerInitializedAsync() + { + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), true)).OnServerInitializedAsync(); + } + + public UniTask OnServerInitializedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), cancellationToken, true)).OnServerInitializedAsync(); + } + } +#endregion + +#region TransformChildrenChanged + + public interface IAsyncOnTransformChildrenChangedHandler + { + UniTask OnTransformChildrenChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTransformChildrenChangedHandler + { + UniTask IAsyncOnTransformChildrenChangedHandler.OnTransformChildrenChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTransformChildrenChangedTrigger GetAsyncTransformChildrenChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTransformChildrenChangedTrigger GetAsyncTransformChildrenChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncTransformChildrenChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTransformChildrenChangedTrigger : AsyncTriggerBase + { + TriggerEvent onTransformChildrenChangedTriggerEvent; + + void OnTransformChildrenChanged() + { + onTransformChildrenChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), false); + } + + public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnTransformChildrenChangedAsync() + { + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), true)).OnTransformChildrenChangedAsync(); + } + + public UniTask OnTransformChildrenChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), cancellationToken, true)).OnTransformChildrenChangedAsync(); + } + } +#endregion + +#region TransformParentChanged + + public interface IAsyncOnTransformParentChangedHandler + { + UniTask OnTransformParentChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTransformParentChangedHandler + { + UniTask IAsyncOnTransformParentChangedHandler.OnTransformParentChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTransformParentChangedTrigger GetAsyncTransformParentChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTransformParentChangedTrigger GetAsyncTransformParentChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncTransformParentChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTransformParentChangedTrigger : AsyncTriggerBase + { + TriggerEvent onTransformParentChangedTriggerEvent; + + void OnTransformParentChanged() + { + onTransformParentChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), false); + } + + public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnTransformParentChangedAsync() + { + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), true)).OnTransformParentChangedAsync(); + } + + public UniTask OnTransformParentChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), cancellationToken, true)).OnTransformParentChangedAsync(); + } + } +#endregion + +#region TriggerEnter + + public interface IAsyncOnTriggerEnterHandler + { + UniTask OnTriggerEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerEnterHandler + { + UniTask IAsyncOnTriggerEnterHandler.OnTriggerEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerEnterTrigger GetAsyncTriggerEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerEnterTrigger GetAsyncTriggerEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerEnterTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerEnterTriggerEvent; + + void OnTriggerEnter(Collider other) + { + onTriggerEnterTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), false); + } + + public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerEnterAsync() + { + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), true)).OnTriggerEnterAsync(); + } + + public UniTask OnTriggerEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), cancellationToken, true)).OnTriggerEnterAsync(); + } + } +#endregion + +#region TriggerEnter2D + + public interface IAsyncOnTriggerEnter2DHandler + { + UniTask OnTriggerEnter2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerEnter2DHandler + { + UniTask IAsyncOnTriggerEnter2DHandler.OnTriggerEnter2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerEnter2DTrigger GetAsyncTriggerEnter2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerEnter2DTrigger GetAsyncTriggerEnter2DTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerEnter2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerEnter2DTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerEnter2DTriggerEvent; + + void OnTriggerEnter2D(Collider2D other) + { + onTriggerEnter2DTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), false); + } + + public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerEnter2DAsync() + { + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), true)).OnTriggerEnter2DAsync(); + } + + public UniTask OnTriggerEnter2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), cancellationToken, true)).OnTriggerEnter2DAsync(); + } + } +#endregion + +#region TriggerExit + + public interface IAsyncOnTriggerExitHandler + { + UniTask OnTriggerExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerExitHandler + { + UniTask IAsyncOnTriggerExitHandler.OnTriggerExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerExitTrigger GetAsyncTriggerExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerExitTrigger GetAsyncTriggerExitTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerExitTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerExitTriggerEvent; + + void OnTriggerExit(Collider other) + { + onTriggerExitTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), false); + } + + public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerExitAsync() + { + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), true)).OnTriggerExitAsync(); + } + + public UniTask OnTriggerExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), cancellationToken, true)).OnTriggerExitAsync(); + } + } +#endregion + +#region TriggerExit2D + + public interface IAsyncOnTriggerExit2DHandler + { + UniTask OnTriggerExit2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerExit2DHandler + { + UniTask IAsyncOnTriggerExit2DHandler.OnTriggerExit2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerExit2DTrigger GetAsyncTriggerExit2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerExit2DTrigger GetAsyncTriggerExit2DTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerExit2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerExit2DTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerExit2DTriggerEvent; + + void OnTriggerExit2D(Collider2D other) + { + onTriggerExit2DTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), false); + } + + public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerExit2DAsync() + { + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), true)).OnTriggerExit2DAsync(); + } + + public UniTask OnTriggerExit2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), cancellationToken, true)).OnTriggerExit2DAsync(); + } + } +#endregion + +#region TriggerStay + + public interface IAsyncOnTriggerStayHandler + { + UniTask OnTriggerStayAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerStayHandler + { + UniTask IAsyncOnTriggerStayHandler.OnTriggerStayAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerStayTrigger GetAsyncTriggerStayTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerStayTrigger GetAsyncTriggerStayTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerStayTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerStayTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerStayTriggerEvent; + + void OnTriggerStay(Collider other) + { + onTriggerStayTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), false); + } + + public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerStayAsync() + { + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), true)).OnTriggerStayAsync(); + } + + public UniTask OnTriggerStayAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), cancellationToken, true)).OnTriggerStayAsync(); + } + } +#endregion + +#region TriggerStay2D + + public interface IAsyncOnTriggerStay2DHandler + { + UniTask OnTriggerStay2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerStay2DHandler + { + UniTask IAsyncOnTriggerStay2DHandler.OnTriggerStay2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerStay2DTrigger GetAsyncTriggerStay2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerStay2DTrigger GetAsyncTriggerStay2DTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerStay2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerStay2DTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerStay2DTriggerEvent; + + void OnTriggerStay2D(Collider2D other) + { + onTriggerStay2DTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), false); + } + + public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerStay2DAsync() + { + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), true)).OnTriggerStay2DAsync(); + } + + public UniTask OnTriggerStay2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), cancellationToken, true)).OnTriggerStay2DAsync(); + } + } +#endregion + +#region Validate + + public interface IAsyncOnValidateHandler + { + UniTask OnValidateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnValidateHandler + { + UniTask IAsyncOnValidateHandler.OnValidateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncValidateTrigger GetAsyncValidateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncValidateTrigger GetAsyncValidateTrigger(this Component component) + { + return component.gameObject.GetAsyncValidateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncValidateTrigger : AsyncTriggerBase + { + TriggerEvent onValidateTriggerEvent; + + void OnValidate() + { + onValidateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnValidateHandler GetOnValidateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), false); + } + + public IAsyncOnValidateHandler GetOnValidateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), cancellationToken, false); + } + + public UniTask OnValidateAsync() + { + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), true)).OnValidateAsync(); + } + + public UniTask OnValidateAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), cancellationToken, true)).OnValidateAsync(); + } + } +#endregion + +#region WillRenderObject + + public interface IAsyncOnWillRenderObjectHandler + { + UniTask OnWillRenderObjectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnWillRenderObjectHandler + { + UniTask IAsyncOnWillRenderObjectHandler.OnWillRenderObjectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncWillRenderObjectTrigger GetAsyncWillRenderObjectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncWillRenderObjectTrigger GetAsyncWillRenderObjectTrigger(this Component component) + { + return component.gameObject.GetAsyncWillRenderObjectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncWillRenderObjectTrigger : AsyncTriggerBase + { + TriggerEvent onWillRenderObjectTriggerEvent; + + void OnWillRenderObject() + { + onWillRenderObjectTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), false); + } + + public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), cancellationToken, false); + } + + public UniTask OnWillRenderObjectAsync() + { + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), true)).OnWillRenderObjectAsync(); + } + + public UniTask OnWillRenderObjectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), cancellationToken, true)).OnWillRenderObjectAsync(); + } + } +#endregion + +#region Reset + + public interface IAsyncResetHandler + { + UniTask ResetAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncResetHandler + { + UniTask IAsyncResetHandler.ResetAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncResetTrigger GetAsyncResetTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncResetTrigger GetAsyncResetTrigger(this Component component) + { + return component.gameObject.GetAsyncResetTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncResetTrigger : AsyncTriggerBase + { + TriggerEvent resetTriggerEvent; + + void Reset() + { + resetTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncResetHandler GetResetAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), false); + } + + public IAsyncResetHandler GetResetAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), cancellationToken, false); + } + + public UniTask ResetAsync() + { + return ((IAsyncResetHandler)new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), true)).ResetAsync(); + } + + public UniTask ResetAsync(CancellationToken cancellationToken) + { + return ((IAsyncResetHandler)new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), cancellationToken, true)).ResetAsync(); + } + } +#endregion + +#region Update + + public interface IAsyncUpdateHandler + { + UniTask UpdateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncUpdateHandler + { + UniTask IAsyncUpdateHandler.UpdateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this Component component) + { + return component.gameObject.GetAsyncUpdateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncUpdateTrigger : AsyncTriggerBase + { + TriggerEvent updateTriggerEvent; + + void Update() + { + updateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncUpdateHandler GetUpdateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), false); + } + + public IAsyncUpdateHandler GetUpdateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), cancellationToken, false); + } + + public UniTask UpdateAsync() + { + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), true)).UpdateAsync(); + } + + public UniTask UpdateAsync(CancellationToken cancellationToken) + { + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), cancellationToken, true)).UpdateAsync(); + } + } +#endregion + +#region BeginDrag + + public interface IAsyncOnBeginDragHandler + { + UniTask OnBeginDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBeginDragHandler + { + UniTask IAsyncOnBeginDragHandler.OnBeginDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this Component component) + { + return component.gameObject.GetAsyncBeginDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler + { + TriggerEvent onBeginDragTriggerEvent; + + void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) + { + onBeginDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), false); + } + + public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnBeginDragAsync() + { + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), true)).OnBeginDragAsync(); + } + + public UniTask OnBeginDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), cancellationToken, true)).OnBeginDragAsync(); + } + } +#endregion + +#region Cancel + + public interface IAsyncOnCancelHandler + { + UniTask OnCancelAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCancelHandler + { + UniTask IAsyncOnCancelHandler.OnCancelAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCancelTrigger GetAsyncCancelTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCancelTrigger GetAsyncCancelTrigger(this Component component) + { + return component.gameObject.GetAsyncCancelTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler + { + TriggerEvent onCancelTriggerEvent; + + void ICancelHandler.OnCancel(BaseEventData eventData) + { + onCancelTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnCancelHandler GetOnCancelAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), false); + } + + public IAsyncOnCancelHandler GetOnCancelAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), cancellationToken, false); + } + + public UniTask OnCancelAsync() + { + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), true)).OnCancelAsync(); + } + + public UniTask OnCancelAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), cancellationToken, true)).OnCancelAsync(); + } + } +#endregion + +#region Deselect + + public interface IAsyncOnDeselectHandler + { + UniTask OnDeselectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDeselectHandler + { + UniTask IAsyncOnDeselectHandler.OnDeselectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this Component component) + { + return component.gameObject.GetAsyncDeselectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler + { + TriggerEvent onDeselectTriggerEvent; + + void IDeselectHandler.OnDeselect(BaseEventData eventData) + { + onDeselectTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), false); + } + + public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), cancellationToken, false); + } + + public UniTask OnDeselectAsync() + { + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), true)).OnDeselectAsync(); + } + + public UniTask OnDeselectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), cancellationToken, true)).OnDeselectAsync(); + } + } +#endregion + +#region Drag + + public interface IAsyncOnDragHandler + { + UniTask OnDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDragHandler + { + UniTask IAsyncOnDragHandler.OnDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDragTrigger GetAsyncDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDragTrigger GetAsyncDragTrigger(this Component component) + { + return component.gameObject.GetAsyncDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDragTrigger : AsyncTriggerBase, IDragHandler + { + TriggerEvent onDragTriggerEvent; + + void IDragHandler.OnDrag(PointerEventData eventData) + { + onDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnDragHandler GetOnDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), false); + } + + public IAsyncOnDragHandler GetOnDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnDragAsync() + { + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), true)).OnDragAsync(); + } + + public UniTask OnDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), cancellationToken, true)).OnDragAsync(); + } + } +#endregion + +#region Drop + + public interface IAsyncOnDropHandler + { + UniTask OnDropAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDropHandler + { + UniTask IAsyncOnDropHandler.OnDropAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDropTrigger GetAsyncDropTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDropTrigger GetAsyncDropTrigger(this Component component) + { + return component.gameObject.GetAsyncDropTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDropTrigger : AsyncTriggerBase, IDropHandler + { + TriggerEvent onDropTriggerEvent; + + void IDropHandler.OnDrop(PointerEventData eventData) + { + onDropTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnDropHandler GetOnDropAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), false); + } + + public IAsyncOnDropHandler GetOnDropAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), cancellationToken, false); + } + + public UniTask OnDropAsync() + { + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), true)).OnDropAsync(); + } + + public UniTask OnDropAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), cancellationToken, true)).OnDropAsync(); + } + } +#endregion + +#region EndDrag + + public interface IAsyncOnEndDragHandler + { + UniTask OnEndDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnEndDragHandler + { + UniTask IAsyncOnEndDragHandler.OnEndDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this Component component) + { + return component.gameObject.GetAsyncEndDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler + { + TriggerEvent onEndDragTriggerEvent; + + void IEndDragHandler.OnEndDrag(PointerEventData eventData) + { + onEndDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), false); + } + + public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnEndDragAsync() + { + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), true)).OnEndDragAsync(); + } + + public UniTask OnEndDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), cancellationToken, true)).OnEndDragAsync(); + } + } +#endregion + +#region InitializePotentialDrag + + public interface IAsyncOnInitializePotentialDragHandler + { + UniTask OnInitializePotentialDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnInitializePotentialDragHandler + { + UniTask IAsyncOnInitializePotentialDragHandler.OnInitializePotentialDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this Component component) + { + return component.gameObject.GetAsyncInitializePotentialDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler + { + TriggerEvent onInitializePotentialDragTriggerEvent; + + void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData) + { + onInitializePotentialDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), false); + } + + public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnInitializePotentialDragAsync() + { + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), true)).OnInitializePotentialDragAsync(); + } + + public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), cancellationToken, true)).OnInitializePotentialDragAsync(); + } + } +#endregion + +#region Move + + public interface IAsyncOnMoveHandler + { + UniTask OnMoveAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMoveHandler + { + UniTask IAsyncOnMoveHandler.OnMoveAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMoveTrigger GetAsyncMoveTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMoveTrigger GetAsyncMoveTrigger(this Component component) + { + return component.gameObject.GetAsyncMoveTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler + { + TriggerEvent onMoveTriggerEvent; + + void IMoveHandler.OnMove(AxisEventData eventData) + { + onMoveTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnMoveHandler GetOnMoveAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), false); + } + + public IAsyncOnMoveHandler GetOnMoveAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), cancellationToken, false); + } + + public UniTask OnMoveAsync() + { + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), true)).OnMoveAsync(); + } + + public UniTask OnMoveAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), cancellationToken, true)).OnMoveAsync(); + } + } +#endregion + +#region PointerClick + + public interface IAsyncOnPointerClickHandler + { + UniTask OnPointerClickAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerClickHandler + { + UniTask IAsyncOnPointerClickHandler.OnPointerClickAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerClickTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler + { + TriggerEvent onPointerClickTriggerEvent; + + void IPointerClickHandler.OnPointerClick(PointerEventData eventData) + { + onPointerClickTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), false); + } + + public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerClickAsync() + { + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), true)).OnPointerClickAsync(); + } + + public UniTask OnPointerClickAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), cancellationToken, true)).OnPointerClickAsync(); + } + } +#endregion + +#region PointerDown + + public interface IAsyncOnPointerDownHandler + { + UniTask OnPointerDownAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerDownHandler + { + UniTask IAsyncOnPointerDownHandler.OnPointerDownAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerDownTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler + { + TriggerEvent onPointerDownTriggerEvent; + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + onPointerDownTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), false); + } + + public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerDownAsync() + { + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), true)).OnPointerDownAsync(); + } + + public UniTask OnPointerDownAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), cancellationToken, true)).OnPointerDownAsync(); + } + } +#endregion + +#region PointerEnter + + public interface IAsyncOnPointerEnterHandler + { + UniTask OnPointerEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerEnterHandler + { + UniTask IAsyncOnPointerEnterHandler.OnPointerEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler + { + TriggerEvent onPointerEnterTriggerEvent; + + void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) + { + onPointerEnterTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), false); + } + + public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerEnterAsync() + { + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), true)).OnPointerEnterAsync(); + } + + public UniTask OnPointerEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), cancellationToken, true)).OnPointerEnterAsync(); + } + } +#endregion + +#region PointerExit + + public interface IAsyncOnPointerExitHandler + { + UniTask OnPointerExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerExitHandler + { + UniTask IAsyncOnPointerExitHandler.OnPointerExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler + { + TriggerEvent onPointerExitTriggerEvent; + + void IPointerExitHandler.OnPointerExit(PointerEventData eventData) + { + onPointerExitTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), false); + } + + public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerExitAsync() + { + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), true)).OnPointerExitAsync(); + } + + public UniTask OnPointerExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), cancellationToken, true)).OnPointerExitAsync(); + } + } +#endregion + +#region PointerUp + + public interface IAsyncOnPointerUpHandler + { + UniTask OnPointerUpAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerUpHandler + { + UniTask IAsyncOnPointerUpHandler.OnPointerUpAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerUpTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler + { + TriggerEvent onPointerUpTriggerEvent; + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + onPointerUpTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), false); + } + + public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerUpAsync() + { + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), true)).OnPointerUpAsync(); + } + + public UniTask OnPointerUpAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), cancellationToken, true)).OnPointerUpAsync(); + } + } +#endregion + +#region Scroll + + public interface IAsyncOnScrollHandler + { + UniTask OnScrollAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnScrollHandler + { + UniTask IAsyncOnScrollHandler.OnScrollAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncScrollTrigger GetAsyncScrollTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncScrollTrigger GetAsyncScrollTrigger(this Component component) + { + return component.gameObject.GetAsyncScrollTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler + { + TriggerEvent onScrollTriggerEvent; + + void IScrollHandler.OnScroll(PointerEventData eventData) + { + onScrollTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnScrollHandler GetOnScrollAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), false); + } + + public IAsyncOnScrollHandler GetOnScrollAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), cancellationToken, false); + } + + public UniTask OnScrollAsync() + { + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), true)).OnScrollAsync(); + } + + public UniTask OnScrollAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), cancellationToken, true)).OnScrollAsync(); + } + } +#endregion + +#region Select + + public interface IAsyncOnSelectHandler + { + UniTask OnSelectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnSelectHandler + { + UniTask IAsyncOnSelectHandler.OnSelectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncSelectTrigger GetAsyncSelectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncSelectTrigger GetAsyncSelectTrigger(this Component component) + { + return component.gameObject.GetAsyncSelectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler + { + TriggerEvent onSelectTriggerEvent; + + void ISelectHandler.OnSelect(BaseEventData eventData) + { + onSelectTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnSelectHandler GetOnSelectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), false); + } + + public IAsyncOnSelectHandler GetOnSelectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), cancellationToken, false); + } + + public UniTask OnSelectAsync() + { + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), true)).OnSelectAsync(); + } + + public UniTask OnSelectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), cancellationToken, true)).OnSelectAsync(); + } + } +#endregion + +#region Submit + + public interface IAsyncOnSubmitHandler + { + UniTask OnSubmitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnSubmitHandler + { + UniTask IAsyncOnSubmitHandler.OnSubmitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this Component component) + { + return component.gameObject.GetAsyncSubmitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler + { + TriggerEvent onSubmitTriggerEvent; + + void ISubmitHandler.OnSubmit(BaseEventData eventData) + { + onSubmitTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), false); + } + + public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), cancellationToken, false); + } + + public UniTask OnSubmitAsync() + { + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), true)).OnSubmitAsync(); + } + + public UniTask OnSubmitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), cancellationToken, true)).OnSubmitAsync(); + } + } +#endregion + +#region UpdateSelected + + public interface IAsyncOnUpdateSelectedHandler + { + UniTask OnUpdateSelectedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnUpdateSelectedHandler + { + UniTask IAsyncOnUpdateSelectedHandler.OnUpdateSelectedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this Component component) + { + return component.gameObject.GetAsyncUpdateSelectedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler + { + TriggerEvent onUpdateSelectedTriggerEvent; + + void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData) + { + onUpdateSelectedTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), false); + } + + public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), cancellationToken, false); + } + + public UniTask OnUpdateSelectedAsync() + { + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), true)).OnUpdateSelectedAsync(); + } + + public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), cancellationToken, true)).OnUpdateSelectedAsync(); + } + } +#endregion + +} \ No newline at end of file diff --git a/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt new file mode 100644 index 0000000..b2b56d7 --- /dev/null +++ b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt @@ -0,0 +1,186 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +<# + var empty = new (string, string)[0]; + + var triggers = new (string triggerName, string methodName, string returnType, string handlerInterface, (string argType, string argName)[] arguments)[] + { + ("AnimatorIK", "OnAnimatorIK", "int", null, new []{ ("int", "layerIndex") }), + ("AnimatorMove", "OnAnimatorMove", "AsyncUnit", null, empty), + ("OnCanvasGroupChanged", "OnCanvasGroupChanged", "AsyncUnit", null, empty ), + ("CollisionEnter2D", "OnCollisionEnter2D", "Collision2D", null, new []{ ("Collision2D", "coll") }), + ("CollisionExit2D", "OnCollisionExit2D", "Collision2D", null, new []{ ("Collision2D", "coll") }), + ("CollisionStay2D", "OnCollisionStay2D", "Collision2D", null, new []{ ("Collision2D", "coll") }), + ("CollisionEnter", "OnCollisionEnter", "Collision", null, new []{ ("Collision", "coll") }), + ("CollisionExit", "OnCollisionExit", "Collision", null, new []{ ("Collision", "coll") }), + ("CollisionStay", "OnCollisionStay", "Collision", null, new []{ ("Collision", "coll") }), + ("Enable", "OnEnable", "AsyncUnit", null, empty), + ("Disable", "OnDisable", "AsyncUnit", null, empty), + ("JointBreak", "OnJointBreak", "float", null, new []{ ("float", "breakForce") }), + ("JointBreak2D", "OnJointBreak2D", "Joint2D", null, new []{ ("Joint2D", "brokenJoint") }), + ("Update", "Update", "AsyncUnit", null, empty), + ("FixedUpdate", "FixedUpdate", "AsyncUnit", null, empty), + ("LateUpdate", "LateUpdate", "AsyncUnit", null, empty), + ("MouseDown", "OnMouseDown", "AsyncUnit", null, empty), + ("MouseDrag", "OnMouseDrag", "AsyncUnit", null, empty), + ("MouseEnter", "OnMouseEnter", "AsyncUnit", null, empty), + ("MouseExit", "OnMouseExit", "AsyncUnit", null, empty), + ("MouseOver", "OnMouseOver", "AsyncUnit", null, empty), + ("MouseUp", "OnMouseUp", "AsyncUnit", null, empty), + ("MouseUpAsButton", "OnMouseUpAsButton", "AsyncUnit", null, empty), + ("ParticleCollision", "OnParticleCollision", "GameObject", null, new []{ ("GameObject", "other") }), + ("RectTransformDimensionsChange", "OnRectTransformDimensionsChange", "AsyncUnit", null, empty), + ("RectTransformRemoved", "OnRectTransformRemoved", "AsyncUnit", null, empty), + ("BeforeTransformParentChanged", "OnBeforeTransformParentChanged", "AsyncUnit", null, empty), + ("TransformParentChanged", "OnTransformParentChanged", "AsyncUnit", null, empty), + ("TransformChildrenChanged", "OnTransformChildrenChanged", "AsyncUnit", null, empty), + ("TriggerEnter2D", "OnTriggerEnter2D", "Collider2D", null, new []{ ("Collider2D", "other") }), + ("TriggerExit2D", "OnTriggerExit2D", "Collider2D", null, new []{ ("Collider2D", "other") }), + ("TriggerStay2D", "OnTriggerStay2D", "Collider2D", null, new []{ ("Collider2D", "other") }), + ("TriggerEnter", "OnTriggerEnter", "Collider", null, new []{ ("Collider", "other") }), + ("TriggerExit", "OnTriggerExit", "Collider", null, new []{ ("Collider", "other") }), + ("TriggerStay", "OnTriggerStay", "Collider", null, new []{ ("Collider", "other") }), + ("BecameInvisible", "OnBecameInvisible", "AsyncUnit", null, empty), + ("BecameVisible", "OnBecameVisible", "AsyncUnit", null, empty), + + // new in v2 + ("ApplicationFocus", "OnApplicationFocus", "bool", null, new []{("bool", "hasFocus") }), + ("ApplicationPause", "OnApplicationPause", "bool", null, new []{("bool", "pauseStatus") }), + ("ApplicationQuit", "OnApplicationQuit", "AsyncUnit", null, empty), + ("AudioFilterRead", "OnAudioFilterRead", "(float[] data, int channels)", null, new[]{("float[]", "data"), ("int", "channels")}), + ("ControllerColliderHit", "OnControllerColliderHit", "ControllerColliderHit", null, new[]{("ControllerColliderHit", "hit")}), + ("DrawGizmos", "OnDrawGizmos", "AsyncUnit", null, empty), + ("DrawGizmosSelected", "OnDrawGizmosSelected", "AsyncUnit", null, empty), + ("GUI", "OnGUI", "AsyncUnit", null, empty), + ("ParticleSystemStopped", "OnParticleSystemStopped", "AsyncUnit", null, empty), + ("ParticleTrigger", "OnParticleTrigger", "AsyncUnit", null, empty), + ("PostRender", "OnPostRender", "AsyncUnit", null, empty), + ("PreCull", "OnPreCull", "AsyncUnit", null, empty), + ("PreRender", "OnPreRender", "AsyncUnit", null, empty), + ("RenderImage", "OnRenderImage", "(RenderTexture source, RenderTexture destination)", null, new[]{("RenderTexture", "source"), ("RenderTexture", "destination")}), + ("RenderObject", "OnRenderObject", "AsyncUnit", null, empty), + ("ServerInitialized", "OnServerInitialized", "AsyncUnit", null, empty), + ("Validate", "OnValidate", "AsyncUnit", null, empty), + ("WillRenderObject", "OnWillRenderObject", "AsyncUnit", null, empty), + ("Reset", "Reset", "AsyncUnit", null, empty), + + // uGUI + ("BeginDrag", "OnBeginDrag", "PointerEventData", "IBeginDragHandler", new []{ ("PointerEventData", "eventData") }), + ("Cancel", "OnCancel", "BaseEventData", "ICancelHandler", new []{ ("BaseEventData", "eventData") }), + ("Deselect", "OnDeselect", "BaseEventData", "IDeselectHandler", new []{ ("BaseEventData", "eventData") }), + ("Drag", "OnDrag", "PointerEventData", "IDragHandler", new []{ ("PointerEventData", "eventData") }), + ("Drop", "OnDrop", "PointerEventData", "IDropHandler", new []{ ("PointerEventData", "eventData") }), + ("EndDrag", "OnEndDrag", "PointerEventData", "IEndDragHandler", new []{ ("PointerEventData", "eventData") }), + ("InitializePotentialDrag", "OnInitializePotentialDrag", "PointerEventData", "IInitializePotentialDragHandler", new []{ ("PointerEventData", "eventData") }), + ("Move", "OnMove", "AxisEventData", "IMoveHandler", new []{ ("AxisEventData", "eventData") }), + ("PointerClick", "OnPointerClick", "PointerEventData", "IPointerClickHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerDown", "OnPointerDown", "PointerEventData", "IPointerDownHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerEnter", "OnPointerEnter", "PointerEventData", "IPointerEnterHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerExit", "OnPointerExit", "PointerEventData", "IPointerExitHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerUp", "OnPointerUp", "PointerEventData", "IPointerUpHandler", new []{ ("PointerEventData", "eventData") }), + ("Scroll", "OnScroll", "PointerEventData", "IScrollHandler", new []{ ("PointerEventData", "eventData") }), + ("Select", "OnSelect", "BaseEventData", "ISelectHandler", new []{ ("BaseEventData", "eventData") }), + ("Submit", "OnSubmit", "BaseEventData", "ISubmitHandler", new []{ ("BaseEventData", "eventData") }), + ("UpdateSelected", "OnUpdateSelected", "BaseEventData", "IUpdateSelectedHandler", new []{ ("BaseEventData", "eventData") }), + + // 2019.3 + ("ParticleUpdateJobScheduled", "OnParticleUpdateJobScheduled", "UnityEngine.ParticleSystemJobs.ParticleSystemJobData", null, new[]{("UnityEngine.ParticleSystemJobs.ParticleSystemJobData", "particles")}), + + // Oneshot + // Awake, Start, Destroy + }; + + triggers = triggers.OrderBy(x => x.handlerInterface != null).ThenBy(x => x.handlerInterface != null ? x.handlerInterface : x.methodName).ToArray(); + + Func ToInterfaceName = x => $"IAsync{x}Handler"; + Func ToUniTaskName = x => x == "AsyncUnit" ? "UniTask" : $"UniTask<{x}>"; + Func ToCastUniTasSourceType = x => x == "AsyncUnit" ? "IUniTaskSource" : $"IUniTaskSource<{x}>"; + Func TriggerFieldName = x => char.ToLowerInvariant(x[0]) + x.Substring(1, x.Length - 1) + "TriggerEvent"; + Func OnInvokeSuffix = x => x == "AsyncUnit" ? ".AsUniTask()" : $""; + Func<(string argType, string argName)[], string> BuildMethodArgument = x => string.Join(", ", x.Select(y => y.argType + " " + y.argName)); + Func<(string argType, string argName)[], string> BuildResultParameter = x => x.Length == 0 ? "AsyncUnit.Default" : "(" + string.Join(", ", x.Select(y => y.argName)) + ")"; + + Func Is2019_3 = x => x == "ParticleUpdateJobScheduled"; +#> +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +using System.Threading; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace UniRx.Async.Triggers +{ +<# foreach(var t in triggers) { #> +#region <#= t.triggerName #> +<# if(Is2019_3(t.triggerName)) { #> +#if UNITY_2019_3_OR_NEWER +<# } #> + + public interface <#= ToInterfaceName(t.methodName) #> + { + <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async(); + } + + public partial class AsyncTriggerHandler : <#= ToInterfaceName(t.methodName) #> + { + <#= ToUniTaskName(t.returnType) #> <#= ToInterfaceName(t.methodName) #>.<#= t.methodName #>Async() + { + core.Reset(); + return new <#= ToUniTaskName(t.returnType) #>((<#= ToCastUniTasSourceType(t.returnType) #>)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static Async<#= t.triggerName #>Trigger GetAsync<#= t.triggerName #>Trigger(this GameObject gameObject) + { + return GetOrAddComponentTrigger>(gameObject); + } + + public static Async<#= t.triggerName #>Trigger GetAsync<#= t.triggerName #>Trigger(this Component component) + { + return component.gameObject.GetAsync<#= t.triggerName #>Trigger(); + } + } + + [DisallowMultipleComponent] + public sealed class Async<#= t.triggerName #>Trigger : AsyncTriggerBase<#= (t.handlerInterface == null) ? "" : $", {t.handlerInterface}" #> + { + TriggerEvent<<#= t.returnType #>> <#= TriggerFieldName(t.methodName) #>; + + void <#= (t.handlerInterface == null) ? "" : $"{t.handlerInterface}." #><#= t.methodName #>(<#= BuildMethodArgument(t.arguments) #>) + { + <#= TriggerFieldName(t.methodName) #>?.TrySetResult(<#= BuildResultParameter(t.arguments) #>); + } + + public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler() + { + return new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), false); + } + + public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), cancellationToken, false); + } + + public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async() + { + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), true)).<#= t.methodName #>Async(); + } + + public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async(CancellationToken cancellationToken) + { + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), cancellationToken, true)).<#= t.methodName #>Async(); + } + } +<# if(Is2019_3(t.triggerName)) { #> +#endif +<# } #> +#endregion + +<# } #> +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.Delay.cs b/Assets/UniRx.Async/UniTask.Delay.cs index df3f4ef..05048d4 100644 --- a/Assets/UniRx.Async/UniTask.Delay.cs +++ b/Assets/UniRx.Async/UniTask.Delay.cs @@ -79,7 +79,7 @@ namespace UniRx.Async result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -91,7 +91,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -168,7 +168,7 @@ namespace UniRx.Async result.delayFrameCount = delayFrameCount; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -180,7 +180,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -266,7 +266,7 @@ namespace UniRx.Async result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -278,7 +278,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -364,7 +364,7 @@ namespace UniRx.Async result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -376,7 +376,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/UniTask.WaitUntil.cs b/Assets/UniRx.Async/UniTask.WaitUntil.cs index 554dc59..877fe2f 100644 --- a/Assets/UniRx.Async/UniTask.WaitUntil.cs +++ b/Assets/UniRx.Async/UniTask.WaitUntil.cs @@ -56,7 +56,7 @@ namespace UniRx.Async result.predicate = predicate; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -68,7 +68,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -158,7 +158,7 @@ namespace UniRx.Async result.predicate = predicate; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -170,7 +170,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -267,7 +267,7 @@ namespace UniRx.Async result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -279,7 +279,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } finally @@ -387,7 +387,7 @@ namespace UniRx.Async result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -399,7 +399,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs index 8652192..95c6a4c 100644 --- a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs +++ b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs @@ -29,7 +29,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -107,7 +107,7 @@ namespace UniRx.Async public (T1, T2) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -158,7 +158,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -271,7 +271,7 @@ namespace UniRx.Async public (T1, T2, T3) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -323,7 +323,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -471,7 +471,7 @@ namespace UniRx.Async public (T1, T2, T3, T4) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -524,7 +524,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -707,7 +707,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -761,7 +761,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -979,7 +979,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1034,7 +1034,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1287,7 +1287,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1343,7 +1343,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1631,7 +1631,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1688,7 +1688,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2011,7 +2011,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2069,7 +2069,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2427,7 +2427,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2486,7 +2486,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2879,7 +2879,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2939,7 +2939,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3367,7 +3367,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3428,7 +3428,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3891,7 +3891,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3953,7 +3953,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -4451,7 +4451,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -4514,7 +4514,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -5047,7 +5047,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTask.WhenAll.cs b/Assets/UniRx.Async/UniTask.WhenAll.cs index e9a83d7..ed6f2dc 100644 --- a/Assets/UniRx.Async/UniTask.WhenAll.cs +++ b/Assets/UniRx.Async/UniTask.WhenAll.cs @@ -17,7 +17,7 @@ namespace UniRx.Async public static UniTask WhenAll(IEnumerable> tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { var promise = new WhenAllPromise(span.Array, span.Length); // consumed array in constructor. return new UniTask(promise, 0); @@ -31,7 +31,7 @@ namespace UniRx.Async public static UniTask WhenAll(IEnumerable tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { var promise = new WhenAllPromise(span.Array, span.Length); // consumed array in constructor. return new UniTask(promise, 0); @@ -46,7 +46,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completeCount = 0; this.result = new T[tasksLength]; @@ -101,7 +101,7 @@ namespace UniRx.Async public T[] GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -140,7 +140,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.tasksLength = tasksLength; this.completeCount = 0; @@ -195,7 +195,7 @@ namespace UniRx.Async public void GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs index 14a29b6..9178472 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs @@ -21,7 +21,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -103,7 +103,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -146,7 +146,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -265,7 +265,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -308,7 +308,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -464,7 +464,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -507,7 +507,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -700,7 +700,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -743,7 +743,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -973,7 +973,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1016,7 +1016,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1283,7 +1283,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1326,7 +1326,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1630,7 +1630,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1673,7 +1673,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2014,7 +2014,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2057,7 +2057,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2435,7 +2435,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2478,7 +2478,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2893,7 +2893,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2936,7 +2936,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3388,7 +3388,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3431,7 +3431,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3920,7 +3920,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3963,7 +3963,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -4489,7 +4489,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -4532,7 +4532,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -5095,7 +5095,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTask.WhenAny.cs b/Assets/UniRx.Async/UniTask.WhenAny.cs index 3bfe25c..c025f1b 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.cs +++ b/Assets/UniRx.Async/UniTask.WhenAny.cs @@ -22,7 +22,7 @@ namespace UniRx.Async public static UniTask<(int winArgumentIndex, T result)> WhenAny(IEnumerable> tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { return new UniTask<(int, T)>(new WhenAnyPromise(span.Array, span.Length), 0); } @@ -37,7 +37,7 @@ namespace UniRx.Async /// Return value is winArgumentIndex public static UniTask WhenAny(IEnumerable tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { return new UniTask(new WhenAnyPromise(span.Array, span.Length), 0); } @@ -51,7 +51,7 @@ namespace UniRx.Async public WhenAnyLRPromise(UniTask leftTask, UniTask rightTask) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); { UniTask.Awaiter awaiter; @@ -149,7 +149,7 @@ namespace UniRx.Async public (bool, T) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -189,7 +189,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); for (int i = 0; i < tasksLength; i++) { @@ -242,7 +242,7 @@ namespace UniRx.Async public (int, T) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -281,7 +281,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); for (int i = 0; i < tasksLength; i++) { @@ -333,7 +333,7 @@ namespace UniRx.Async public int GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index ccc4f4a..de72a47 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -272,7 +272,7 @@ namespace UniRx.Async public UniTaskCompletionSource() { - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); } [Conditional("UNITY_EDITOR")] @@ -281,7 +281,7 @@ namespace UniRx.Async if (!handled) { handled = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); } } @@ -297,7 +297,7 @@ namespace UniRx.Async { // Reset, re-active tracker handled = false; - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); core.Reset(); } @@ -357,7 +357,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource Create() { var value = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); - TaskTracker2.TrackActiveTask(value, 2); + TaskTracker.TrackActiveTask(value, 2); return value; } @@ -412,7 +412,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -459,7 +459,7 @@ namespace UniRx.Async public UniTaskCompletionSource() { - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); } [Conditional("UNITY_EDITOR")] @@ -468,7 +468,7 @@ namespace UniRx.Async if (!handled) { handled = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); } } @@ -484,7 +484,7 @@ namespace UniRx.Async { handled = false; core.Reset(); - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); } public bool TrySetResult(T result) @@ -548,7 +548,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource Create() { var result = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); - TaskTracker2.TrackActiveTask(result, 2); + TaskTracker.TrackActiveTask(result, 2); return result; } @@ -603,7 +603,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs b/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs index 2e958d6..4c76539 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs @@ -3,136 +3,117 @@ using System; using System.Threading; -using UniRx.Async.Internal; using Unity.Jobs; namespace UniRx.Async { public static partial class UnityAsyncExtensions { - public static IAwaiter GetAwaiter(this JobHandle jobHandle) + public static UniTask.Awaiter GetAwaiter(this JobHandle jobHandle) { - var awaiter = new JobHandleAwaiter(jobHandle, CancellationToken.None); - if (!awaiter.IsCompleted) + var handler = JobHandlePromise.Create(jobHandle, CancellationToken.None, out var token); + if (handler.GetStatus(token).IsCompleted() && handler is JobHandlePromise loopItem) { - PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, awaiter); + PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, loopItem); } - return awaiter; + + return new UniTask(handler, token).GetAwaiter(); } public static UniTask ToUniTask(this JobHandle jobHandle, CancellationToken cancellation = default(CancellationToken)) { - var awaiter = new JobHandleAwaiter(jobHandle, cancellation); - if (!awaiter.IsCompleted) + var handler = JobHandlePromise.Create(jobHandle, cancellation, out var token); + if (handler.GetStatus(token).IsCompleted() && handler is JobHandlePromise loopItem) { - PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, awaiter); + PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, loopItem); } - return new UniTask(awaiter); + + return new UniTask(handler, token); } public static UniTask ConfigureAwait(this JobHandle jobHandle, PlayerLoopTiming waitTiming, CancellationToken cancellation = default(CancellationToken)) { - var awaiter = new JobHandleAwaiter(jobHandle, cancellation); - if (!awaiter.IsCompleted) + var handler = JobHandlePromise.Create(jobHandle, cancellation, out var token); + if (handler.GetStatus(token).IsCompleted() && handler is JobHandlePromise loopItem) { - PlayerLoopHelper.AddAction(waitTiming, awaiter); + PlayerLoopHelper.AddAction(waitTiming, loopItem); } - return new UniTask(awaiter); + + return new UniTask(handler, token); } - class JobHandleAwaiter : IAwaiter, IPlayerLoopItem + sealed class JobHandlePromise : IUniTaskSource, IPlayerLoopItem { JobHandle jobHandle; CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - public JobHandleAwaiter(JobHandle jobHandle, CancellationToken cancellationToken, int skipFrame = 2) + UniTaskCompletionSourceCore core; + + public static IUniTaskSource Create(JobHandle jobHandle, CancellationToken cancellationToken, out short token) { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : jobHandle.IsCompleted ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } - if (this.status.IsCompleted()) return; + // not use pool. + var result = new JobHandlePromise(); - this.jobHandle = jobHandle; - this.cancellationToken = cancellationToken; - this.status = UniTaskStatus.Pending; - this.continuation = null; + result.jobHandle = jobHandle; + result.cancellationToken = cancellationToken; - TaskTracker.TrackActiveTask(this, skipFrame); + TaskTracker.TrackActiveTask(result, 3); + + token = result.core.Version; + return result; } - public bool IsCompleted => status.IsCompleted(); - - public UniTaskStatus Status => status; - - public void GetResult() + public void GetResult(short token) { - if (status == UniTaskStatus.Succeeded) - { - return; - } - else if (status == UniTaskStatus.Canceled) - { - Error.ThrowOperationCanceledException(); - } + TaskTracker.RemoveTracking(this); + core.GetResult(token); + } - Error.ThrowNotYetCompleted(); + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - // Call jobHandle.Complete after finished. - PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, new JobHandleAwaiter(jobHandle, CancellationToken.None, 1)); - InvokeContinuation(UniTaskStatus.Canceled); + core.TrySetCanceled(cancellationToken); return false; } if (jobHandle.IsCompleted) { jobHandle.Complete(); - InvokeContinuation(UniTaskStatus.Succeeded); + core.TrySetResult(AsyncUnit.Default); return false; } return true; } - - void InvokeContinuation(UniTaskStatus status) - { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.jobHandle = default(JobHandle); - - if (cont != null) cont.Invoke(); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } } } } diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index 385581f..d8d00be 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -104,7 +104,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -116,7 +116,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } @@ -277,7 +277,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -289,7 +289,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } @@ -454,7 +454,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -466,7 +466,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } @@ -631,7 +631,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -643,7 +643,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } @@ -809,7 +809,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -821,7 +821,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.tt b/Assets/UniRx.Async/UnityAsyncExtensions.tt index e4d6e27..1b2b8ac 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.tt +++ b/Assets/UniRx.Async/UnityAsyncExtensions.tt @@ -137,7 +137,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -149,7 +149,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); <# if (!IsVoid(t)) { #> return core.GetResult(token); diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs index 09658f7..24a119c 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs @@ -211,7 +211,7 @@ namespace UniRx.Async registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); } - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); } public UniTask OnInvokeAsync() @@ -238,7 +238,7 @@ namespace UniRx.Async if (!isDisposed) { isDisposed = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); registration.Dispose(); if (unityEvent != null) { @@ -317,7 +317,7 @@ namespace UniRx.Async registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); } - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); } public UniTask OnInvokeAsync() @@ -344,7 +344,7 @@ namespace UniRx.Async if (!isDisposed) { isDisposed = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); registration.Dispose(); if (unityEvent != null) { From 75f0bd26e7bbe5dc58ac7a1e0a7d9229a997d1cf Mon Sep 17 00:00:00 2001 From: neuecc Date: Tue, 5 May 2020 04:17:08 +0900 Subject: [PATCH 015/173] ToAsyncLazy --- Assets/UniRx.Async/AsyncLazy.cs | 56 +++++++++++++++++++++++++ Assets/UniRx.Async/UniTask.Factory.cs | 5 +++ Assets/UniRx.Async/UniTaskExtensions.cs | 10 +++++ 3 files changed, 71 insertions(+) diff --git a/Assets/UniRx.Async/AsyncLazy.cs b/Assets/UniRx.Async/AsyncLazy.cs index 1969f61..9a11b2f 100644 --- a/Assets/UniRx.Async/AsyncLazy.cs +++ b/Assets/UniRx.Async/AsyncLazy.cs @@ -6,6 +6,62 @@ using System.Threading; namespace UniRx.Async { + public class AsyncLazy + { + Func valueFactory; + UniTask target; + object syncLock; + bool initialized; + + public AsyncLazy(Func valueFactory) + { + this.valueFactory = valueFactory; + this.target = default; + this.syncLock = new object(); + this.initialized = false; + } + + internal AsyncLazy(UniTask value) + { + this.valueFactory = null; + this.target = value; + this.syncLock = null; + this.initialized = true; + } + + public UniTask Task => EnsureInitialized(); + + public UniTask.Awaiter GetAwaiter() => EnsureInitialized().GetAwaiter(); + + UniTask EnsureInitialized() + { + if (Volatile.Read(ref initialized)) + { + return target; + } + + return EnsureInitializedCore(); + } + + UniTask EnsureInitializedCore() + { + lock (syncLock) + { + if (!Volatile.Read(ref initialized)) + { + var f = Interlocked.Exchange(ref valueFactory, null); + if (f != null) + { + target = f().Preserve(); // with preserve(allow multiple await). + Volatile.Write(ref initialized, true); + } + } + } + + return target; + } + } + public class AsyncLazy { Func> valueFactory; diff --git a/Assets/UniRx.Async/UniTask.Factory.cs b/Assets/UniRx.Async/UniTask.Factory.cs index c63d8c3..d0c906a 100644 --- a/Assets/UniRx.Async/UniTask.Factory.cs +++ b/Assets/UniRx.Async/UniTask.Factory.cs @@ -93,6 +93,11 @@ namespace UniRx.Async return factory(); } + public static AsyncLazy Lazy(Func factory) + { + return new AsyncLazy(factory); + } + public static AsyncLazy Lazy(Func> factory) { return new AsyncLazy(factory); diff --git a/Assets/UniRx.Async/UniTaskExtensions.cs b/Assets/UniRx.Async/UniTaskExtensions.cs index 9642af1..795abc1 100644 --- a/Assets/UniRx.Async/UniTaskExtensions.cs +++ b/Assets/UniRx.Async/UniTaskExtensions.cs @@ -180,6 +180,16 @@ namespace UniRx.Async } } + public static AsyncLazy ToAsyncLazy(this UniTask task) + { + return new AsyncLazy(task.Preserve()); // require Preserve + } + + public static AsyncLazy ToAsyncLazy(this UniTask task) + { + return new AsyncLazy(task.Preserve()); // require Preserve + } + public static IEnumerator ToCoroutine(this UniTask task, Action resultHandler = null, Action exceptionHandler = null) { return new ToCoroutineEnumerator(task, resultHandler, exceptionHandler); From 6e80295ec7437c667f3da6641305d3dc0f01c1a0 Mon Sep 17 00:00:00 2001 From: neuecc Date: Tue, 5 May 2020 05:22:49 +0900 Subject: [PATCH 016/173] add PlayerLoopTiming.Last*** --- .../Editor/UnitTestBuilder.MenuItems.cs | 32 +- .../Editor/UnitTestBuilder.cs | 41 +- .../RuntimeUnitTestToolkit/UnitTestRunner.cs | 374 ++++++++++++++---- Assets/RuntimeUnitTestToolkit/package.json | 4 +- Assets/Scenes/SandboxMain.cs | 86 +++- Assets/UniRx.Async/PlayerLoopHelper.cs | 144 +++++-- .../MonoBehaviourMessagesTriggers.cs.meta | 11 + .../MonoBehaviourMessagesTriggers.tt.meta | 7 + .../UniRx.Async/UnityAsyncExtensions.cs.meta | 11 + .../UniRx.Async/UnityAsyncExtensions.tt.meta | 7 + 10 files changed, 598 insertions(+), 119 deletions(-) create mode 100644 Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs.meta create mode 100644 Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt.meta create mode 100644 Assets/UniRx.Async/UnityAsyncExtensions.cs.meta create mode 100644 Assets/UniRx.Async/UnityAsyncExtensions.tt.meta diff --git a/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.MenuItems.cs b/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.MenuItems.cs index cef082e..94508b5 100644 --- a/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.MenuItems.cs +++ b/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.MenuItems.cs @@ -169,21 +169,25 @@ Switch, SaveSettings(settings); } - //[MenuItem("Test/Settings/BuildTarget/StandaloneLinux", validate = true, priority = 3)] - //static bool ValidateBuildTargetStandaloneLinux() - //{ - // Menu.SetChecked("Test/Settings/BuildTarget/StandaloneLinux", LoadOrGetDefaultSettings().BuildTarget == BuildTarget.StandaloneLinux); - // return true; - //} +#if !UNITY_2019_2_OR_NEWER - //[MenuItem("Test/Settings/BuildTarget/StandaloneLinux", validate = false, priority = 3)] - //static void BuildTargetStandaloneLinux() - //{ - // var settings = LoadOrGetDefaultSettings(); - // settings.UseCurrentBuildTarget = false; - // settings.BuildTarget = BuildTarget.StandaloneLinux; - // SaveSettings(settings); - //} + [MenuItem("Test/Settings/BuildTarget/StandaloneLinux", validate = true, priority = 3)] + static bool ValidateBuildTargetStandaloneLinux() + { + Menu.SetChecked("Test/Settings/BuildTarget/StandaloneLinux", LoadOrGetDefaultSettings().BuildTarget == BuildTarget.StandaloneLinux); + return true; + } + + [MenuItem("Test/Settings/BuildTarget/StandaloneLinux", validate = false, priority = 3)] + static void BuildTargetStandaloneLinux() + { + var settings = LoadOrGetDefaultSettings(); + settings.UseCurrentBuildTarget = false; + settings.BuildTarget = BuildTarget.StandaloneLinux; + SaveSettings(settings); + } + +#endif [MenuItem("Test/Settings/BuildTarget/StandaloneLinux64", validate = true, priority = 4)] static bool ValidateBuildTargetStandaloneLinux64() diff --git a/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.cs b/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.cs index 8ca1068..ca45d0b 100644 --- a/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.cs +++ b/Assets/RuntimeUnitTestToolkit/Editor/UnitTestBuilder.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR using RuntimeUnitTestToolkit; using RuntimeUnitTestToolkit.Editor; @@ -118,7 +118,7 @@ public static partial class UnitTestBuilder if (buildPath == null) { - buildPath = $"bin/UnitTest/{settings.BuildTarget}_{settings.ScriptBackend}/test" + (IsWindows(settings.BuildTarget) ? ".exe" : ""); + buildPath = $"bin/UnitTest/{settings.BuildTarget}_{settings.ScriptBackend}/test" + GetExtensionForBuildTarget(settings.BuildTarget); } var originalScene = SceneManager.GetActiveScene().path; @@ -136,6 +136,15 @@ public static partial class UnitTestBuilder } } + + [MenuItem("Test/LoadUnitTestScene")] + public static void LoadUnitTestScene() + { + var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); + BuildUnitTestRunnerScene(); + EditorSceneManager.MarkSceneDirty(scene); + } + static RuntimeUnitTestSettings LoadOrGetDefaultSettings() { var key = SettingsKeyBase + Application.productName; @@ -448,20 +457,42 @@ public static partial class UnitTestBuilder } } + static string GetExtensionForBuildTarget(BuildTarget buildTarget) + { + switch (buildTarget) + { + case BuildTarget.StandaloneWindows: + case BuildTarget.StandaloneWindows64: + case BuildTarget.WSAPlayer: + return ".exe"; + case BuildTarget.StandaloneOSX: + return ".app"; + case BuildTarget.Android: + return ".apk"; + default: + return ""; + } + } + static BuildTargetGroup ToBuildTargetGroup(BuildTarget buildTarget) { #pragma warning disable CS0618 switch (buildTarget) { +#if UNITY_2017_3_OR_NEWER case BuildTarget.StandaloneOSX: - case (BuildTarget)3: +#else case BuildTarget.StandaloneOSXIntel: case BuildTarget.StandaloneOSXIntel64: + case BuildTarget.StandaloneOSXUniversal: +#endif // UNITY_2017_3_OR_NEWER case BuildTarget.StandaloneWindows: case BuildTarget.StandaloneWindows64: - case BuildTarget.StandaloneLinux: case BuildTarget.StandaloneLinux64: +#if !UNITY_2019_2_OR_NEWER + case BuildTarget.StandaloneLinux: case BuildTarget.StandaloneLinuxUniversal: +#endif // !UNITY_2019_2_OR_NEWER return BuildTargetGroup.Standalone; case (BuildTarget)6: case (BuildTarget)7: @@ -512,4 +543,4 @@ public static partial class UnitTestBuilder } } -#endif \ No newline at end of file +#endif diff --git a/Assets/RuntimeUnitTestToolkit/UnitTestRunner.cs b/Assets/RuntimeUnitTestToolkit/UnitTestRunner.cs index ff7041c..8637876 100644 --- a/Assets/RuntimeUnitTestToolkit/UnitTestRunner.cs +++ b/Assets/RuntimeUnitTestToolkit/UnitTestRunner.cs @@ -14,7 +14,7 @@ namespace RuntimeUnitTestToolkit public class UnitTestRunner : MonoBehaviour { // object is IEnumerator or Func - Dictionary>> tests = new Dictionary>>(); + Dictionary> tests = new Dictionary>(); List additionalActionsOnFirst = new List(); @@ -30,6 +30,7 @@ namespace RuntimeUnitTestToolkit readonly Color normalColor = new Color(1f, 1f, 1f, 1f); // white bool allTestGreen = true; + bool logClear = false; void Start() { @@ -37,7 +38,15 @@ namespace RuntimeUnitTestToolkit { UnityEngine.Application.logMessageReceived += (a, b, c) => { - logText.text += "[" + c + "]" + a + "\n"; + if (a.Contains("Mesh can not have more than 65000 vertices")) + { + logClear = true; + } + else + { + AppendToGraphicText("[" + c + "]" + a + "\n"); + WriteToConsole("[" + c + "]" + a); + } }; // register all test types @@ -133,13 +142,34 @@ namespace RuntimeUnitTestToolkit { foreach (var method in item.GetMethods()) { - var t1 = method.GetCustomAttribute(true); + TestAttribute t1 = null; + try + { + t1 = method.GetCustomAttribute(true); + } + catch (Exception ex) + { + Debug.Log("TestAttribute Load Fail, Assembly:" + assembly.FullName); + Debug.LogException(ex); + goto NEXT_ASSEMBLY; + } if (t1 != null) { yield return item; break; } - var t2 = method.GetCustomAttribute(true); + + UnityTestAttribute t2 = null; + try + { + t2 = method.GetCustomAttribute(true); + } + catch (Exception ex) + { + Debug.Log("UnityTestAttribute Load Fail, Assembly:" + assembly.FullName); + Debug.LogException(ex); + goto NEXT_ASSEMBLY; + } if (t2 != null) { yield return item; @@ -147,31 +177,34 @@ namespace RuntimeUnitTestToolkit } } } + +NEXT_ASSEMBLY: + continue; } } - public void AddTest(string group, string title, Action test) + public void AddTest(string group, string title, Action test, List setups, List teardowns) { - List> list; + List list; if (!tests.TryGetValue(group, out list)) { - list = new List>(); + list = new List(); tests[group] = list; } - list.Add(new KeyValuePair(title, test)); + list.Add(new TestKeyValuePair(title, test, setups, teardowns)); } - public void AddAsyncTest(string group, string title, Func asyncTestCoroutine) + public void AddAsyncTest(string group, string title, Func asyncTestCoroutine, List setups, List teardowns) { - List> list; + List list; if (!tests.TryGetValue(group, out list)) { - list = new List>(); + list = new List(); tests[group] = list; } - list.Add(new KeyValuePair(title, asyncTestCoroutine)); + list.Add(new TestKeyValuePair(title, asyncTestCoroutine, setups, teardowns)); } public void AddCutomAction(string name, UnityAction action) @@ -193,6 +226,29 @@ namespace RuntimeUnitTestToolkit var test = Activator.CreateInstance(testType); var methods = testType.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); + List setups = new List(); + List teardowns = new List(); + foreach (var item in methods) + { + try + { + var setup = item.GetCustomAttribute(true); + if (setup != null) + { + setups.Add((Action)Delegate.CreateDelegate(typeof(Action), test, item)); + } + var teardown = item.GetCustomAttribute(true); + if (teardown != null) + { + teardowns.Add((Action)Delegate.CreateDelegate(typeof(Action), test, item)); + } + } + catch (Exception e) + { + UnityEngine.Debug.LogError(testType.Name + "." + item.Name + " failed to register setup/teardown method, exception: " + e.ToString()); + } + } + foreach (var item in methods) { try @@ -203,11 +259,34 @@ namespace RuntimeUnitTestToolkit if (item.GetParameters().Length == 0 && item.ReturnType == typeof(IEnumerator)) { var factory = (Func)Delegate.CreateDelegate(typeof(Func), test, item); - AddAsyncTest(factory.Target.GetType().Name, factory.Method.Name, factory); + AddAsyncTest(factory.Target.GetType().Name, factory.Method.Name, factory, setups, teardowns); } else { - UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter or return type is invalid)."); + var testData = GetTestData(item); + if (testData.Count != 0) + { + foreach (var item2 in testData) + { + Func factory; + if (item.IsGenericMethod) + { + var method2 = InferGenericType(item, item2); + factory = () => (IEnumerator)method2.Invoke(test, item2); + } + else + { + factory = () => (IEnumerator)item.Invoke(test, item2); + } + var name = item.Name + "(" + string.Join(", ", item2.Select(x => x?.ToString() ?? "null")) + ")"; + name = name.Replace(Char.MinValue, ' ').Replace(Char.MaxValue, ' ').Replace("<", "[").Replace(">", "]"); + AddAsyncTest(test.GetType().Name, name, factory, setups, teardowns); + } + } + else + { + UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter without TestCase or return type is invalid)."); + } } } @@ -217,11 +296,34 @@ namespace RuntimeUnitTestToolkit if (item.GetParameters().Length == 0 && item.ReturnType == typeof(void)) { var invoke = (Action)Delegate.CreateDelegate(typeof(Action), test, item); - AddTest(invoke.Target.GetType().Name, invoke.Method.Name, invoke); + AddTest(invoke.Target.GetType().Name, invoke.Method.Name, invoke, setups, teardowns); } else { - UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter or return type is invalid)."); + var testData = GetTestData(item); + if (testData.Count != 0) + { + foreach (var item2 in testData) + { + Action invoke = null; + if (item.IsGenericMethod) + { + var method2 = InferGenericType(item, item2); + invoke = () => method2.Invoke(test, item2); + } + else + { + invoke = () => item.Invoke(test, item2); + } + var name = item.Name + "(" + string.Join(", ", item2.Select(x => x?.ToString() ?? "null")) + ")"; + name = name.Replace(Char.MinValue, ' ').Replace(Char.MaxValue, ' ').Replace("<", "[").Replace(">", "]"); + AddTest(test.GetType().Name, name, invoke, setups, teardowns); + } + } + else + { + UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter without TestCase or return type is invalid)."); + } } } } @@ -237,6 +339,88 @@ namespace RuntimeUnitTestToolkit } } + List GetTestData(MethodInfo methodInfo) + { + List testCases = new List(); + + var inlineData = methodInfo.GetCustomAttributes(true); + foreach (var item in inlineData) + { + testCases.Add(item.Arguments); + } + + var sourceData = methodInfo.GetCustomAttributes(true); + foreach (var item in sourceData) + { + var enumerator = GetTestCaseSource(methodInfo, item.SourceType, item.SourceName, item.MethodParams); + foreach (var item2 in enumerator) + { + var item3 = item2 as IEnumerable; // object[][] + if (item3 != null) + { + var l = new List(); + foreach (var item4 in item3) + { + l.Add(item4); + } + testCases.Add(l.ToArray()); + } + } + } + + return testCases; + } + + IEnumerable GetTestCaseSource(MethodInfo method, Type sourceType, string sourceName, object[] methodParams) + { + Type type = sourceType ?? method.DeclaringType; + + MemberInfo[] member = type.GetMember(sourceName, BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); + if (member.Length == 1) + { + MemberInfo memberInfo = member[0]; + FieldInfo fieldInfo = memberInfo as FieldInfo; + if ((object)fieldInfo != null) + { + return (!fieldInfo.IsStatic) ? ReturnErrorAsParameter("The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method.") : ((methodParams == null) ? ((IEnumerable)fieldInfo.GetValue(null)) : ReturnErrorAsParameter("You have specified a data source field but also given a set of parameters. Fields cannot take parameters, please revise the 3rd parameter passed to the TestCaseSourceAttribute and either remove it or specify a method.")); + } + PropertyInfo propertyInfo = memberInfo as PropertyInfo; + if ((object)propertyInfo != null) + { + return (!propertyInfo.GetGetMethod(nonPublic: true).IsStatic) ? ReturnErrorAsParameter("The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method.") : ((methodParams == null) ? ((IEnumerable)propertyInfo.GetValue(null, null)) : ReturnErrorAsParameter("You have specified a data source property but also given a set of parameters. Properties cannot take parameters, please revise the 3rd parameter passed to the TestCaseSource attribute and either remove it or specify a method.")); + } + MethodInfo methodInfo = memberInfo as MethodInfo; + if ((object)methodInfo != null) + { + return (!methodInfo.IsStatic) ? ReturnErrorAsParameter("The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method.") : ((methodParams == null || methodInfo.GetParameters().Length == methodParams.Length) ? ((IEnumerable)methodInfo.Invoke(null, methodParams)) : ReturnErrorAsParameter("You have given the wrong number of arguments to the method in the TestCaseSourceAttribute, please check the number of parameters passed in the object is correct in the 3rd parameter for the TestCaseSourceAttribute and this matches the number of parameters in the target method and try again.")); + } + } + return null; + } + + MethodInfo InferGenericType(MethodInfo methodInfo, object[] parameters) + { + var set = new HashSet(); + List genericParameters = new List(); + foreach (var item in methodInfo.GetParameters() + .Select((x, i) => new { x.ParameterType, i }) + .Where(x => x.ParameterType.IsGenericParameter) + .OrderBy(x => x.ParameterType.GenericParameterPosition)) + { + if (set.Add(item.ParameterType)) // DistinctBy + { + genericParameters.Add(parameters[item.i].GetType()); + } + } + + return methodInfo.MakeGenericMethod(genericParameters.ToArray()); + } + + IEnumerable ReturnErrorAsParameter(string name) + { + throw new Exception(name); + } + System.Collections.IEnumerator ScrollLogToEndNextFrame() { yield return null; @@ -244,7 +428,7 @@ namespace RuntimeUnitTestToolkit logScrollBar.value = 0; } - IEnumerator RunTestInCoroutine(KeyValuePair>> actionList) + IEnumerator RunTestInCoroutine(KeyValuePair> actionList) { Button self = null; foreach (var btn in list.GetComponentsInChildren