UniTask.WhenAny.Generated.cs 200 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060
  1. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  2. using System;
  3. using System.Runtime.CompilerServices;
  4. using System.Runtime.ExceptionServices;
  5. using System.Threading;
  6. using Cysharp.Threading.Tasks.Internal;
  7. namespace Cysharp.Threading.Tasks
  8. {
  9. public partial struct UniTask
  10. {
  11. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2)> WhenAny<T1, T2>(UniTask<T1> task1, UniTask<T2> task2)
  12. {
  13. return new UniTask<(int winArgumentIndex, T1 result1, T2 result2)>(new WhenAnyPromise<T1, T2>(task1, task2), 0);
  14. }
  15. sealed class WhenAnyPromise<T1, T2> : IUniTaskSource<(int, T1 result1, T2 result2)>
  16. {
  17. int completedCount;
  18. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2)> core;
  19. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2)
  20. {
  21. TaskTracker.TrackActiveTask(this, 3);
  22. this.completedCount = 0;
  23. {
  24. var awaiter = task1.GetAwaiter();
  25. if (awaiter.IsCompleted)
  26. {
  27. TryInvokeContinuationT1(this, awaiter);
  28. }
  29. else
  30. {
  31. awaiter.SourceOnCompleted(state =>
  32. {
  33. using (var t = (StateTuple<WhenAnyPromise<T1, T2>, UniTask<T1>.Awaiter>)state)
  34. {
  35. TryInvokeContinuationT1(t.Item1, t.Item2);
  36. }
  37. }, StateTuple.Create(this, awaiter));
  38. }
  39. }
  40. {
  41. var awaiter = task2.GetAwaiter();
  42. if (awaiter.IsCompleted)
  43. {
  44. TryInvokeContinuationT2(this, awaiter);
  45. }
  46. else
  47. {
  48. awaiter.SourceOnCompleted(state =>
  49. {
  50. using (var t = (StateTuple<WhenAnyPromise<T1, T2>, UniTask<T2>.Awaiter>)state)
  51. {
  52. TryInvokeContinuationT2(t.Item1, t.Item2);
  53. }
  54. }, StateTuple.Create(this, awaiter));
  55. }
  56. }
  57. }
  58. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2> self, in UniTask<T1>.Awaiter awaiter)
  59. {
  60. T1 result;
  61. try
  62. {
  63. result = awaiter.GetResult();
  64. }
  65. catch (Exception ex)
  66. {
  67. self.core.TrySetException(ex);
  68. return;
  69. }
  70. if (Interlocked.Increment(ref self.completedCount) == 1)
  71. {
  72. self.core.TrySetResult((0, result, default));
  73. }
  74. }
  75. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2> self, in UniTask<T2>.Awaiter awaiter)
  76. {
  77. T2 result;
  78. try
  79. {
  80. result = awaiter.GetResult();
  81. }
  82. catch (Exception ex)
  83. {
  84. self.core.TrySetException(ex);
  85. return;
  86. }
  87. if (Interlocked.Increment(ref self.completedCount) == 1)
  88. {
  89. self.core.TrySetResult((1, default, result));
  90. }
  91. }
  92. public (int, T1 result1, T2 result2) GetResult(short token)
  93. {
  94. TaskTracker.RemoveTracking(this);
  95. GC.SuppressFinalize(this);
  96. return core.GetResult(token);
  97. }
  98. public UniTaskStatus GetStatus(short token)
  99. {
  100. return core.GetStatus(token);
  101. }
  102. public void OnCompleted(Action<object> continuation, object state, short token)
  103. {
  104. core.OnCompleted(continuation, state, token);
  105. }
  106. public UniTaskStatus UnsafeGetStatus()
  107. {
  108. return core.UnsafeGetStatus();
  109. }
  110. void IUniTaskSource.GetResult(short token)
  111. {
  112. GetResult(token);
  113. }
  114. }
  115. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3)> WhenAny<T1, T2, T3>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3)
  116. {
  117. return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3)>(new WhenAnyPromise<T1, T2, T3>(task1, task2, task3), 0);
  118. }
  119. sealed class WhenAnyPromise<T1, T2, T3> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3)>
  120. {
  121. int completedCount;
  122. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3)> core;
  123. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3)
  124. {
  125. TaskTracker.TrackActiveTask(this, 3);
  126. this.completedCount = 0;
  127. {
  128. var awaiter = task1.GetAwaiter();
  129. if (awaiter.IsCompleted)
  130. {
  131. TryInvokeContinuationT1(this, awaiter);
  132. }
  133. else
  134. {
  135. awaiter.SourceOnCompleted(state =>
  136. {
  137. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3>, UniTask<T1>.Awaiter>)state)
  138. {
  139. TryInvokeContinuationT1(t.Item1, t.Item2);
  140. }
  141. }, StateTuple.Create(this, awaiter));
  142. }
  143. }
  144. {
  145. var awaiter = task2.GetAwaiter();
  146. if (awaiter.IsCompleted)
  147. {
  148. TryInvokeContinuationT2(this, awaiter);
  149. }
  150. else
  151. {
  152. awaiter.SourceOnCompleted(state =>
  153. {
  154. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3>, UniTask<T2>.Awaiter>)state)
  155. {
  156. TryInvokeContinuationT2(t.Item1, t.Item2);
  157. }
  158. }, StateTuple.Create(this, awaiter));
  159. }
  160. }
  161. {
  162. var awaiter = task3.GetAwaiter();
  163. if (awaiter.IsCompleted)
  164. {
  165. TryInvokeContinuationT3(this, awaiter);
  166. }
  167. else
  168. {
  169. awaiter.SourceOnCompleted(state =>
  170. {
  171. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3>, UniTask<T3>.Awaiter>)state)
  172. {
  173. TryInvokeContinuationT3(t.Item1, t.Item2);
  174. }
  175. }, StateTuple.Create(this, awaiter));
  176. }
  177. }
  178. }
  179. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3> self, in UniTask<T1>.Awaiter awaiter)
  180. {
  181. T1 result;
  182. try
  183. {
  184. result = awaiter.GetResult();
  185. }
  186. catch (Exception ex)
  187. {
  188. self.core.TrySetException(ex);
  189. return;
  190. }
  191. if (Interlocked.Increment(ref self.completedCount) == 1)
  192. {
  193. self.core.TrySetResult((0, result, default, default));
  194. }
  195. }
  196. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3> self, in UniTask<T2>.Awaiter awaiter)
  197. {
  198. T2 result;
  199. try
  200. {
  201. result = awaiter.GetResult();
  202. }
  203. catch (Exception ex)
  204. {
  205. self.core.TrySetException(ex);
  206. return;
  207. }
  208. if (Interlocked.Increment(ref self.completedCount) == 1)
  209. {
  210. self.core.TrySetResult((1, default, result, default));
  211. }
  212. }
  213. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3> self, in UniTask<T3>.Awaiter awaiter)
  214. {
  215. T3 result;
  216. try
  217. {
  218. result = awaiter.GetResult();
  219. }
  220. catch (Exception ex)
  221. {
  222. self.core.TrySetException(ex);
  223. return;
  224. }
  225. if (Interlocked.Increment(ref self.completedCount) == 1)
  226. {
  227. self.core.TrySetResult((2, default, default, result));
  228. }
  229. }
  230. public (int, T1 result1, T2 result2, T3 result3) GetResult(short token)
  231. {
  232. TaskTracker.RemoveTracking(this);
  233. GC.SuppressFinalize(this);
  234. return core.GetResult(token);
  235. }
  236. public UniTaskStatus GetStatus(short token)
  237. {
  238. return core.GetStatus(token);
  239. }
  240. public void OnCompleted(Action<object> continuation, object state, short token)
  241. {
  242. core.OnCompleted(continuation, state, token);
  243. }
  244. public UniTaskStatus UnsafeGetStatus()
  245. {
  246. return core.UnsafeGetStatus();
  247. }
  248. void IUniTaskSource.GetResult(short token)
  249. {
  250. GetResult(token);
  251. }
  252. }
  253. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4)> WhenAny<T1, T2, T3, T4>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4)
  254. {
  255. return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4)>(new WhenAnyPromise<T1, T2, T3, T4>(task1, task2, task3, task4), 0);
  256. }
  257. sealed class WhenAnyPromise<T1, T2, T3, T4> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4)>
  258. {
  259. int completedCount;
  260. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4)> core;
  261. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4)
  262. {
  263. TaskTracker.TrackActiveTask(this, 3);
  264. this.completedCount = 0;
  265. {
  266. var awaiter = task1.GetAwaiter();
  267. if (awaiter.IsCompleted)
  268. {
  269. TryInvokeContinuationT1(this, awaiter);
  270. }
  271. else
  272. {
  273. awaiter.SourceOnCompleted(state =>
  274. {
  275. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4>, UniTask<T1>.Awaiter>)state)
  276. {
  277. TryInvokeContinuationT1(t.Item1, t.Item2);
  278. }
  279. }, StateTuple.Create(this, awaiter));
  280. }
  281. }
  282. {
  283. var awaiter = task2.GetAwaiter();
  284. if (awaiter.IsCompleted)
  285. {
  286. TryInvokeContinuationT2(this, awaiter);
  287. }
  288. else
  289. {
  290. awaiter.SourceOnCompleted(state =>
  291. {
  292. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4>, UniTask<T2>.Awaiter>)state)
  293. {
  294. TryInvokeContinuationT2(t.Item1, t.Item2);
  295. }
  296. }, StateTuple.Create(this, awaiter));
  297. }
  298. }
  299. {
  300. var awaiter = task3.GetAwaiter();
  301. if (awaiter.IsCompleted)
  302. {
  303. TryInvokeContinuationT3(this, awaiter);
  304. }
  305. else
  306. {
  307. awaiter.SourceOnCompleted(state =>
  308. {
  309. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4>, UniTask<T3>.Awaiter>)state)
  310. {
  311. TryInvokeContinuationT3(t.Item1, t.Item2);
  312. }
  313. }, StateTuple.Create(this, awaiter));
  314. }
  315. }
  316. {
  317. var awaiter = task4.GetAwaiter();
  318. if (awaiter.IsCompleted)
  319. {
  320. TryInvokeContinuationT4(this, awaiter);
  321. }
  322. else
  323. {
  324. awaiter.SourceOnCompleted(state =>
  325. {
  326. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4>, UniTask<T4>.Awaiter>)state)
  327. {
  328. TryInvokeContinuationT4(t.Item1, t.Item2);
  329. }
  330. }, StateTuple.Create(this, awaiter));
  331. }
  332. }
  333. }
  334. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4> self, in UniTask<T1>.Awaiter awaiter)
  335. {
  336. T1 result;
  337. try
  338. {
  339. result = awaiter.GetResult();
  340. }
  341. catch (Exception ex)
  342. {
  343. self.core.TrySetException(ex);
  344. return;
  345. }
  346. if (Interlocked.Increment(ref self.completedCount) == 1)
  347. {
  348. self.core.TrySetResult((0, result, default, default, default));
  349. }
  350. }
  351. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4> self, in UniTask<T2>.Awaiter awaiter)
  352. {
  353. T2 result;
  354. try
  355. {
  356. result = awaiter.GetResult();
  357. }
  358. catch (Exception ex)
  359. {
  360. self.core.TrySetException(ex);
  361. return;
  362. }
  363. if (Interlocked.Increment(ref self.completedCount) == 1)
  364. {
  365. self.core.TrySetResult((1, default, result, default, default));
  366. }
  367. }
  368. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4> self, in UniTask<T3>.Awaiter awaiter)
  369. {
  370. T3 result;
  371. try
  372. {
  373. result = awaiter.GetResult();
  374. }
  375. catch (Exception ex)
  376. {
  377. self.core.TrySetException(ex);
  378. return;
  379. }
  380. if (Interlocked.Increment(ref self.completedCount) == 1)
  381. {
  382. self.core.TrySetResult((2, default, default, result, default));
  383. }
  384. }
  385. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4> self, in UniTask<T4>.Awaiter awaiter)
  386. {
  387. T4 result;
  388. try
  389. {
  390. result = awaiter.GetResult();
  391. }
  392. catch (Exception ex)
  393. {
  394. self.core.TrySetException(ex);
  395. return;
  396. }
  397. if (Interlocked.Increment(ref self.completedCount) == 1)
  398. {
  399. self.core.TrySetResult((3, default, default, default, result));
  400. }
  401. }
  402. public (int, T1 result1, T2 result2, T3 result3, T4 result4) GetResult(short token)
  403. {
  404. TaskTracker.RemoveTracking(this);
  405. GC.SuppressFinalize(this);
  406. return core.GetResult(token);
  407. }
  408. public UniTaskStatus GetStatus(short token)
  409. {
  410. return core.GetStatus(token);
  411. }
  412. public void OnCompleted(Action<object> continuation, object state, short token)
  413. {
  414. core.OnCompleted(continuation, state, token);
  415. }
  416. public UniTaskStatus UnsafeGetStatus()
  417. {
  418. return core.UnsafeGetStatus();
  419. }
  420. void IUniTaskSource.GetResult(short token)
  421. {
  422. GetResult(token);
  423. }
  424. }
  425. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> WhenAny<T1, T2, T3, T4, T5>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5)
  426. {
  427. return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)>(new WhenAnyPromise<T1, T2, T3, T4, T5>(task1, task2, task3, task4, task5), 0);
  428. }
  429. sealed class WhenAnyPromise<T1, T2, T3, T4, T5> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)>
  430. {
  431. int completedCount;
  432. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> core;
  433. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5)
  434. {
  435. TaskTracker.TrackActiveTask(this, 3);
  436. this.completedCount = 0;
  437. {
  438. var awaiter = task1.GetAwaiter();
  439. if (awaiter.IsCompleted)
  440. {
  441. TryInvokeContinuationT1(this, awaiter);
  442. }
  443. else
  444. {
  445. awaiter.SourceOnCompleted(state =>
  446. {
  447. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5>, UniTask<T1>.Awaiter>)state)
  448. {
  449. TryInvokeContinuationT1(t.Item1, t.Item2);
  450. }
  451. }, StateTuple.Create(this, awaiter));
  452. }
  453. }
  454. {
  455. var awaiter = task2.GetAwaiter();
  456. if (awaiter.IsCompleted)
  457. {
  458. TryInvokeContinuationT2(this, awaiter);
  459. }
  460. else
  461. {
  462. awaiter.SourceOnCompleted(state =>
  463. {
  464. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5>, UniTask<T2>.Awaiter>)state)
  465. {
  466. TryInvokeContinuationT2(t.Item1, t.Item2);
  467. }
  468. }, StateTuple.Create(this, awaiter));
  469. }
  470. }
  471. {
  472. var awaiter = task3.GetAwaiter();
  473. if (awaiter.IsCompleted)
  474. {
  475. TryInvokeContinuationT3(this, awaiter);
  476. }
  477. else
  478. {
  479. awaiter.SourceOnCompleted(state =>
  480. {
  481. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5>, UniTask<T3>.Awaiter>)state)
  482. {
  483. TryInvokeContinuationT3(t.Item1, t.Item2);
  484. }
  485. }, StateTuple.Create(this, awaiter));
  486. }
  487. }
  488. {
  489. var awaiter = task4.GetAwaiter();
  490. if (awaiter.IsCompleted)
  491. {
  492. TryInvokeContinuationT4(this, awaiter);
  493. }
  494. else
  495. {
  496. awaiter.SourceOnCompleted(state =>
  497. {
  498. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5>, UniTask<T4>.Awaiter>)state)
  499. {
  500. TryInvokeContinuationT4(t.Item1, t.Item2);
  501. }
  502. }, StateTuple.Create(this, awaiter));
  503. }
  504. }
  505. {
  506. var awaiter = task5.GetAwaiter();
  507. if (awaiter.IsCompleted)
  508. {
  509. TryInvokeContinuationT5(this, awaiter);
  510. }
  511. else
  512. {
  513. awaiter.SourceOnCompleted(state =>
  514. {
  515. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5>, UniTask<T5>.Awaiter>)state)
  516. {
  517. TryInvokeContinuationT5(t.Item1, t.Item2);
  518. }
  519. }, StateTuple.Create(this, awaiter));
  520. }
  521. }
  522. }
  523. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5> self, in UniTask<T1>.Awaiter awaiter)
  524. {
  525. T1 result;
  526. try
  527. {
  528. result = awaiter.GetResult();
  529. }
  530. catch (Exception ex)
  531. {
  532. self.core.TrySetException(ex);
  533. return;
  534. }
  535. if (Interlocked.Increment(ref self.completedCount) == 1)
  536. {
  537. self.core.TrySetResult((0, result, default, default, default, default));
  538. }
  539. }
  540. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5> self, in UniTask<T2>.Awaiter awaiter)
  541. {
  542. T2 result;
  543. try
  544. {
  545. result = awaiter.GetResult();
  546. }
  547. catch (Exception ex)
  548. {
  549. self.core.TrySetException(ex);
  550. return;
  551. }
  552. if (Interlocked.Increment(ref self.completedCount) == 1)
  553. {
  554. self.core.TrySetResult((1, default, result, default, default, default));
  555. }
  556. }
  557. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5> self, in UniTask<T3>.Awaiter awaiter)
  558. {
  559. T3 result;
  560. try
  561. {
  562. result = awaiter.GetResult();
  563. }
  564. catch (Exception ex)
  565. {
  566. self.core.TrySetException(ex);
  567. return;
  568. }
  569. if (Interlocked.Increment(ref self.completedCount) == 1)
  570. {
  571. self.core.TrySetResult((2, default, default, result, default, default));
  572. }
  573. }
  574. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5> self, in UniTask<T4>.Awaiter awaiter)
  575. {
  576. T4 result;
  577. try
  578. {
  579. result = awaiter.GetResult();
  580. }
  581. catch (Exception ex)
  582. {
  583. self.core.TrySetException(ex);
  584. return;
  585. }
  586. if (Interlocked.Increment(ref self.completedCount) == 1)
  587. {
  588. self.core.TrySetResult((3, default, default, default, result, default));
  589. }
  590. }
  591. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5> self, in UniTask<T5>.Awaiter awaiter)
  592. {
  593. T5 result;
  594. try
  595. {
  596. result = awaiter.GetResult();
  597. }
  598. catch (Exception ex)
  599. {
  600. self.core.TrySetException(ex);
  601. return;
  602. }
  603. if (Interlocked.Increment(ref self.completedCount) == 1)
  604. {
  605. self.core.TrySetResult((4, default, default, default, default, result));
  606. }
  607. }
  608. public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5) GetResult(short token)
  609. {
  610. TaskTracker.RemoveTracking(this);
  611. GC.SuppressFinalize(this);
  612. return core.GetResult(token);
  613. }
  614. public UniTaskStatus GetStatus(short token)
  615. {
  616. return core.GetStatus(token);
  617. }
  618. public void OnCompleted(Action<object> continuation, object state, short token)
  619. {
  620. core.OnCompleted(continuation, state, token);
  621. }
  622. public UniTaskStatus UnsafeGetStatus()
  623. {
  624. return core.UnsafeGetStatus();
  625. }
  626. void IUniTaskSource.GetResult(short token)
  627. {
  628. GetResult(token);
  629. }
  630. }
  631. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> WhenAny<T1, T2, T3, T4, T5, T6>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6)
  632. {
  633. return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)>(new WhenAnyPromise<T1, T2, T3, T4, T5, T6>(task1, task2, task3, task4, task5, task6), 0);
  634. }
  635. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)>
  636. {
  637. int completedCount;
  638. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> core;
  639. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6)
  640. {
  641. TaskTracker.TrackActiveTask(this, 3);
  642. this.completedCount = 0;
  643. {
  644. var awaiter = task1.GetAwaiter();
  645. if (awaiter.IsCompleted)
  646. {
  647. TryInvokeContinuationT1(this, awaiter);
  648. }
  649. else
  650. {
  651. awaiter.SourceOnCompleted(state =>
  652. {
  653. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6>, UniTask<T1>.Awaiter>)state)
  654. {
  655. TryInvokeContinuationT1(t.Item1, t.Item2);
  656. }
  657. }, StateTuple.Create(this, awaiter));
  658. }
  659. }
  660. {
  661. var awaiter = task2.GetAwaiter();
  662. if (awaiter.IsCompleted)
  663. {
  664. TryInvokeContinuationT2(this, awaiter);
  665. }
  666. else
  667. {
  668. awaiter.SourceOnCompleted(state =>
  669. {
  670. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6>, UniTask<T2>.Awaiter>)state)
  671. {
  672. TryInvokeContinuationT2(t.Item1, t.Item2);
  673. }
  674. }, StateTuple.Create(this, awaiter));
  675. }
  676. }
  677. {
  678. var awaiter = task3.GetAwaiter();
  679. if (awaiter.IsCompleted)
  680. {
  681. TryInvokeContinuationT3(this, awaiter);
  682. }
  683. else
  684. {
  685. awaiter.SourceOnCompleted(state =>
  686. {
  687. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6>, UniTask<T3>.Awaiter>)state)
  688. {
  689. TryInvokeContinuationT3(t.Item1, t.Item2);
  690. }
  691. }, StateTuple.Create(this, awaiter));
  692. }
  693. }
  694. {
  695. var awaiter = task4.GetAwaiter();
  696. if (awaiter.IsCompleted)
  697. {
  698. TryInvokeContinuationT4(this, awaiter);
  699. }
  700. else
  701. {
  702. awaiter.SourceOnCompleted(state =>
  703. {
  704. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6>, UniTask<T4>.Awaiter>)state)
  705. {
  706. TryInvokeContinuationT4(t.Item1, t.Item2);
  707. }
  708. }, StateTuple.Create(this, awaiter));
  709. }
  710. }
  711. {
  712. var awaiter = task5.GetAwaiter();
  713. if (awaiter.IsCompleted)
  714. {
  715. TryInvokeContinuationT5(this, awaiter);
  716. }
  717. else
  718. {
  719. awaiter.SourceOnCompleted(state =>
  720. {
  721. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6>, UniTask<T5>.Awaiter>)state)
  722. {
  723. TryInvokeContinuationT5(t.Item1, t.Item2);
  724. }
  725. }, StateTuple.Create(this, awaiter));
  726. }
  727. }
  728. {
  729. var awaiter = task6.GetAwaiter();
  730. if (awaiter.IsCompleted)
  731. {
  732. TryInvokeContinuationT6(this, awaiter);
  733. }
  734. else
  735. {
  736. awaiter.SourceOnCompleted(state =>
  737. {
  738. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6>, UniTask<T6>.Awaiter>)state)
  739. {
  740. TryInvokeContinuationT6(t.Item1, t.Item2);
  741. }
  742. }, StateTuple.Create(this, awaiter));
  743. }
  744. }
  745. }
  746. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6> self, in UniTask<T1>.Awaiter awaiter)
  747. {
  748. T1 result;
  749. try
  750. {
  751. result = awaiter.GetResult();
  752. }
  753. catch (Exception ex)
  754. {
  755. self.core.TrySetException(ex);
  756. return;
  757. }
  758. if (Interlocked.Increment(ref self.completedCount) == 1)
  759. {
  760. self.core.TrySetResult((0, result, default, default, default, default, default));
  761. }
  762. }
  763. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6> self, in UniTask<T2>.Awaiter awaiter)
  764. {
  765. T2 result;
  766. try
  767. {
  768. result = awaiter.GetResult();
  769. }
  770. catch (Exception ex)
  771. {
  772. self.core.TrySetException(ex);
  773. return;
  774. }
  775. if (Interlocked.Increment(ref self.completedCount) == 1)
  776. {
  777. self.core.TrySetResult((1, default, result, default, default, default, default));
  778. }
  779. }
  780. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6> self, in UniTask<T3>.Awaiter awaiter)
  781. {
  782. T3 result;
  783. try
  784. {
  785. result = awaiter.GetResult();
  786. }
  787. catch (Exception ex)
  788. {
  789. self.core.TrySetException(ex);
  790. return;
  791. }
  792. if (Interlocked.Increment(ref self.completedCount) == 1)
  793. {
  794. self.core.TrySetResult((2, default, default, result, default, default, default));
  795. }
  796. }
  797. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6> self, in UniTask<T4>.Awaiter awaiter)
  798. {
  799. T4 result;
  800. try
  801. {
  802. result = awaiter.GetResult();
  803. }
  804. catch (Exception ex)
  805. {
  806. self.core.TrySetException(ex);
  807. return;
  808. }
  809. if (Interlocked.Increment(ref self.completedCount) == 1)
  810. {
  811. self.core.TrySetResult((3, default, default, default, result, default, default));
  812. }
  813. }
  814. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6> self, in UniTask<T5>.Awaiter awaiter)
  815. {
  816. T5 result;
  817. try
  818. {
  819. result = awaiter.GetResult();
  820. }
  821. catch (Exception ex)
  822. {
  823. self.core.TrySetException(ex);
  824. return;
  825. }
  826. if (Interlocked.Increment(ref self.completedCount) == 1)
  827. {
  828. self.core.TrySetResult((4, default, default, default, default, result, default));
  829. }
  830. }
  831. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6> self, in UniTask<T6>.Awaiter awaiter)
  832. {
  833. T6 result;
  834. try
  835. {
  836. result = awaiter.GetResult();
  837. }
  838. catch (Exception ex)
  839. {
  840. self.core.TrySetException(ex);
  841. return;
  842. }
  843. if (Interlocked.Increment(ref self.completedCount) == 1)
  844. {
  845. self.core.TrySetResult((5, default, default, default, default, default, result));
  846. }
  847. }
  848. public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6) GetResult(short token)
  849. {
  850. TaskTracker.RemoveTracking(this);
  851. GC.SuppressFinalize(this);
  852. return core.GetResult(token);
  853. }
  854. public UniTaskStatus GetStatus(short token)
  855. {
  856. return core.GetStatus(token);
  857. }
  858. public void OnCompleted(Action<object> continuation, object state, short token)
  859. {
  860. core.OnCompleted(continuation, state, token);
  861. }
  862. public UniTaskStatus UnsafeGetStatus()
  863. {
  864. return core.UnsafeGetStatus();
  865. }
  866. void IUniTaskSource.GetResult(short token)
  867. {
  868. GetResult(token);
  869. }
  870. }
  871. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> WhenAny<T1, T2, T3, T4, T5, T6, T7>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7)
  872. {
  873. return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)>(new WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>(task1, task2, task3, task4, task5, task6, task7), 0);
  874. }
  875. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)>
  876. {
  877. int completedCount;
  878. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> core;
  879. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7)
  880. {
  881. TaskTracker.TrackActiveTask(this, 3);
  882. this.completedCount = 0;
  883. {
  884. var awaiter = task1.GetAwaiter();
  885. if (awaiter.IsCompleted)
  886. {
  887. TryInvokeContinuationT1(this, awaiter);
  888. }
  889. else
  890. {
  891. awaiter.SourceOnCompleted(state =>
  892. {
  893. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>, UniTask<T1>.Awaiter>)state)
  894. {
  895. TryInvokeContinuationT1(t.Item1, t.Item2);
  896. }
  897. }, StateTuple.Create(this, awaiter));
  898. }
  899. }
  900. {
  901. var awaiter = task2.GetAwaiter();
  902. if (awaiter.IsCompleted)
  903. {
  904. TryInvokeContinuationT2(this, awaiter);
  905. }
  906. else
  907. {
  908. awaiter.SourceOnCompleted(state =>
  909. {
  910. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>, UniTask<T2>.Awaiter>)state)
  911. {
  912. TryInvokeContinuationT2(t.Item1, t.Item2);
  913. }
  914. }, StateTuple.Create(this, awaiter));
  915. }
  916. }
  917. {
  918. var awaiter = task3.GetAwaiter();
  919. if (awaiter.IsCompleted)
  920. {
  921. TryInvokeContinuationT3(this, awaiter);
  922. }
  923. else
  924. {
  925. awaiter.SourceOnCompleted(state =>
  926. {
  927. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>, UniTask<T3>.Awaiter>)state)
  928. {
  929. TryInvokeContinuationT3(t.Item1, t.Item2);
  930. }
  931. }, StateTuple.Create(this, awaiter));
  932. }
  933. }
  934. {
  935. var awaiter = task4.GetAwaiter();
  936. if (awaiter.IsCompleted)
  937. {
  938. TryInvokeContinuationT4(this, awaiter);
  939. }
  940. else
  941. {
  942. awaiter.SourceOnCompleted(state =>
  943. {
  944. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>, UniTask<T4>.Awaiter>)state)
  945. {
  946. TryInvokeContinuationT4(t.Item1, t.Item2);
  947. }
  948. }, StateTuple.Create(this, awaiter));
  949. }
  950. }
  951. {
  952. var awaiter = task5.GetAwaiter();
  953. if (awaiter.IsCompleted)
  954. {
  955. TryInvokeContinuationT5(this, awaiter);
  956. }
  957. else
  958. {
  959. awaiter.SourceOnCompleted(state =>
  960. {
  961. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>, UniTask<T5>.Awaiter>)state)
  962. {
  963. TryInvokeContinuationT5(t.Item1, t.Item2);
  964. }
  965. }, StateTuple.Create(this, awaiter));
  966. }
  967. }
  968. {
  969. var awaiter = task6.GetAwaiter();
  970. if (awaiter.IsCompleted)
  971. {
  972. TryInvokeContinuationT6(this, awaiter);
  973. }
  974. else
  975. {
  976. awaiter.SourceOnCompleted(state =>
  977. {
  978. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>, UniTask<T6>.Awaiter>)state)
  979. {
  980. TryInvokeContinuationT6(t.Item1, t.Item2);
  981. }
  982. }, StateTuple.Create(this, awaiter));
  983. }
  984. }
  985. {
  986. var awaiter = task7.GetAwaiter();
  987. if (awaiter.IsCompleted)
  988. {
  989. TryInvokeContinuationT7(this, awaiter);
  990. }
  991. else
  992. {
  993. awaiter.SourceOnCompleted(state =>
  994. {
  995. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7>, UniTask<T7>.Awaiter>)state)
  996. {
  997. TryInvokeContinuationT7(t.Item1, t.Item2);
  998. }
  999. }, StateTuple.Create(this, awaiter));
  1000. }
  1001. }
  1002. }
  1003. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> self, in UniTask<T1>.Awaiter awaiter)
  1004. {
  1005. T1 result;
  1006. try
  1007. {
  1008. result = awaiter.GetResult();
  1009. }
  1010. catch (Exception ex)
  1011. {
  1012. self.core.TrySetException(ex);
  1013. return;
  1014. }
  1015. if (Interlocked.Increment(ref self.completedCount) == 1)
  1016. {
  1017. self.core.TrySetResult((0, result, default, default, default, default, default, default));
  1018. }
  1019. }
  1020. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> self, in UniTask<T2>.Awaiter awaiter)
  1021. {
  1022. T2 result;
  1023. try
  1024. {
  1025. result = awaiter.GetResult();
  1026. }
  1027. catch (Exception ex)
  1028. {
  1029. self.core.TrySetException(ex);
  1030. return;
  1031. }
  1032. if (Interlocked.Increment(ref self.completedCount) == 1)
  1033. {
  1034. self.core.TrySetResult((1, default, result, default, default, default, default, default));
  1035. }
  1036. }
  1037. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> self, in UniTask<T3>.Awaiter awaiter)
  1038. {
  1039. T3 result;
  1040. try
  1041. {
  1042. result = awaiter.GetResult();
  1043. }
  1044. catch (Exception ex)
  1045. {
  1046. self.core.TrySetException(ex);
  1047. return;
  1048. }
  1049. if (Interlocked.Increment(ref self.completedCount) == 1)
  1050. {
  1051. self.core.TrySetResult((2, default, default, result, default, default, default, default));
  1052. }
  1053. }
  1054. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> self, in UniTask<T4>.Awaiter awaiter)
  1055. {
  1056. T4 result;
  1057. try
  1058. {
  1059. result = awaiter.GetResult();
  1060. }
  1061. catch (Exception ex)
  1062. {
  1063. self.core.TrySetException(ex);
  1064. return;
  1065. }
  1066. if (Interlocked.Increment(ref self.completedCount) == 1)
  1067. {
  1068. self.core.TrySetResult((3, default, default, default, result, default, default, default));
  1069. }
  1070. }
  1071. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> self, in UniTask<T5>.Awaiter awaiter)
  1072. {
  1073. T5 result;
  1074. try
  1075. {
  1076. result = awaiter.GetResult();
  1077. }
  1078. catch (Exception ex)
  1079. {
  1080. self.core.TrySetException(ex);
  1081. return;
  1082. }
  1083. if (Interlocked.Increment(ref self.completedCount) == 1)
  1084. {
  1085. self.core.TrySetResult((4, default, default, default, default, result, default, default));
  1086. }
  1087. }
  1088. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> self, in UniTask<T6>.Awaiter awaiter)
  1089. {
  1090. T6 result;
  1091. try
  1092. {
  1093. result = awaiter.GetResult();
  1094. }
  1095. catch (Exception ex)
  1096. {
  1097. self.core.TrySetException(ex);
  1098. return;
  1099. }
  1100. if (Interlocked.Increment(ref self.completedCount) == 1)
  1101. {
  1102. self.core.TrySetResult((5, default, default, default, default, default, result, default));
  1103. }
  1104. }
  1105. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7> self, in UniTask<T7>.Awaiter awaiter)
  1106. {
  1107. T7 result;
  1108. try
  1109. {
  1110. result = awaiter.GetResult();
  1111. }
  1112. catch (Exception ex)
  1113. {
  1114. self.core.TrySetException(ex);
  1115. return;
  1116. }
  1117. if (Interlocked.Increment(ref self.completedCount) == 1)
  1118. {
  1119. self.core.TrySetResult((6, default, default, default, default, default, default, result));
  1120. }
  1121. }
  1122. public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7) GetResult(short token)
  1123. {
  1124. TaskTracker.RemoveTracking(this);
  1125. GC.SuppressFinalize(this);
  1126. return core.GetResult(token);
  1127. }
  1128. public UniTaskStatus GetStatus(short token)
  1129. {
  1130. return core.GetStatus(token);
  1131. }
  1132. public void OnCompleted(Action<object> continuation, object state, short token)
  1133. {
  1134. core.OnCompleted(continuation, state, token);
  1135. }
  1136. public UniTaskStatus UnsafeGetStatus()
  1137. {
  1138. return core.UnsafeGetStatus();
  1139. }
  1140. void IUniTaskSource.GetResult(short token)
  1141. {
  1142. GetResult(token);
  1143. }
  1144. }
  1145. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)> WhenAny<T1, T2, T3, T4, T5, T6, T7, T8>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8)
  1146. {
  1147. return new UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)>(new WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>(task1, task2, task3, task4, task5, task6, task7, task8), 0);
  1148. }
  1149. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)>
  1150. {
  1151. int completedCount;
  1152. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)> core;
  1153. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8)
  1154. {
  1155. TaskTracker.TrackActiveTask(this, 3);
  1156. this.completedCount = 0;
  1157. {
  1158. var awaiter = task1.GetAwaiter();
  1159. if (awaiter.IsCompleted)
  1160. {
  1161. TryInvokeContinuationT1(this, awaiter);
  1162. }
  1163. else
  1164. {
  1165. awaiter.SourceOnCompleted(state =>
  1166. {
  1167. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T1>.Awaiter>)state)
  1168. {
  1169. TryInvokeContinuationT1(t.Item1, t.Item2);
  1170. }
  1171. }, StateTuple.Create(this, awaiter));
  1172. }
  1173. }
  1174. {
  1175. var awaiter = task2.GetAwaiter();
  1176. if (awaiter.IsCompleted)
  1177. {
  1178. TryInvokeContinuationT2(this, awaiter);
  1179. }
  1180. else
  1181. {
  1182. awaiter.SourceOnCompleted(state =>
  1183. {
  1184. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T2>.Awaiter>)state)
  1185. {
  1186. TryInvokeContinuationT2(t.Item1, t.Item2);
  1187. }
  1188. }, StateTuple.Create(this, awaiter));
  1189. }
  1190. }
  1191. {
  1192. var awaiter = task3.GetAwaiter();
  1193. if (awaiter.IsCompleted)
  1194. {
  1195. TryInvokeContinuationT3(this, awaiter);
  1196. }
  1197. else
  1198. {
  1199. awaiter.SourceOnCompleted(state =>
  1200. {
  1201. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T3>.Awaiter>)state)
  1202. {
  1203. TryInvokeContinuationT3(t.Item1, t.Item2);
  1204. }
  1205. }, StateTuple.Create(this, awaiter));
  1206. }
  1207. }
  1208. {
  1209. var awaiter = task4.GetAwaiter();
  1210. if (awaiter.IsCompleted)
  1211. {
  1212. TryInvokeContinuationT4(this, awaiter);
  1213. }
  1214. else
  1215. {
  1216. awaiter.SourceOnCompleted(state =>
  1217. {
  1218. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T4>.Awaiter>)state)
  1219. {
  1220. TryInvokeContinuationT4(t.Item1, t.Item2);
  1221. }
  1222. }, StateTuple.Create(this, awaiter));
  1223. }
  1224. }
  1225. {
  1226. var awaiter = task5.GetAwaiter();
  1227. if (awaiter.IsCompleted)
  1228. {
  1229. TryInvokeContinuationT5(this, awaiter);
  1230. }
  1231. else
  1232. {
  1233. awaiter.SourceOnCompleted(state =>
  1234. {
  1235. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T5>.Awaiter>)state)
  1236. {
  1237. TryInvokeContinuationT5(t.Item1, t.Item2);
  1238. }
  1239. }, StateTuple.Create(this, awaiter));
  1240. }
  1241. }
  1242. {
  1243. var awaiter = task6.GetAwaiter();
  1244. if (awaiter.IsCompleted)
  1245. {
  1246. TryInvokeContinuationT6(this, awaiter);
  1247. }
  1248. else
  1249. {
  1250. awaiter.SourceOnCompleted(state =>
  1251. {
  1252. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T6>.Awaiter>)state)
  1253. {
  1254. TryInvokeContinuationT6(t.Item1, t.Item2);
  1255. }
  1256. }, StateTuple.Create(this, awaiter));
  1257. }
  1258. }
  1259. {
  1260. var awaiter = task7.GetAwaiter();
  1261. if (awaiter.IsCompleted)
  1262. {
  1263. TryInvokeContinuationT7(this, awaiter);
  1264. }
  1265. else
  1266. {
  1267. awaiter.SourceOnCompleted(state =>
  1268. {
  1269. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T7>.Awaiter>)state)
  1270. {
  1271. TryInvokeContinuationT7(t.Item1, t.Item2);
  1272. }
  1273. }, StateTuple.Create(this, awaiter));
  1274. }
  1275. }
  1276. {
  1277. var awaiter = task8.GetAwaiter();
  1278. if (awaiter.IsCompleted)
  1279. {
  1280. TryInvokeContinuationT8(this, awaiter);
  1281. }
  1282. else
  1283. {
  1284. awaiter.SourceOnCompleted(state =>
  1285. {
  1286. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8>, UniTask<T8>.Awaiter>)state)
  1287. {
  1288. TryInvokeContinuationT8(t.Item1, t.Item2);
  1289. }
  1290. }, StateTuple.Create(this, awaiter));
  1291. }
  1292. }
  1293. }
  1294. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T1>.Awaiter awaiter)
  1295. {
  1296. T1 result;
  1297. try
  1298. {
  1299. result = awaiter.GetResult();
  1300. }
  1301. catch (Exception ex)
  1302. {
  1303. self.core.TrySetException(ex);
  1304. return;
  1305. }
  1306. if (Interlocked.Increment(ref self.completedCount) == 1)
  1307. {
  1308. self.core.TrySetResult((0, result, default, default, default, default, default, default, default));
  1309. }
  1310. }
  1311. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T2>.Awaiter awaiter)
  1312. {
  1313. T2 result;
  1314. try
  1315. {
  1316. result = awaiter.GetResult();
  1317. }
  1318. catch (Exception ex)
  1319. {
  1320. self.core.TrySetException(ex);
  1321. return;
  1322. }
  1323. if (Interlocked.Increment(ref self.completedCount) == 1)
  1324. {
  1325. self.core.TrySetResult((1, default, result, default, default, default, default, default, default));
  1326. }
  1327. }
  1328. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T3>.Awaiter awaiter)
  1329. {
  1330. T3 result;
  1331. try
  1332. {
  1333. result = awaiter.GetResult();
  1334. }
  1335. catch (Exception ex)
  1336. {
  1337. self.core.TrySetException(ex);
  1338. return;
  1339. }
  1340. if (Interlocked.Increment(ref self.completedCount) == 1)
  1341. {
  1342. self.core.TrySetResult((2, default, default, result, default, default, default, default, default));
  1343. }
  1344. }
  1345. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T4>.Awaiter awaiter)
  1346. {
  1347. T4 result;
  1348. try
  1349. {
  1350. result = awaiter.GetResult();
  1351. }
  1352. catch (Exception ex)
  1353. {
  1354. self.core.TrySetException(ex);
  1355. return;
  1356. }
  1357. if (Interlocked.Increment(ref self.completedCount) == 1)
  1358. {
  1359. self.core.TrySetResult((3, default, default, default, result, default, default, default, default));
  1360. }
  1361. }
  1362. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T5>.Awaiter awaiter)
  1363. {
  1364. T5 result;
  1365. try
  1366. {
  1367. result = awaiter.GetResult();
  1368. }
  1369. catch (Exception ex)
  1370. {
  1371. self.core.TrySetException(ex);
  1372. return;
  1373. }
  1374. if (Interlocked.Increment(ref self.completedCount) == 1)
  1375. {
  1376. self.core.TrySetResult((4, default, default, default, default, result, default, default, default));
  1377. }
  1378. }
  1379. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T6>.Awaiter awaiter)
  1380. {
  1381. T6 result;
  1382. try
  1383. {
  1384. result = awaiter.GetResult();
  1385. }
  1386. catch (Exception ex)
  1387. {
  1388. self.core.TrySetException(ex);
  1389. return;
  1390. }
  1391. if (Interlocked.Increment(ref self.completedCount) == 1)
  1392. {
  1393. self.core.TrySetResult((5, default, default, default, default, default, result, default, default));
  1394. }
  1395. }
  1396. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T7>.Awaiter awaiter)
  1397. {
  1398. T7 result;
  1399. try
  1400. {
  1401. result = awaiter.GetResult();
  1402. }
  1403. catch (Exception ex)
  1404. {
  1405. self.core.TrySetException(ex);
  1406. return;
  1407. }
  1408. if (Interlocked.Increment(ref self.completedCount) == 1)
  1409. {
  1410. self.core.TrySetResult((6, default, default, default, default, default, default, result, default));
  1411. }
  1412. }
  1413. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8> self, in UniTask<T8>.Awaiter awaiter)
  1414. {
  1415. T8 result;
  1416. try
  1417. {
  1418. result = awaiter.GetResult();
  1419. }
  1420. catch (Exception ex)
  1421. {
  1422. self.core.TrySetException(ex);
  1423. return;
  1424. }
  1425. if (Interlocked.Increment(ref self.completedCount) == 1)
  1426. {
  1427. self.core.TrySetResult((7, default, default, default, default, default, default, default, result));
  1428. }
  1429. }
  1430. public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8) GetResult(short token)
  1431. {
  1432. TaskTracker.RemoveTracking(this);
  1433. GC.SuppressFinalize(this);
  1434. return core.GetResult(token);
  1435. }
  1436. public UniTaskStatus GetStatus(short token)
  1437. {
  1438. return core.GetStatus(token);
  1439. }
  1440. public void OnCompleted(Action<object> continuation, object state, short token)
  1441. {
  1442. core.OnCompleted(continuation, state, token);
  1443. }
  1444. public UniTaskStatus UnsafeGetStatus()
  1445. {
  1446. return core.UnsafeGetStatus();
  1447. }
  1448. void IUniTaskSource.GetResult(short token)
  1449. {
  1450. GetResult(token);
  1451. }
  1452. }
  1453. public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)> WhenAny<T1, T2, T3, T4, T5, T6, T7, T8, T9>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9)
  1454. {
  1455. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9>(task1, task2, task3, task4, task5, task6, task7, task8, task9), 0);
  1456. }
  1457. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)>
  1458. {
  1459. int completedCount;
  1460. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)> core;
  1461. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9)
  1462. {
  1463. TaskTracker.TrackActiveTask(this, 3);
  1464. this.completedCount = 0;
  1465. {
  1466. var awaiter = task1.GetAwaiter();
  1467. if (awaiter.IsCompleted)
  1468. {
  1469. TryInvokeContinuationT1(this, awaiter);
  1470. }
  1471. else
  1472. {
  1473. awaiter.SourceOnCompleted(state =>
  1474. {
  1475. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T1>.Awaiter>)state)
  1476. {
  1477. TryInvokeContinuationT1(t.Item1, t.Item2);
  1478. }
  1479. }, StateTuple.Create(this, awaiter));
  1480. }
  1481. }
  1482. {
  1483. var awaiter = task2.GetAwaiter();
  1484. if (awaiter.IsCompleted)
  1485. {
  1486. TryInvokeContinuationT2(this, awaiter);
  1487. }
  1488. else
  1489. {
  1490. awaiter.SourceOnCompleted(state =>
  1491. {
  1492. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T2>.Awaiter>)state)
  1493. {
  1494. TryInvokeContinuationT2(t.Item1, t.Item2);
  1495. }
  1496. }, StateTuple.Create(this, awaiter));
  1497. }
  1498. }
  1499. {
  1500. var awaiter = task3.GetAwaiter();
  1501. if (awaiter.IsCompleted)
  1502. {
  1503. TryInvokeContinuationT3(this, awaiter);
  1504. }
  1505. else
  1506. {
  1507. awaiter.SourceOnCompleted(state =>
  1508. {
  1509. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T3>.Awaiter>)state)
  1510. {
  1511. TryInvokeContinuationT3(t.Item1, t.Item2);
  1512. }
  1513. }, StateTuple.Create(this, awaiter));
  1514. }
  1515. }
  1516. {
  1517. var awaiter = task4.GetAwaiter();
  1518. if (awaiter.IsCompleted)
  1519. {
  1520. TryInvokeContinuationT4(this, awaiter);
  1521. }
  1522. else
  1523. {
  1524. awaiter.SourceOnCompleted(state =>
  1525. {
  1526. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T4>.Awaiter>)state)
  1527. {
  1528. TryInvokeContinuationT4(t.Item1, t.Item2);
  1529. }
  1530. }, StateTuple.Create(this, awaiter));
  1531. }
  1532. }
  1533. {
  1534. var awaiter = task5.GetAwaiter();
  1535. if (awaiter.IsCompleted)
  1536. {
  1537. TryInvokeContinuationT5(this, awaiter);
  1538. }
  1539. else
  1540. {
  1541. awaiter.SourceOnCompleted(state =>
  1542. {
  1543. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T5>.Awaiter>)state)
  1544. {
  1545. TryInvokeContinuationT5(t.Item1, t.Item2);
  1546. }
  1547. }, StateTuple.Create(this, awaiter));
  1548. }
  1549. }
  1550. {
  1551. var awaiter = task6.GetAwaiter();
  1552. if (awaiter.IsCompleted)
  1553. {
  1554. TryInvokeContinuationT6(this, awaiter);
  1555. }
  1556. else
  1557. {
  1558. awaiter.SourceOnCompleted(state =>
  1559. {
  1560. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T6>.Awaiter>)state)
  1561. {
  1562. TryInvokeContinuationT6(t.Item1, t.Item2);
  1563. }
  1564. }, StateTuple.Create(this, awaiter));
  1565. }
  1566. }
  1567. {
  1568. var awaiter = task7.GetAwaiter();
  1569. if (awaiter.IsCompleted)
  1570. {
  1571. TryInvokeContinuationT7(this, awaiter);
  1572. }
  1573. else
  1574. {
  1575. awaiter.SourceOnCompleted(state =>
  1576. {
  1577. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T7>.Awaiter>)state)
  1578. {
  1579. TryInvokeContinuationT7(t.Item1, t.Item2);
  1580. }
  1581. }, StateTuple.Create(this, awaiter));
  1582. }
  1583. }
  1584. {
  1585. var awaiter = task8.GetAwaiter();
  1586. if (awaiter.IsCompleted)
  1587. {
  1588. TryInvokeContinuationT8(this, awaiter);
  1589. }
  1590. else
  1591. {
  1592. awaiter.SourceOnCompleted(state =>
  1593. {
  1594. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T8>.Awaiter>)state)
  1595. {
  1596. TryInvokeContinuationT8(t.Item1, t.Item2);
  1597. }
  1598. }, StateTuple.Create(this, awaiter));
  1599. }
  1600. }
  1601. {
  1602. var awaiter = task9.GetAwaiter();
  1603. if (awaiter.IsCompleted)
  1604. {
  1605. TryInvokeContinuationT9(this, awaiter);
  1606. }
  1607. else
  1608. {
  1609. awaiter.SourceOnCompleted(state =>
  1610. {
  1611. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9>, UniTask<T9>.Awaiter>)state)
  1612. {
  1613. TryInvokeContinuationT9(t.Item1, t.Item2);
  1614. }
  1615. }, StateTuple.Create(this, awaiter));
  1616. }
  1617. }
  1618. }
  1619. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T1>.Awaiter awaiter)
  1620. {
  1621. T1 result;
  1622. try
  1623. {
  1624. result = awaiter.GetResult();
  1625. }
  1626. catch (Exception ex)
  1627. {
  1628. self.core.TrySetException(ex);
  1629. return;
  1630. }
  1631. if (Interlocked.Increment(ref self.completedCount) == 1)
  1632. {
  1633. self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default));
  1634. }
  1635. }
  1636. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T2>.Awaiter awaiter)
  1637. {
  1638. T2 result;
  1639. try
  1640. {
  1641. result = awaiter.GetResult();
  1642. }
  1643. catch (Exception ex)
  1644. {
  1645. self.core.TrySetException(ex);
  1646. return;
  1647. }
  1648. if (Interlocked.Increment(ref self.completedCount) == 1)
  1649. {
  1650. self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default));
  1651. }
  1652. }
  1653. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T3>.Awaiter awaiter)
  1654. {
  1655. T3 result;
  1656. try
  1657. {
  1658. result = awaiter.GetResult();
  1659. }
  1660. catch (Exception ex)
  1661. {
  1662. self.core.TrySetException(ex);
  1663. return;
  1664. }
  1665. if (Interlocked.Increment(ref self.completedCount) == 1)
  1666. {
  1667. self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default));
  1668. }
  1669. }
  1670. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T4>.Awaiter awaiter)
  1671. {
  1672. T4 result;
  1673. try
  1674. {
  1675. result = awaiter.GetResult();
  1676. }
  1677. catch (Exception ex)
  1678. {
  1679. self.core.TrySetException(ex);
  1680. return;
  1681. }
  1682. if (Interlocked.Increment(ref self.completedCount) == 1)
  1683. {
  1684. self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default));
  1685. }
  1686. }
  1687. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T5>.Awaiter awaiter)
  1688. {
  1689. T5 result;
  1690. try
  1691. {
  1692. result = awaiter.GetResult();
  1693. }
  1694. catch (Exception ex)
  1695. {
  1696. self.core.TrySetException(ex);
  1697. return;
  1698. }
  1699. if (Interlocked.Increment(ref self.completedCount) == 1)
  1700. {
  1701. self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default));
  1702. }
  1703. }
  1704. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T6>.Awaiter awaiter)
  1705. {
  1706. T6 result;
  1707. try
  1708. {
  1709. result = awaiter.GetResult();
  1710. }
  1711. catch (Exception ex)
  1712. {
  1713. self.core.TrySetException(ex);
  1714. return;
  1715. }
  1716. if (Interlocked.Increment(ref self.completedCount) == 1)
  1717. {
  1718. self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default));
  1719. }
  1720. }
  1721. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T7>.Awaiter awaiter)
  1722. {
  1723. T7 result;
  1724. try
  1725. {
  1726. result = awaiter.GetResult();
  1727. }
  1728. catch (Exception ex)
  1729. {
  1730. self.core.TrySetException(ex);
  1731. return;
  1732. }
  1733. if (Interlocked.Increment(ref self.completedCount) == 1)
  1734. {
  1735. self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default));
  1736. }
  1737. }
  1738. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T8>.Awaiter awaiter)
  1739. {
  1740. T8 result;
  1741. try
  1742. {
  1743. result = awaiter.GetResult();
  1744. }
  1745. catch (Exception ex)
  1746. {
  1747. self.core.TrySetException(ex);
  1748. return;
  1749. }
  1750. if (Interlocked.Increment(ref self.completedCount) == 1)
  1751. {
  1752. self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default));
  1753. }
  1754. }
  1755. static void TryInvokeContinuationT9(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9> self, in UniTask<T9>.Awaiter awaiter)
  1756. {
  1757. T9 result;
  1758. try
  1759. {
  1760. result = awaiter.GetResult();
  1761. }
  1762. catch (Exception ex)
  1763. {
  1764. self.core.TrySetException(ex);
  1765. return;
  1766. }
  1767. if (Interlocked.Increment(ref self.completedCount) == 1)
  1768. {
  1769. self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result));
  1770. }
  1771. }
  1772. public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9) GetResult(short token)
  1773. {
  1774. TaskTracker.RemoveTracking(this);
  1775. GC.SuppressFinalize(this);
  1776. return core.GetResult(token);
  1777. }
  1778. public UniTaskStatus GetStatus(short token)
  1779. {
  1780. return core.GetStatus(token);
  1781. }
  1782. public void OnCompleted(Action<object> continuation, object state, short token)
  1783. {
  1784. core.OnCompleted(continuation, state, token);
  1785. }
  1786. public UniTaskStatus UnsafeGetStatus()
  1787. {
  1788. return core.UnsafeGetStatus();
  1789. }
  1790. void IUniTaskSource.GetResult(short token)
  1791. {
  1792. GetResult(token);
  1793. }
  1794. }
  1795. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10)
  1796. {
  1797. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10), 0);
  1798. }
  1799. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10)>
  1800. {
  1801. int completedCount;
  1802. UniTaskCompletionSourceCore<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10)> core;
  1803. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10)
  1804. {
  1805. TaskTracker.TrackActiveTask(this, 3);
  1806. this.completedCount = 0;
  1807. {
  1808. var awaiter = task1.GetAwaiter();
  1809. if (awaiter.IsCompleted)
  1810. {
  1811. TryInvokeContinuationT1(this, awaiter);
  1812. }
  1813. else
  1814. {
  1815. awaiter.SourceOnCompleted(state =>
  1816. {
  1817. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T1>.Awaiter>)state)
  1818. {
  1819. TryInvokeContinuationT1(t.Item1, t.Item2);
  1820. }
  1821. }, StateTuple.Create(this, awaiter));
  1822. }
  1823. }
  1824. {
  1825. var awaiter = task2.GetAwaiter();
  1826. if (awaiter.IsCompleted)
  1827. {
  1828. TryInvokeContinuationT2(this, awaiter);
  1829. }
  1830. else
  1831. {
  1832. awaiter.SourceOnCompleted(state =>
  1833. {
  1834. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T2>.Awaiter>)state)
  1835. {
  1836. TryInvokeContinuationT2(t.Item1, t.Item2);
  1837. }
  1838. }, StateTuple.Create(this, awaiter));
  1839. }
  1840. }
  1841. {
  1842. var awaiter = task3.GetAwaiter();
  1843. if (awaiter.IsCompleted)
  1844. {
  1845. TryInvokeContinuationT3(this, awaiter);
  1846. }
  1847. else
  1848. {
  1849. awaiter.SourceOnCompleted(state =>
  1850. {
  1851. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T3>.Awaiter>)state)
  1852. {
  1853. TryInvokeContinuationT3(t.Item1, t.Item2);
  1854. }
  1855. }, StateTuple.Create(this, awaiter));
  1856. }
  1857. }
  1858. {
  1859. var awaiter = task4.GetAwaiter();
  1860. if (awaiter.IsCompleted)
  1861. {
  1862. TryInvokeContinuationT4(this, awaiter);
  1863. }
  1864. else
  1865. {
  1866. awaiter.SourceOnCompleted(state =>
  1867. {
  1868. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T4>.Awaiter>)state)
  1869. {
  1870. TryInvokeContinuationT4(t.Item1, t.Item2);
  1871. }
  1872. }, StateTuple.Create(this, awaiter));
  1873. }
  1874. }
  1875. {
  1876. var awaiter = task5.GetAwaiter();
  1877. if (awaiter.IsCompleted)
  1878. {
  1879. TryInvokeContinuationT5(this, awaiter);
  1880. }
  1881. else
  1882. {
  1883. awaiter.SourceOnCompleted(state =>
  1884. {
  1885. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T5>.Awaiter>)state)
  1886. {
  1887. TryInvokeContinuationT5(t.Item1, t.Item2);
  1888. }
  1889. }, StateTuple.Create(this, awaiter));
  1890. }
  1891. }
  1892. {
  1893. var awaiter = task6.GetAwaiter();
  1894. if (awaiter.IsCompleted)
  1895. {
  1896. TryInvokeContinuationT6(this, awaiter);
  1897. }
  1898. else
  1899. {
  1900. awaiter.SourceOnCompleted(state =>
  1901. {
  1902. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T6>.Awaiter>)state)
  1903. {
  1904. TryInvokeContinuationT6(t.Item1, t.Item2);
  1905. }
  1906. }, StateTuple.Create(this, awaiter));
  1907. }
  1908. }
  1909. {
  1910. var awaiter = task7.GetAwaiter();
  1911. if (awaiter.IsCompleted)
  1912. {
  1913. TryInvokeContinuationT7(this, awaiter);
  1914. }
  1915. else
  1916. {
  1917. awaiter.SourceOnCompleted(state =>
  1918. {
  1919. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T7>.Awaiter>)state)
  1920. {
  1921. TryInvokeContinuationT7(t.Item1, t.Item2);
  1922. }
  1923. }, StateTuple.Create(this, awaiter));
  1924. }
  1925. }
  1926. {
  1927. var awaiter = task8.GetAwaiter();
  1928. if (awaiter.IsCompleted)
  1929. {
  1930. TryInvokeContinuationT8(this, awaiter);
  1931. }
  1932. else
  1933. {
  1934. awaiter.SourceOnCompleted(state =>
  1935. {
  1936. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T8>.Awaiter>)state)
  1937. {
  1938. TryInvokeContinuationT8(t.Item1, t.Item2);
  1939. }
  1940. }, StateTuple.Create(this, awaiter));
  1941. }
  1942. }
  1943. {
  1944. var awaiter = task9.GetAwaiter();
  1945. if (awaiter.IsCompleted)
  1946. {
  1947. TryInvokeContinuationT9(this, awaiter);
  1948. }
  1949. else
  1950. {
  1951. awaiter.SourceOnCompleted(state =>
  1952. {
  1953. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T9>.Awaiter>)state)
  1954. {
  1955. TryInvokeContinuationT9(t.Item1, t.Item2);
  1956. }
  1957. }, StateTuple.Create(this, awaiter));
  1958. }
  1959. }
  1960. {
  1961. var awaiter = task10.GetAwaiter();
  1962. if (awaiter.IsCompleted)
  1963. {
  1964. TryInvokeContinuationT10(this, awaiter);
  1965. }
  1966. else
  1967. {
  1968. awaiter.SourceOnCompleted(state =>
  1969. {
  1970. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, UniTask<T10>.Awaiter>)state)
  1971. {
  1972. TryInvokeContinuationT10(t.Item1, t.Item2);
  1973. }
  1974. }, StateTuple.Create(this, awaiter));
  1975. }
  1976. }
  1977. }
  1978. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T1>.Awaiter awaiter)
  1979. {
  1980. T1 result;
  1981. try
  1982. {
  1983. result = awaiter.GetResult();
  1984. }
  1985. catch (Exception ex)
  1986. {
  1987. self.core.TrySetException(ex);
  1988. return;
  1989. }
  1990. if (Interlocked.Increment(ref self.completedCount) == 1)
  1991. {
  1992. self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default));
  1993. }
  1994. }
  1995. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T2>.Awaiter awaiter)
  1996. {
  1997. T2 result;
  1998. try
  1999. {
  2000. result = awaiter.GetResult();
  2001. }
  2002. catch (Exception ex)
  2003. {
  2004. self.core.TrySetException(ex);
  2005. return;
  2006. }
  2007. if (Interlocked.Increment(ref self.completedCount) == 1)
  2008. {
  2009. self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default));
  2010. }
  2011. }
  2012. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T3>.Awaiter awaiter)
  2013. {
  2014. T3 result;
  2015. try
  2016. {
  2017. result = awaiter.GetResult();
  2018. }
  2019. catch (Exception ex)
  2020. {
  2021. self.core.TrySetException(ex);
  2022. return;
  2023. }
  2024. if (Interlocked.Increment(ref self.completedCount) == 1)
  2025. {
  2026. self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default));
  2027. }
  2028. }
  2029. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T4>.Awaiter awaiter)
  2030. {
  2031. T4 result;
  2032. try
  2033. {
  2034. result = awaiter.GetResult();
  2035. }
  2036. catch (Exception ex)
  2037. {
  2038. self.core.TrySetException(ex);
  2039. return;
  2040. }
  2041. if (Interlocked.Increment(ref self.completedCount) == 1)
  2042. {
  2043. self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default));
  2044. }
  2045. }
  2046. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T5>.Awaiter awaiter)
  2047. {
  2048. T5 result;
  2049. try
  2050. {
  2051. result = awaiter.GetResult();
  2052. }
  2053. catch (Exception ex)
  2054. {
  2055. self.core.TrySetException(ex);
  2056. return;
  2057. }
  2058. if (Interlocked.Increment(ref self.completedCount) == 1)
  2059. {
  2060. self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default));
  2061. }
  2062. }
  2063. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T6>.Awaiter awaiter)
  2064. {
  2065. T6 result;
  2066. try
  2067. {
  2068. result = awaiter.GetResult();
  2069. }
  2070. catch (Exception ex)
  2071. {
  2072. self.core.TrySetException(ex);
  2073. return;
  2074. }
  2075. if (Interlocked.Increment(ref self.completedCount) == 1)
  2076. {
  2077. self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default));
  2078. }
  2079. }
  2080. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T7>.Awaiter awaiter)
  2081. {
  2082. T7 result;
  2083. try
  2084. {
  2085. result = awaiter.GetResult();
  2086. }
  2087. catch (Exception ex)
  2088. {
  2089. self.core.TrySetException(ex);
  2090. return;
  2091. }
  2092. if (Interlocked.Increment(ref self.completedCount) == 1)
  2093. {
  2094. self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default));
  2095. }
  2096. }
  2097. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T8>.Awaiter awaiter)
  2098. {
  2099. T8 result;
  2100. try
  2101. {
  2102. result = awaiter.GetResult();
  2103. }
  2104. catch (Exception ex)
  2105. {
  2106. self.core.TrySetException(ex);
  2107. return;
  2108. }
  2109. if (Interlocked.Increment(ref self.completedCount) == 1)
  2110. {
  2111. self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default));
  2112. }
  2113. }
  2114. static void TryInvokeContinuationT9(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T9>.Awaiter awaiter)
  2115. {
  2116. T9 result;
  2117. try
  2118. {
  2119. result = awaiter.GetResult();
  2120. }
  2121. catch (Exception ex)
  2122. {
  2123. self.core.TrySetException(ex);
  2124. return;
  2125. }
  2126. if (Interlocked.Increment(ref self.completedCount) == 1)
  2127. {
  2128. self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default));
  2129. }
  2130. }
  2131. static void TryInvokeContinuationT10(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self, in UniTask<T10>.Awaiter awaiter)
  2132. {
  2133. T10 result;
  2134. try
  2135. {
  2136. result = awaiter.GetResult();
  2137. }
  2138. catch (Exception ex)
  2139. {
  2140. self.core.TrySetException(ex);
  2141. return;
  2142. }
  2143. if (Interlocked.Increment(ref self.completedCount) == 1)
  2144. {
  2145. self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result));
  2146. }
  2147. }
  2148. 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)
  2149. {
  2150. TaskTracker.RemoveTracking(this);
  2151. GC.SuppressFinalize(this);
  2152. return core.GetResult(token);
  2153. }
  2154. public UniTaskStatus GetStatus(short token)
  2155. {
  2156. return core.GetStatus(token);
  2157. }
  2158. public void OnCompleted(Action<object> continuation, object state, short token)
  2159. {
  2160. core.OnCompleted(continuation, state, token);
  2161. }
  2162. public UniTaskStatus UnsafeGetStatus()
  2163. {
  2164. return core.UnsafeGetStatus();
  2165. }
  2166. void IUniTaskSource.GetResult(short token)
  2167. {
  2168. GetResult(token);
  2169. }
  2170. }
  2171. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11)
  2172. {
  2173. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11), 0);
  2174. }
  2175. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : IUniTaskSource<(int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11)>
  2176. {
  2177. int completedCount;
  2178. 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;
  2179. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11)
  2180. {
  2181. TaskTracker.TrackActiveTask(this, 3);
  2182. this.completedCount = 0;
  2183. {
  2184. var awaiter = task1.GetAwaiter();
  2185. if (awaiter.IsCompleted)
  2186. {
  2187. TryInvokeContinuationT1(this, awaiter);
  2188. }
  2189. else
  2190. {
  2191. awaiter.SourceOnCompleted(state =>
  2192. {
  2193. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T1>.Awaiter>)state)
  2194. {
  2195. TryInvokeContinuationT1(t.Item1, t.Item2);
  2196. }
  2197. }, StateTuple.Create(this, awaiter));
  2198. }
  2199. }
  2200. {
  2201. var awaiter = task2.GetAwaiter();
  2202. if (awaiter.IsCompleted)
  2203. {
  2204. TryInvokeContinuationT2(this, awaiter);
  2205. }
  2206. else
  2207. {
  2208. awaiter.SourceOnCompleted(state =>
  2209. {
  2210. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T2>.Awaiter>)state)
  2211. {
  2212. TryInvokeContinuationT2(t.Item1, t.Item2);
  2213. }
  2214. }, StateTuple.Create(this, awaiter));
  2215. }
  2216. }
  2217. {
  2218. var awaiter = task3.GetAwaiter();
  2219. if (awaiter.IsCompleted)
  2220. {
  2221. TryInvokeContinuationT3(this, awaiter);
  2222. }
  2223. else
  2224. {
  2225. awaiter.SourceOnCompleted(state =>
  2226. {
  2227. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T3>.Awaiter>)state)
  2228. {
  2229. TryInvokeContinuationT3(t.Item1, t.Item2);
  2230. }
  2231. }, StateTuple.Create(this, awaiter));
  2232. }
  2233. }
  2234. {
  2235. var awaiter = task4.GetAwaiter();
  2236. if (awaiter.IsCompleted)
  2237. {
  2238. TryInvokeContinuationT4(this, awaiter);
  2239. }
  2240. else
  2241. {
  2242. awaiter.SourceOnCompleted(state =>
  2243. {
  2244. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T4>.Awaiter>)state)
  2245. {
  2246. TryInvokeContinuationT4(t.Item1, t.Item2);
  2247. }
  2248. }, StateTuple.Create(this, awaiter));
  2249. }
  2250. }
  2251. {
  2252. var awaiter = task5.GetAwaiter();
  2253. if (awaiter.IsCompleted)
  2254. {
  2255. TryInvokeContinuationT5(this, awaiter);
  2256. }
  2257. else
  2258. {
  2259. awaiter.SourceOnCompleted(state =>
  2260. {
  2261. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T5>.Awaiter>)state)
  2262. {
  2263. TryInvokeContinuationT5(t.Item1, t.Item2);
  2264. }
  2265. }, StateTuple.Create(this, awaiter));
  2266. }
  2267. }
  2268. {
  2269. var awaiter = task6.GetAwaiter();
  2270. if (awaiter.IsCompleted)
  2271. {
  2272. TryInvokeContinuationT6(this, awaiter);
  2273. }
  2274. else
  2275. {
  2276. awaiter.SourceOnCompleted(state =>
  2277. {
  2278. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T6>.Awaiter>)state)
  2279. {
  2280. TryInvokeContinuationT6(t.Item1, t.Item2);
  2281. }
  2282. }, StateTuple.Create(this, awaiter));
  2283. }
  2284. }
  2285. {
  2286. var awaiter = task7.GetAwaiter();
  2287. if (awaiter.IsCompleted)
  2288. {
  2289. TryInvokeContinuationT7(this, awaiter);
  2290. }
  2291. else
  2292. {
  2293. awaiter.SourceOnCompleted(state =>
  2294. {
  2295. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T7>.Awaiter>)state)
  2296. {
  2297. TryInvokeContinuationT7(t.Item1, t.Item2);
  2298. }
  2299. }, StateTuple.Create(this, awaiter));
  2300. }
  2301. }
  2302. {
  2303. var awaiter = task8.GetAwaiter();
  2304. if (awaiter.IsCompleted)
  2305. {
  2306. TryInvokeContinuationT8(this, awaiter);
  2307. }
  2308. else
  2309. {
  2310. awaiter.SourceOnCompleted(state =>
  2311. {
  2312. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T8>.Awaiter>)state)
  2313. {
  2314. TryInvokeContinuationT8(t.Item1, t.Item2);
  2315. }
  2316. }, StateTuple.Create(this, awaiter));
  2317. }
  2318. }
  2319. {
  2320. var awaiter = task9.GetAwaiter();
  2321. if (awaiter.IsCompleted)
  2322. {
  2323. TryInvokeContinuationT9(this, awaiter);
  2324. }
  2325. else
  2326. {
  2327. awaiter.SourceOnCompleted(state =>
  2328. {
  2329. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T9>.Awaiter>)state)
  2330. {
  2331. TryInvokeContinuationT9(t.Item1, t.Item2);
  2332. }
  2333. }, StateTuple.Create(this, awaiter));
  2334. }
  2335. }
  2336. {
  2337. var awaiter = task10.GetAwaiter();
  2338. if (awaiter.IsCompleted)
  2339. {
  2340. TryInvokeContinuationT10(this, awaiter);
  2341. }
  2342. else
  2343. {
  2344. awaiter.SourceOnCompleted(state =>
  2345. {
  2346. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T10>.Awaiter>)state)
  2347. {
  2348. TryInvokeContinuationT10(t.Item1, t.Item2);
  2349. }
  2350. }, StateTuple.Create(this, awaiter));
  2351. }
  2352. }
  2353. {
  2354. var awaiter = task11.GetAwaiter();
  2355. if (awaiter.IsCompleted)
  2356. {
  2357. TryInvokeContinuationT11(this, awaiter);
  2358. }
  2359. else
  2360. {
  2361. awaiter.SourceOnCompleted(state =>
  2362. {
  2363. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, UniTask<T11>.Awaiter>)state)
  2364. {
  2365. TryInvokeContinuationT11(t.Item1, t.Item2);
  2366. }
  2367. }, StateTuple.Create(this, awaiter));
  2368. }
  2369. }
  2370. }
  2371. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T1>.Awaiter awaiter)
  2372. {
  2373. T1 result;
  2374. try
  2375. {
  2376. result = awaiter.GetResult();
  2377. }
  2378. catch (Exception ex)
  2379. {
  2380. self.core.TrySetException(ex);
  2381. return;
  2382. }
  2383. if (Interlocked.Increment(ref self.completedCount) == 1)
  2384. {
  2385. self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default));
  2386. }
  2387. }
  2388. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T2>.Awaiter awaiter)
  2389. {
  2390. T2 result;
  2391. try
  2392. {
  2393. result = awaiter.GetResult();
  2394. }
  2395. catch (Exception ex)
  2396. {
  2397. self.core.TrySetException(ex);
  2398. return;
  2399. }
  2400. if (Interlocked.Increment(ref self.completedCount) == 1)
  2401. {
  2402. self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default));
  2403. }
  2404. }
  2405. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T3>.Awaiter awaiter)
  2406. {
  2407. T3 result;
  2408. try
  2409. {
  2410. result = awaiter.GetResult();
  2411. }
  2412. catch (Exception ex)
  2413. {
  2414. self.core.TrySetException(ex);
  2415. return;
  2416. }
  2417. if (Interlocked.Increment(ref self.completedCount) == 1)
  2418. {
  2419. self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default));
  2420. }
  2421. }
  2422. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T4>.Awaiter awaiter)
  2423. {
  2424. T4 result;
  2425. try
  2426. {
  2427. result = awaiter.GetResult();
  2428. }
  2429. catch (Exception ex)
  2430. {
  2431. self.core.TrySetException(ex);
  2432. return;
  2433. }
  2434. if (Interlocked.Increment(ref self.completedCount) == 1)
  2435. {
  2436. self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default));
  2437. }
  2438. }
  2439. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T5>.Awaiter awaiter)
  2440. {
  2441. T5 result;
  2442. try
  2443. {
  2444. result = awaiter.GetResult();
  2445. }
  2446. catch (Exception ex)
  2447. {
  2448. self.core.TrySetException(ex);
  2449. return;
  2450. }
  2451. if (Interlocked.Increment(ref self.completedCount) == 1)
  2452. {
  2453. self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default));
  2454. }
  2455. }
  2456. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T6>.Awaiter awaiter)
  2457. {
  2458. T6 result;
  2459. try
  2460. {
  2461. result = awaiter.GetResult();
  2462. }
  2463. catch (Exception ex)
  2464. {
  2465. self.core.TrySetException(ex);
  2466. return;
  2467. }
  2468. if (Interlocked.Increment(ref self.completedCount) == 1)
  2469. {
  2470. self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default));
  2471. }
  2472. }
  2473. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T7>.Awaiter awaiter)
  2474. {
  2475. T7 result;
  2476. try
  2477. {
  2478. result = awaiter.GetResult();
  2479. }
  2480. catch (Exception ex)
  2481. {
  2482. self.core.TrySetException(ex);
  2483. return;
  2484. }
  2485. if (Interlocked.Increment(ref self.completedCount) == 1)
  2486. {
  2487. self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default));
  2488. }
  2489. }
  2490. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T8>.Awaiter awaiter)
  2491. {
  2492. T8 result;
  2493. try
  2494. {
  2495. result = awaiter.GetResult();
  2496. }
  2497. catch (Exception ex)
  2498. {
  2499. self.core.TrySetException(ex);
  2500. return;
  2501. }
  2502. if (Interlocked.Increment(ref self.completedCount) == 1)
  2503. {
  2504. self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default));
  2505. }
  2506. }
  2507. static void TryInvokeContinuationT9(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T9>.Awaiter awaiter)
  2508. {
  2509. T9 result;
  2510. try
  2511. {
  2512. result = awaiter.GetResult();
  2513. }
  2514. catch (Exception ex)
  2515. {
  2516. self.core.TrySetException(ex);
  2517. return;
  2518. }
  2519. if (Interlocked.Increment(ref self.completedCount) == 1)
  2520. {
  2521. self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default));
  2522. }
  2523. }
  2524. static void TryInvokeContinuationT10(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T10>.Awaiter awaiter)
  2525. {
  2526. T10 result;
  2527. try
  2528. {
  2529. result = awaiter.GetResult();
  2530. }
  2531. catch (Exception ex)
  2532. {
  2533. self.core.TrySetException(ex);
  2534. return;
  2535. }
  2536. if (Interlocked.Increment(ref self.completedCount) == 1)
  2537. {
  2538. self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default));
  2539. }
  2540. }
  2541. static void TryInvokeContinuationT11(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> self, in UniTask<T11>.Awaiter awaiter)
  2542. {
  2543. T11 result;
  2544. try
  2545. {
  2546. result = awaiter.GetResult();
  2547. }
  2548. catch (Exception ex)
  2549. {
  2550. self.core.TrySetException(ex);
  2551. return;
  2552. }
  2553. if (Interlocked.Increment(ref self.completedCount) == 1)
  2554. {
  2555. self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result));
  2556. }
  2557. }
  2558. 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)
  2559. {
  2560. TaskTracker.RemoveTracking(this);
  2561. GC.SuppressFinalize(this);
  2562. return core.GetResult(token);
  2563. }
  2564. public UniTaskStatus GetStatus(short token)
  2565. {
  2566. return core.GetStatus(token);
  2567. }
  2568. public void OnCompleted(Action<object> continuation, object state, short token)
  2569. {
  2570. core.OnCompleted(continuation, state, token);
  2571. }
  2572. public UniTaskStatus UnsafeGetStatus()
  2573. {
  2574. return core.UnsafeGetStatus();
  2575. }
  2576. void IUniTaskSource.GetResult(short token)
  2577. {
  2578. GetResult(token);
  2579. }
  2580. }
  2581. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12)
  2582. {
  2583. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12), 0);
  2584. }
  2585. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> : 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)>
  2586. {
  2587. int completedCount;
  2588. 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;
  2589. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12)
  2590. {
  2591. TaskTracker.TrackActiveTask(this, 3);
  2592. this.completedCount = 0;
  2593. {
  2594. var awaiter = task1.GetAwaiter();
  2595. if (awaiter.IsCompleted)
  2596. {
  2597. TryInvokeContinuationT1(this, awaiter);
  2598. }
  2599. else
  2600. {
  2601. awaiter.SourceOnCompleted(state =>
  2602. {
  2603. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T1>.Awaiter>)state)
  2604. {
  2605. TryInvokeContinuationT1(t.Item1, t.Item2);
  2606. }
  2607. }, StateTuple.Create(this, awaiter));
  2608. }
  2609. }
  2610. {
  2611. var awaiter = task2.GetAwaiter();
  2612. if (awaiter.IsCompleted)
  2613. {
  2614. TryInvokeContinuationT2(this, awaiter);
  2615. }
  2616. else
  2617. {
  2618. awaiter.SourceOnCompleted(state =>
  2619. {
  2620. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T2>.Awaiter>)state)
  2621. {
  2622. TryInvokeContinuationT2(t.Item1, t.Item2);
  2623. }
  2624. }, StateTuple.Create(this, awaiter));
  2625. }
  2626. }
  2627. {
  2628. var awaiter = task3.GetAwaiter();
  2629. if (awaiter.IsCompleted)
  2630. {
  2631. TryInvokeContinuationT3(this, awaiter);
  2632. }
  2633. else
  2634. {
  2635. awaiter.SourceOnCompleted(state =>
  2636. {
  2637. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T3>.Awaiter>)state)
  2638. {
  2639. TryInvokeContinuationT3(t.Item1, t.Item2);
  2640. }
  2641. }, StateTuple.Create(this, awaiter));
  2642. }
  2643. }
  2644. {
  2645. var awaiter = task4.GetAwaiter();
  2646. if (awaiter.IsCompleted)
  2647. {
  2648. TryInvokeContinuationT4(this, awaiter);
  2649. }
  2650. else
  2651. {
  2652. awaiter.SourceOnCompleted(state =>
  2653. {
  2654. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T4>.Awaiter>)state)
  2655. {
  2656. TryInvokeContinuationT4(t.Item1, t.Item2);
  2657. }
  2658. }, StateTuple.Create(this, awaiter));
  2659. }
  2660. }
  2661. {
  2662. var awaiter = task5.GetAwaiter();
  2663. if (awaiter.IsCompleted)
  2664. {
  2665. TryInvokeContinuationT5(this, awaiter);
  2666. }
  2667. else
  2668. {
  2669. awaiter.SourceOnCompleted(state =>
  2670. {
  2671. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T5>.Awaiter>)state)
  2672. {
  2673. TryInvokeContinuationT5(t.Item1, t.Item2);
  2674. }
  2675. }, StateTuple.Create(this, awaiter));
  2676. }
  2677. }
  2678. {
  2679. var awaiter = task6.GetAwaiter();
  2680. if (awaiter.IsCompleted)
  2681. {
  2682. TryInvokeContinuationT6(this, awaiter);
  2683. }
  2684. else
  2685. {
  2686. awaiter.SourceOnCompleted(state =>
  2687. {
  2688. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T6>.Awaiter>)state)
  2689. {
  2690. TryInvokeContinuationT6(t.Item1, t.Item2);
  2691. }
  2692. }, StateTuple.Create(this, awaiter));
  2693. }
  2694. }
  2695. {
  2696. var awaiter = task7.GetAwaiter();
  2697. if (awaiter.IsCompleted)
  2698. {
  2699. TryInvokeContinuationT7(this, awaiter);
  2700. }
  2701. else
  2702. {
  2703. awaiter.SourceOnCompleted(state =>
  2704. {
  2705. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T7>.Awaiter>)state)
  2706. {
  2707. TryInvokeContinuationT7(t.Item1, t.Item2);
  2708. }
  2709. }, StateTuple.Create(this, awaiter));
  2710. }
  2711. }
  2712. {
  2713. var awaiter = task8.GetAwaiter();
  2714. if (awaiter.IsCompleted)
  2715. {
  2716. TryInvokeContinuationT8(this, awaiter);
  2717. }
  2718. else
  2719. {
  2720. awaiter.SourceOnCompleted(state =>
  2721. {
  2722. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T8>.Awaiter>)state)
  2723. {
  2724. TryInvokeContinuationT8(t.Item1, t.Item2);
  2725. }
  2726. }, StateTuple.Create(this, awaiter));
  2727. }
  2728. }
  2729. {
  2730. var awaiter = task9.GetAwaiter();
  2731. if (awaiter.IsCompleted)
  2732. {
  2733. TryInvokeContinuationT9(this, awaiter);
  2734. }
  2735. else
  2736. {
  2737. awaiter.SourceOnCompleted(state =>
  2738. {
  2739. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T9>.Awaiter>)state)
  2740. {
  2741. TryInvokeContinuationT9(t.Item1, t.Item2);
  2742. }
  2743. }, StateTuple.Create(this, awaiter));
  2744. }
  2745. }
  2746. {
  2747. var awaiter = task10.GetAwaiter();
  2748. if (awaiter.IsCompleted)
  2749. {
  2750. TryInvokeContinuationT10(this, awaiter);
  2751. }
  2752. else
  2753. {
  2754. awaiter.SourceOnCompleted(state =>
  2755. {
  2756. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T10>.Awaiter>)state)
  2757. {
  2758. TryInvokeContinuationT10(t.Item1, t.Item2);
  2759. }
  2760. }, StateTuple.Create(this, awaiter));
  2761. }
  2762. }
  2763. {
  2764. var awaiter = task11.GetAwaiter();
  2765. if (awaiter.IsCompleted)
  2766. {
  2767. TryInvokeContinuationT11(this, awaiter);
  2768. }
  2769. else
  2770. {
  2771. awaiter.SourceOnCompleted(state =>
  2772. {
  2773. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T11>.Awaiter>)state)
  2774. {
  2775. TryInvokeContinuationT11(t.Item1, t.Item2);
  2776. }
  2777. }, StateTuple.Create(this, awaiter));
  2778. }
  2779. }
  2780. {
  2781. var awaiter = task12.GetAwaiter();
  2782. if (awaiter.IsCompleted)
  2783. {
  2784. TryInvokeContinuationT12(this, awaiter);
  2785. }
  2786. else
  2787. {
  2788. awaiter.SourceOnCompleted(state =>
  2789. {
  2790. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, UniTask<T12>.Awaiter>)state)
  2791. {
  2792. TryInvokeContinuationT12(t.Item1, t.Item2);
  2793. }
  2794. }, StateTuple.Create(this, awaiter));
  2795. }
  2796. }
  2797. }
  2798. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T1>.Awaiter awaiter)
  2799. {
  2800. T1 result;
  2801. try
  2802. {
  2803. result = awaiter.GetResult();
  2804. }
  2805. catch (Exception ex)
  2806. {
  2807. self.core.TrySetException(ex);
  2808. return;
  2809. }
  2810. if (Interlocked.Increment(ref self.completedCount) == 1)
  2811. {
  2812. self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default));
  2813. }
  2814. }
  2815. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T2>.Awaiter awaiter)
  2816. {
  2817. T2 result;
  2818. try
  2819. {
  2820. result = awaiter.GetResult();
  2821. }
  2822. catch (Exception ex)
  2823. {
  2824. self.core.TrySetException(ex);
  2825. return;
  2826. }
  2827. if (Interlocked.Increment(ref self.completedCount) == 1)
  2828. {
  2829. self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default));
  2830. }
  2831. }
  2832. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T3>.Awaiter awaiter)
  2833. {
  2834. T3 result;
  2835. try
  2836. {
  2837. result = awaiter.GetResult();
  2838. }
  2839. catch (Exception ex)
  2840. {
  2841. self.core.TrySetException(ex);
  2842. return;
  2843. }
  2844. if (Interlocked.Increment(ref self.completedCount) == 1)
  2845. {
  2846. self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default));
  2847. }
  2848. }
  2849. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T4>.Awaiter awaiter)
  2850. {
  2851. T4 result;
  2852. try
  2853. {
  2854. result = awaiter.GetResult();
  2855. }
  2856. catch (Exception ex)
  2857. {
  2858. self.core.TrySetException(ex);
  2859. return;
  2860. }
  2861. if (Interlocked.Increment(ref self.completedCount) == 1)
  2862. {
  2863. self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default));
  2864. }
  2865. }
  2866. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T5>.Awaiter awaiter)
  2867. {
  2868. T5 result;
  2869. try
  2870. {
  2871. result = awaiter.GetResult();
  2872. }
  2873. catch (Exception ex)
  2874. {
  2875. self.core.TrySetException(ex);
  2876. return;
  2877. }
  2878. if (Interlocked.Increment(ref self.completedCount) == 1)
  2879. {
  2880. self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default));
  2881. }
  2882. }
  2883. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T6>.Awaiter awaiter)
  2884. {
  2885. T6 result;
  2886. try
  2887. {
  2888. result = awaiter.GetResult();
  2889. }
  2890. catch (Exception ex)
  2891. {
  2892. self.core.TrySetException(ex);
  2893. return;
  2894. }
  2895. if (Interlocked.Increment(ref self.completedCount) == 1)
  2896. {
  2897. self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default));
  2898. }
  2899. }
  2900. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T7>.Awaiter awaiter)
  2901. {
  2902. T7 result;
  2903. try
  2904. {
  2905. result = awaiter.GetResult();
  2906. }
  2907. catch (Exception ex)
  2908. {
  2909. self.core.TrySetException(ex);
  2910. return;
  2911. }
  2912. if (Interlocked.Increment(ref self.completedCount) == 1)
  2913. {
  2914. self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default));
  2915. }
  2916. }
  2917. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T8>.Awaiter awaiter)
  2918. {
  2919. T8 result;
  2920. try
  2921. {
  2922. result = awaiter.GetResult();
  2923. }
  2924. catch (Exception ex)
  2925. {
  2926. self.core.TrySetException(ex);
  2927. return;
  2928. }
  2929. if (Interlocked.Increment(ref self.completedCount) == 1)
  2930. {
  2931. self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default));
  2932. }
  2933. }
  2934. static void TryInvokeContinuationT9(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T9>.Awaiter awaiter)
  2935. {
  2936. T9 result;
  2937. try
  2938. {
  2939. result = awaiter.GetResult();
  2940. }
  2941. catch (Exception ex)
  2942. {
  2943. self.core.TrySetException(ex);
  2944. return;
  2945. }
  2946. if (Interlocked.Increment(ref self.completedCount) == 1)
  2947. {
  2948. self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default));
  2949. }
  2950. }
  2951. static void TryInvokeContinuationT10(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T10>.Awaiter awaiter)
  2952. {
  2953. T10 result;
  2954. try
  2955. {
  2956. result = awaiter.GetResult();
  2957. }
  2958. catch (Exception ex)
  2959. {
  2960. self.core.TrySetException(ex);
  2961. return;
  2962. }
  2963. if (Interlocked.Increment(ref self.completedCount) == 1)
  2964. {
  2965. self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default));
  2966. }
  2967. }
  2968. static void TryInvokeContinuationT11(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T11>.Awaiter awaiter)
  2969. {
  2970. T11 result;
  2971. try
  2972. {
  2973. result = awaiter.GetResult();
  2974. }
  2975. catch (Exception ex)
  2976. {
  2977. self.core.TrySetException(ex);
  2978. return;
  2979. }
  2980. if (Interlocked.Increment(ref self.completedCount) == 1)
  2981. {
  2982. self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default));
  2983. }
  2984. }
  2985. static void TryInvokeContinuationT12(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> self, in UniTask<T12>.Awaiter awaiter)
  2986. {
  2987. T12 result;
  2988. try
  2989. {
  2990. result = awaiter.GetResult();
  2991. }
  2992. catch (Exception ex)
  2993. {
  2994. self.core.TrySetException(ex);
  2995. return;
  2996. }
  2997. if (Interlocked.Increment(ref self.completedCount) == 1)
  2998. {
  2999. self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result));
  3000. }
  3001. }
  3002. 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)
  3003. {
  3004. TaskTracker.RemoveTracking(this);
  3005. GC.SuppressFinalize(this);
  3006. return core.GetResult(token);
  3007. }
  3008. public UniTaskStatus GetStatus(short token)
  3009. {
  3010. return core.GetStatus(token);
  3011. }
  3012. public void OnCompleted(Action<object> continuation, object state, short token)
  3013. {
  3014. core.OnCompleted(continuation, state, token);
  3015. }
  3016. public UniTaskStatus UnsafeGetStatus()
  3017. {
  3018. return core.UnsafeGetStatus();
  3019. }
  3020. void IUniTaskSource.GetResult(short token)
  3021. {
  3022. GetResult(token);
  3023. }
  3024. }
  3025. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12, UniTask<T13> task13)
  3026. {
  3027. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13), 0);
  3028. }
  3029. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> : 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)>
  3030. {
  3031. int completedCount;
  3032. 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;
  3033. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12, UniTask<T13> task13)
  3034. {
  3035. TaskTracker.TrackActiveTask(this, 3);
  3036. this.completedCount = 0;
  3037. {
  3038. var awaiter = task1.GetAwaiter();
  3039. if (awaiter.IsCompleted)
  3040. {
  3041. TryInvokeContinuationT1(this, awaiter);
  3042. }
  3043. else
  3044. {
  3045. awaiter.SourceOnCompleted(state =>
  3046. {
  3047. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T1>.Awaiter>)state)
  3048. {
  3049. TryInvokeContinuationT1(t.Item1, t.Item2);
  3050. }
  3051. }, StateTuple.Create(this, awaiter));
  3052. }
  3053. }
  3054. {
  3055. var awaiter = task2.GetAwaiter();
  3056. if (awaiter.IsCompleted)
  3057. {
  3058. TryInvokeContinuationT2(this, awaiter);
  3059. }
  3060. else
  3061. {
  3062. awaiter.SourceOnCompleted(state =>
  3063. {
  3064. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T2>.Awaiter>)state)
  3065. {
  3066. TryInvokeContinuationT2(t.Item1, t.Item2);
  3067. }
  3068. }, StateTuple.Create(this, awaiter));
  3069. }
  3070. }
  3071. {
  3072. var awaiter = task3.GetAwaiter();
  3073. if (awaiter.IsCompleted)
  3074. {
  3075. TryInvokeContinuationT3(this, awaiter);
  3076. }
  3077. else
  3078. {
  3079. awaiter.SourceOnCompleted(state =>
  3080. {
  3081. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T3>.Awaiter>)state)
  3082. {
  3083. TryInvokeContinuationT3(t.Item1, t.Item2);
  3084. }
  3085. }, StateTuple.Create(this, awaiter));
  3086. }
  3087. }
  3088. {
  3089. var awaiter = task4.GetAwaiter();
  3090. if (awaiter.IsCompleted)
  3091. {
  3092. TryInvokeContinuationT4(this, awaiter);
  3093. }
  3094. else
  3095. {
  3096. awaiter.SourceOnCompleted(state =>
  3097. {
  3098. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T4>.Awaiter>)state)
  3099. {
  3100. TryInvokeContinuationT4(t.Item1, t.Item2);
  3101. }
  3102. }, StateTuple.Create(this, awaiter));
  3103. }
  3104. }
  3105. {
  3106. var awaiter = task5.GetAwaiter();
  3107. if (awaiter.IsCompleted)
  3108. {
  3109. TryInvokeContinuationT5(this, awaiter);
  3110. }
  3111. else
  3112. {
  3113. awaiter.SourceOnCompleted(state =>
  3114. {
  3115. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T5>.Awaiter>)state)
  3116. {
  3117. TryInvokeContinuationT5(t.Item1, t.Item2);
  3118. }
  3119. }, StateTuple.Create(this, awaiter));
  3120. }
  3121. }
  3122. {
  3123. var awaiter = task6.GetAwaiter();
  3124. if (awaiter.IsCompleted)
  3125. {
  3126. TryInvokeContinuationT6(this, awaiter);
  3127. }
  3128. else
  3129. {
  3130. awaiter.SourceOnCompleted(state =>
  3131. {
  3132. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T6>.Awaiter>)state)
  3133. {
  3134. TryInvokeContinuationT6(t.Item1, t.Item2);
  3135. }
  3136. }, StateTuple.Create(this, awaiter));
  3137. }
  3138. }
  3139. {
  3140. var awaiter = task7.GetAwaiter();
  3141. if (awaiter.IsCompleted)
  3142. {
  3143. TryInvokeContinuationT7(this, awaiter);
  3144. }
  3145. else
  3146. {
  3147. awaiter.SourceOnCompleted(state =>
  3148. {
  3149. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T7>.Awaiter>)state)
  3150. {
  3151. TryInvokeContinuationT7(t.Item1, t.Item2);
  3152. }
  3153. }, StateTuple.Create(this, awaiter));
  3154. }
  3155. }
  3156. {
  3157. var awaiter = task8.GetAwaiter();
  3158. if (awaiter.IsCompleted)
  3159. {
  3160. TryInvokeContinuationT8(this, awaiter);
  3161. }
  3162. else
  3163. {
  3164. awaiter.SourceOnCompleted(state =>
  3165. {
  3166. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T8>.Awaiter>)state)
  3167. {
  3168. TryInvokeContinuationT8(t.Item1, t.Item2);
  3169. }
  3170. }, StateTuple.Create(this, awaiter));
  3171. }
  3172. }
  3173. {
  3174. var awaiter = task9.GetAwaiter();
  3175. if (awaiter.IsCompleted)
  3176. {
  3177. TryInvokeContinuationT9(this, awaiter);
  3178. }
  3179. else
  3180. {
  3181. awaiter.SourceOnCompleted(state =>
  3182. {
  3183. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T9>.Awaiter>)state)
  3184. {
  3185. TryInvokeContinuationT9(t.Item1, t.Item2);
  3186. }
  3187. }, StateTuple.Create(this, awaiter));
  3188. }
  3189. }
  3190. {
  3191. var awaiter = task10.GetAwaiter();
  3192. if (awaiter.IsCompleted)
  3193. {
  3194. TryInvokeContinuationT10(this, awaiter);
  3195. }
  3196. else
  3197. {
  3198. awaiter.SourceOnCompleted(state =>
  3199. {
  3200. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T10>.Awaiter>)state)
  3201. {
  3202. TryInvokeContinuationT10(t.Item1, t.Item2);
  3203. }
  3204. }, StateTuple.Create(this, awaiter));
  3205. }
  3206. }
  3207. {
  3208. var awaiter = task11.GetAwaiter();
  3209. if (awaiter.IsCompleted)
  3210. {
  3211. TryInvokeContinuationT11(this, awaiter);
  3212. }
  3213. else
  3214. {
  3215. awaiter.SourceOnCompleted(state =>
  3216. {
  3217. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T11>.Awaiter>)state)
  3218. {
  3219. TryInvokeContinuationT11(t.Item1, t.Item2);
  3220. }
  3221. }, StateTuple.Create(this, awaiter));
  3222. }
  3223. }
  3224. {
  3225. var awaiter = task12.GetAwaiter();
  3226. if (awaiter.IsCompleted)
  3227. {
  3228. TryInvokeContinuationT12(this, awaiter);
  3229. }
  3230. else
  3231. {
  3232. awaiter.SourceOnCompleted(state =>
  3233. {
  3234. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T12>.Awaiter>)state)
  3235. {
  3236. TryInvokeContinuationT12(t.Item1, t.Item2);
  3237. }
  3238. }, StateTuple.Create(this, awaiter));
  3239. }
  3240. }
  3241. {
  3242. var awaiter = task13.GetAwaiter();
  3243. if (awaiter.IsCompleted)
  3244. {
  3245. TryInvokeContinuationT13(this, awaiter);
  3246. }
  3247. else
  3248. {
  3249. awaiter.SourceOnCompleted(state =>
  3250. {
  3251. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, UniTask<T13>.Awaiter>)state)
  3252. {
  3253. TryInvokeContinuationT13(t.Item1, t.Item2);
  3254. }
  3255. }, StateTuple.Create(this, awaiter));
  3256. }
  3257. }
  3258. }
  3259. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T1>.Awaiter awaiter)
  3260. {
  3261. T1 result;
  3262. try
  3263. {
  3264. result = awaiter.GetResult();
  3265. }
  3266. catch (Exception ex)
  3267. {
  3268. self.core.TrySetException(ex);
  3269. return;
  3270. }
  3271. if (Interlocked.Increment(ref self.completedCount) == 1)
  3272. {
  3273. self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default, default));
  3274. }
  3275. }
  3276. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T2>.Awaiter awaiter)
  3277. {
  3278. T2 result;
  3279. try
  3280. {
  3281. result = awaiter.GetResult();
  3282. }
  3283. catch (Exception ex)
  3284. {
  3285. self.core.TrySetException(ex);
  3286. return;
  3287. }
  3288. if (Interlocked.Increment(ref self.completedCount) == 1)
  3289. {
  3290. self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default, default));
  3291. }
  3292. }
  3293. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T3>.Awaiter awaiter)
  3294. {
  3295. T3 result;
  3296. try
  3297. {
  3298. result = awaiter.GetResult();
  3299. }
  3300. catch (Exception ex)
  3301. {
  3302. self.core.TrySetException(ex);
  3303. return;
  3304. }
  3305. if (Interlocked.Increment(ref self.completedCount) == 1)
  3306. {
  3307. self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default, default));
  3308. }
  3309. }
  3310. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T4>.Awaiter awaiter)
  3311. {
  3312. T4 result;
  3313. try
  3314. {
  3315. result = awaiter.GetResult();
  3316. }
  3317. catch (Exception ex)
  3318. {
  3319. self.core.TrySetException(ex);
  3320. return;
  3321. }
  3322. if (Interlocked.Increment(ref self.completedCount) == 1)
  3323. {
  3324. self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default, default));
  3325. }
  3326. }
  3327. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T5>.Awaiter awaiter)
  3328. {
  3329. T5 result;
  3330. try
  3331. {
  3332. result = awaiter.GetResult();
  3333. }
  3334. catch (Exception ex)
  3335. {
  3336. self.core.TrySetException(ex);
  3337. return;
  3338. }
  3339. if (Interlocked.Increment(ref self.completedCount) == 1)
  3340. {
  3341. self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default, default));
  3342. }
  3343. }
  3344. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T6>.Awaiter awaiter)
  3345. {
  3346. T6 result;
  3347. try
  3348. {
  3349. result = awaiter.GetResult();
  3350. }
  3351. catch (Exception ex)
  3352. {
  3353. self.core.TrySetException(ex);
  3354. return;
  3355. }
  3356. if (Interlocked.Increment(ref self.completedCount) == 1)
  3357. {
  3358. self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default, default));
  3359. }
  3360. }
  3361. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T7>.Awaiter awaiter)
  3362. {
  3363. T7 result;
  3364. try
  3365. {
  3366. result = awaiter.GetResult();
  3367. }
  3368. catch (Exception ex)
  3369. {
  3370. self.core.TrySetException(ex);
  3371. return;
  3372. }
  3373. if (Interlocked.Increment(ref self.completedCount) == 1)
  3374. {
  3375. self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default, default));
  3376. }
  3377. }
  3378. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T8>.Awaiter awaiter)
  3379. {
  3380. T8 result;
  3381. try
  3382. {
  3383. result = awaiter.GetResult();
  3384. }
  3385. catch (Exception ex)
  3386. {
  3387. self.core.TrySetException(ex);
  3388. return;
  3389. }
  3390. if (Interlocked.Increment(ref self.completedCount) == 1)
  3391. {
  3392. self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default, default));
  3393. }
  3394. }
  3395. static void TryInvokeContinuationT9(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T9>.Awaiter awaiter)
  3396. {
  3397. T9 result;
  3398. try
  3399. {
  3400. result = awaiter.GetResult();
  3401. }
  3402. catch (Exception ex)
  3403. {
  3404. self.core.TrySetException(ex);
  3405. return;
  3406. }
  3407. if (Interlocked.Increment(ref self.completedCount) == 1)
  3408. {
  3409. self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default, default));
  3410. }
  3411. }
  3412. static void TryInvokeContinuationT10(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T10>.Awaiter awaiter)
  3413. {
  3414. T10 result;
  3415. try
  3416. {
  3417. result = awaiter.GetResult();
  3418. }
  3419. catch (Exception ex)
  3420. {
  3421. self.core.TrySetException(ex);
  3422. return;
  3423. }
  3424. if (Interlocked.Increment(ref self.completedCount) == 1)
  3425. {
  3426. self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default, default));
  3427. }
  3428. }
  3429. static void TryInvokeContinuationT11(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T11>.Awaiter awaiter)
  3430. {
  3431. T11 result;
  3432. try
  3433. {
  3434. result = awaiter.GetResult();
  3435. }
  3436. catch (Exception ex)
  3437. {
  3438. self.core.TrySetException(ex);
  3439. return;
  3440. }
  3441. if (Interlocked.Increment(ref self.completedCount) == 1)
  3442. {
  3443. self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default, default));
  3444. }
  3445. }
  3446. static void TryInvokeContinuationT12(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T12>.Awaiter awaiter)
  3447. {
  3448. T12 result;
  3449. try
  3450. {
  3451. result = awaiter.GetResult();
  3452. }
  3453. catch (Exception ex)
  3454. {
  3455. self.core.TrySetException(ex);
  3456. return;
  3457. }
  3458. if (Interlocked.Increment(ref self.completedCount) == 1)
  3459. {
  3460. self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result, default));
  3461. }
  3462. }
  3463. static void TryInvokeContinuationT13(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> self, in UniTask<T13>.Awaiter awaiter)
  3464. {
  3465. T13 result;
  3466. try
  3467. {
  3468. result = awaiter.GetResult();
  3469. }
  3470. catch (Exception ex)
  3471. {
  3472. self.core.TrySetException(ex);
  3473. return;
  3474. }
  3475. if (Interlocked.Increment(ref self.completedCount) == 1)
  3476. {
  3477. self.core.TrySetResult((12, default, default, default, default, default, default, default, default, default, default, default, default, result));
  3478. }
  3479. }
  3480. 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)
  3481. {
  3482. TaskTracker.RemoveTracking(this);
  3483. GC.SuppressFinalize(this);
  3484. return core.GetResult(token);
  3485. }
  3486. public UniTaskStatus GetStatus(short token)
  3487. {
  3488. return core.GetStatus(token);
  3489. }
  3490. public void OnCompleted(Action<object> continuation, object state, short token)
  3491. {
  3492. core.OnCompleted(continuation, state, token);
  3493. }
  3494. public UniTaskStatus UnsafeGetStatus()
  3495. {
  3496. return core.UnsafeGetStatus();
  3497. }
  3498. void IUniTaskSource.GetResult(short token)
  3499. {
  3500. GetResult(token);
  3501. }
  3502. }
  3503. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12, UniTask<T13> task13, UniTask<T14> task14)
  3504. {
  3505. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14), 0);
  3506. }
  3507. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> : 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)>
  3508. {
  3509. int completedCount;
  3510. 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;
  3511. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12, UniTask<T13> task13, UniTask<T14> task14)
  3512. {
  3513. TaskTracker.TrackActiveTask(this, 3);
  3514. this.completedCount = 0;
  3515. {
  3516. var awaiter = task1.GetAwaiter();
  3517. if (awaiter.IsCompleted)
  3518. {
  3519. TryInvokeContinuationT1(this, awaiter);
  3520. }
  3521. else
  3522. {
  3523. awaiter.SourceOnCompleted(state =>
  3524. {
  3525. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T1>.Awaiter>)state)
  3526. {
  3527. TryInvokeContinuationT1(t.Item1, t.Item2);
  3528. }
  3529. }, StateTuple.Create(this, awaiter));
  3530. }
  3531. }
  3532. {
  3533. var awaiter = task2.GetAwaiter();
  3534. if (awaiter.IsCompleted)
  3535. {
  3536. TryInvokeContinuationT2(this, awaiter);
  3537. }
  3538. else
  3539. {
  3540. awaiter.SourceOnCompleted(state =>
  3541. {
  3542. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T2>.Awaiter>)state)
  3543. {
  3544. TryInvokeContinuationT2(t.Item1, t.Item2);
  3545. }
  3546. }, StateTuple.Create(this, awaiter));
  3547. }
  3548. }
  3549. {
  3550. var awaiter = task3.GetAwaiter();
  3551. if (awaiter.IsCompleted)
  3552. {
  3553. TryInvokeContinuationT3(this, awaiter);
  3554. }
  3555. else
  3556. {
  3557. awaiter.SourceOnCompleted(state =>
  3558. {
  3559. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T3>.Awaiter>)state)
  3560. {
  3561. TryInvokeContinuationT3(t.Item1, t.Item2);
  3562. }
  3563. }, StateTuple.Create(this, awaiter));
  3564. }
  3565. }
  3566. {
  3567. var awaiter = task4.GetAwaiter();
  3568. if (awaiter.IsCompleted)
  3569. {
  3570. TryInvokeContinuationT4(this, awaiter);
  3571. }
  3572. else
  3573. {
  3574. awaiter.SourceOnCompleted(state =>
  3575. {
  3576. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T4>.Awaiter>)state)
  3577. {
  3578. TryInvokeContinuationT4(t.Item1, t.Item2);
  3579. }
  3580. }, StateTuple.Create(this, awaiter));
  3581. }
  3582. }
  3583. {
  3584. var awaiter = task5.GetAwaiter();
  3585. if (awaiter.IsCompleted)
  3586. {
  3587. TryInvokeContinuationT5(this, awaiter);
  3588. }
  3589. else
  3590. {
  3591. awaiter.SourceOnCompleted(state =>
  3592. {
  3593. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T5>.Awaiter>)state)
  3594. {
  3595. TryInvokeContinuationT5(t.Item1, t.Item2);
  3596. }
  3597. }, StateTuple.Create(this, awaiter));
  3598. }
  3599. }
  3600. {
  3601. var awaiter = task6.GetAwaiter();
  3602. if (awaiter.IsCompleted)
  3603. {
  3604. TryInvokeContinuationT6(this, awaiter);
  3605. }
  3606. else
  3607. {
  3608. awaiter.SourceOnCompleted(state =>
  3609. {
  3610. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T6>.Awaiter>)state)
  3611. {
  3612. TryInvokeContinuationT6(t.Item1, t.Item2);
  3613. }
  3614. }, StateTuple.Create(this, awaiter));
  3615. }
  3616. }
  3617. {
  3618. var awaiter = task7.GetAwaiter();
  3619. if (awaiter.IsCompleted)
  3620. {
  3621. TryInvokeContinuationT7(this, awaiter);
  3622. }
  3623. else
  3624. {
  3625. awaiter.SourceOnCompleted(state =>
  3626. {
  3627. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T7>.Awaiter>)state)
  3628. {
  3629. TryInvokeContinuationT7(t.Item1, t.Item2);
  3630. }
  3631. }, StateTuple.Create(this, awaiter));
  3632. }
  3633. }
  3634. {
  3635. var awaiter = task8.GetAwaiter();
  3636. if (awaiter.IsCompleted)
  3637. {
  3638. TryInvokeContinuationT8(this, awaiter);
  3639. }
  3640. else
  3641. {
  3642. awaiter.SourceOnCompleted(state =>
  3643. {
  3644. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T8>.Awaiter>)state)
  3645. {
  3646. TryInvokeContinuationT8(t.Item1, t.Item2);
  3647. }
  3648. }, StateTuple.Create(this, awaiter));
  3649. }
  3650. }
  3651. {
  3652. var awaiter = task9.GetAwaiter();
  3653. if (awaiter.IsCompleted)
  3654. {
  3655. TryInvokeContinuationT9(this, awaiter);
  3656. }
  3657. else
  3658. {
  3659. awaiter.SourceOnCompleted(state =>
  3660. {
  3661. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T9>.Awaiter>)state)
  3662. {
  3663. TryInvokeContinuationT9(t.Item1, t.Item2);
  3664. }
  3665. }, StateTuple.Create(this, awaiter));
  3666. }
  3667. }
  3668. {
  3669. var awaiter = task10.GetAwaiter();
  3670. if (awaiter.IsCompleted)
  3671. {
  3672. TryInvokeContinuationT10(this, awaiter);
  3673. }
  3674. else
  3675. {
  3676. awaiter.SourceOnCompleted(state =>
  3677. {
  3678. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T10>.Awaiter>)state)
  3679. {
  3680. TryInvokeContinuationT10(t.Item1, t.Item2);
  3681. }
  3682. }, StateTuple.Create(this, awaiter));
  3683. }
  3684. }
  3685. {
  3686. var awaiter = task11.GetAwaiter();
  3687. if (awaiter.IsCompleted)
  3688. {
  3689. TryInvokeContinuationT11(this, awaiter);
  3690. }
  3691. else
  3692. {
  3693. awaiter.SourceOnCompleted(state =>
  3694. {
  3695. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T11>.Awaiter>)state)
  3696. {
  3697. TryInvokeContinuationT11(t.Item1, t.Item2);
  3698. }
  3699. }, StateTuple.Create(this, awaiter));
  3700. }
  3701. }
  3702. {
  3703. var awaiter = task12.GetAwaiter();
  3704. if (awaiter.IsCompleted)
  3705. {
  3706. TryInvokeContinuationT12(this, awaiter);
  3707. }
  3708. else
  3709. {
  3710. awaiter.SourceOnCompleted(state =>
  3711. {
  3712. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T12>.Awaiter>)state)
  3713. {
  3714. TryInvokeContinuationT12(t.Item1, t.Item2);
  3715. }
  3716. }, StateTuple.Create(this, awaiter));
  3717. }
  3718. }
  3719. {
  3720. var awaiter = task13.GetAwaiter();
  3721. if (awaiter.IsCompleted)
  3722. {
  3723. TryInvokeContinuationT13(this, awaiter);
  3724. }
  3725. else
  3726. {
  3727. awaiter.SourceOnCompleted(state =>
  3728. {
  3729. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T13>.Awaiter>)state)
  3730. {
  3731. TryInvokeContinuationT13(t.Item1, t.Item2);
  3732. }
  3733. }, StateTuple.Create(this, awaiter));
  3734. }
  3735. }
  3736. {
  3737. var awaiter = task14.GetAwaiter();
  3738. if (awaiter.IsCompleted)
  3739. {
  3740. TryInvokeContinuationT14(this, awaiter);
  3741. }
  3742. else
  3743. {
  3744. awaiter.SourceOnCompleted(state =>
  3745. {
  3746. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, UniTask<T14>.Awaiter>)state)
  3747. {
  3748. TryInvokeContinuationT14(t.Item1, t.Item2);
  3749. }
  3750. }, StateTuple.Create(this, awaiter));
  3751. }
  3752. }
  3753. }
  3754. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T1>.Awaiter awaiter)
  3755. {
  3756. T1 result;
  3757. try
  3758. {
  3759. result = awaiter.GetResult();
  3760. }
  3761. catch (Exception ex)
  3762. {
  3763. self.core.TrySetException(ex);
  3764. return;
  3765. }
  3766. if (Interlocked.Increment(ref self.completedCount) == 1)
  3767. {
  3768. self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default, default, default));
  3769. }
  3770. }
  3771. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T2>.Awaiter awaiter)
  3772. {
  3773. T2 result;
  3774. try
  3775. {
  3776. result = awaiter.GetResult();
  3777. }
  3778. catch (Exception ex)
  3779. {
  3780. self.core.TrySetException(ex);
  3781. return;
  3782. }
  3783. if (Interlocked.Increment(ref self.completedCount) == 1)
  3784. {
  3785. self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default, default, default));
  3786. }
  3787. }
  3788. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T3>.Awaiter awaiter)
  3789. {
  3790. T3 result;
  3791. try
  3792. {
  3793. result = awaiter.GetResult();
  3794. }
  3795. catch (Exception ex)
  3796. {
  3797. self.core.TrySetException(ex);
  3798. return;
  3799. }
  3800. if (Interlocked.Increment(ref self.completedCount) == 1)
  3801. {
  3802. self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default, default, default));
  3803. }
  3804. }
  3805. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T4>.Awaiter awaiter)
  3806. {
  3807. T4 result;
  3808. try
  3809. {
  3810. result = awaiter.GetResult();
  3811. }
  3812. catch (Exception ex)
  3813. {
  3814. self.core.TrySetException(ex);
  3815. return;
  3816. }
  3817. if (Interlocked.Increment(ref self.completedCount) == 1)
  3818. {
  3819. self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default, default, default));
  3820. }
  3821. }
  3822. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T5>.Awaiter awaiter)
  3823. {
  3824. T5 result;
  3825. try
  3826. {
  3827. result = awaiter.GetResult();
  3828. }
  3829. catch (Exception ex)
  3830. {
  3831. self.core.TrySetException(ex);
  3832. return;
  3833. }
  3834. if (Interlocked.Increment(ref self.completedCount) == 1)
  3835. {
  3836. self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default, default, default));
  3837. }
  3838. }
  3839. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T6>.Awaiter awaiter)
  3840. {
  3841. T6 result;
  3842. try
  3843. {
  3844. result = awaiter.GetResult();
  3845. }
  3846. catch (Exception ex)
  3847. {
  3848. self.core.TrySetException(ex);
  3849. return;
  3850. }
  3851. if (Interlocked.Increment(ref self.completedCount) == 1)
  3852. {
  3853. self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default, default, default));
  3854. }
  3855. }
  3856. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T7>.Awaiter awaiter)
  3857. {
  3858. T7 result;
  3859. try
  3860. {
  3861. result = awaiter.GetResult();
  3862. }
  3863. catch (Exception ex)
  3864. {
  3865. self.core.TrySetException(ex);
  3866. return;
  3867. }
  3868. if (Interlocked.Increment(ref self.completedCount) == 1)
  3869. {
  3870. self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default, default, default));
  3871. }
  3872. }
  3873. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T8>.Awaiter awaiter)
  3874. {
  3875. T8 result;
  3876. try
  3877. {
  3878. result = awaiter.GetResult();
  3879. }
  3880. catch (Exception ex)
  3881. {
  3882. self.core.TrySetException(ex);
  3883. return;
  3884. }
  3885. if (Interlocked.Increment(ref self.completedCount) == 1)
  3886. {
  3887. self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default, default, default));
  3888. }
  3889. }
  3890. static void TryInvokeContinuationT9(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T9>.Awaiter awaiter)
  3891. {
  3892. T9 result;
  3893. try
  3894. {
  3895. result = awaiter.GetResult();
  3896. }
  3897. catch (Exception ex)
  3898. {
  3899. self.core.TrySetException(ex);
  3900. return;
  3901. }
  3902. if (Interlocked.Increment(ref self.completedCount) == 1)
  3903. {
  3904. self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default, default, default));
  3905. }
  3906. }
  3907. static void TryInvokeContinuationT10(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T10>.Awaiter awaiter)
  3908. {
  3909. T10 result;
  3910. try
  3911. {
  3912. result = awaiter.GetResult();
  3913. }
  3914. catch (Exception ex)
  3915. {
  3916. self.core.TrySetException(ex);
  3917. return;
  3918. }
  3919. if (Interlocked.Increment(ref self.completedCount) == 1)
  3920. {
  3921. self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default, default, default));
  3922. }
  3923. }
  3924. static void TryInvokeContinuationT11(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T11>.Awaiter awaiter)
  3925. {
  3926. T11 result;
  3927. try
  3928. {
  3929. result = awaiter.GetResult();
  3930. }
  3931. catch (Exception ex)
  3932. {
  3933. self.core.TrySetException(ex);
  3934. return;
  3935. }
  3936. if (Interlocked.Increment(ref self.completedCount) == 1)
  3937. {
  3938. self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default, default, default));
  3939. }
  3940. }
  3941. static void TryInvokeContinuationT12(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T12>.Awaiter awaiter)
  3942. {
  3943. T12 result;
  3944. try
  3945. {
  3946. result = awaiter.GetResult();
  3947. }
  3948. catch (Exception ex)
  3949. {
  3950. self.core.TrySetException(ex);
  3951. return;
  3952. }
  3953. if (Interlocked.Increment(ref self.completedCount) == 1)
  3954. {
  3955. self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result, default, default));
  3956. }
  3957. }
  3958. static void TryInvokeContinuationT13(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T13>.Awaiter awaiter)
  3959. {
  3960. T13 result;
  3961. try
  3962. {
  3963. result = awaiter.GetResult();
  3964. }
  3965. catch (Exception ex)
  3966. {
  3967. self.core.TrySetException(ex);
  3968. return;
  3969. }
  3970. if (Interlocked.Increment(ref self.completedCount) == 1)
  3971. {
  3972. self.core.TrySetResult((12, default, default, default, default, default, default, default, default, default, default, default, default, result, default));
  3973. }
  3974. }
  3975. static void TryInvokeContinuationT14(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> self, in UniTask<T14>.Awaiter awaiter)
  3976. {
  3977. T14 result;
  3978. try
  3979. {
  3980. result = awaiter.GetResult();
  3981. }
  3982. catch (Exception ex)
  3983. {
  3984. self.core.TrySetException(ex);
  3985. return;
  3986. }
  3987. if (Interlocked.Increment(ref self.completedCount) == 1)
  3988. {
  3989. self.core.TrySetResult((13, default, default, default, default, default, default, default, default, default, default, default, default, default, result));
  3990. }
  3991. }
  3992. 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)
  3993. {
  3994. TaskTracker.RemoveTracking(this);
  3995. GC.SuppressFinalize(this);
  3996. return core.GetResult(token);
  3997. }
  3998. public UniTaskStatus GetStatus(short token)
  3999. {
  4000. return core.GetStatus(token);
  4001. }
  4002. public void OnCompleted(Action<object> continuation, object state, short token)
  4003. {
  4004. core.OnCompleted(continuation, state, token);
  4005. }
  4006. public UniTaskStatus UnsafeGetStatus()
  4007. {
  4008. return core.UnsafeGetStatus();
  4009. }
  4010. void IUniTaskSource.GetResult(short token)
  4011. {
  4012. GetResult(token);
  4013. }
  4014. }
  4015. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12, UniTask<T13> task13, UniTask<T14> task14, UniTask<T15> task15)
  4016. {
  4017. 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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14, task15), 0);
  4018. }
  4019. sealed class WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> : 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)>
  4020. {
  4021. int completedCount;
  4022. 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;
  4023. public WhenAnyPromise(UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7, UniTask<T8> task8, UniTask<T9> task9, UniTask<T10> task10, UniTask<T11> task11, UniTask<T12> task12, UniTask<T13> task13, UniTask<T14> task14, UniTask<T15> task15)
  4024. {
  4025. TaskTracker.TrackActiveTask(this, 3);
  4026. this.completedCount = 0;
  4027. {
  4028. var awaiter = task1.GetAwaiter();
  4029. if (awaiter.IsCompleted)
  4030. {
  4031. TryInvokeContinuationT1(this, awaiter);
  4032. }
  4033. else
  4034. {
  4035. awaiter.SourceOnCompleted(state =>
  4036. {
  4037. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T1>.Awaiter>)state)
  4038. {
  4039. TryInvokeContinuationT1(t.Item1, t.Item2);
  4040. }
  4041. }, StateTuple.Create(this, awaiter));
  4042. }
  4043. }
  4044. {
  4045. var awaiter = task2.GetAwaiter();
  4046. if (awaiter.IsCompleted)
  4047. {
  4048. TryInvokeContinuationT2(this, awaiter);
  4049. }
  4050. else
  4051. {
  4052. awaiter.SourceOnCompleted(state =>
  4053. {
  4054. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T2>.Awaiter>)state)
  4055. {
  4056. TryInvokeContinuationT2(t.Item1, t.Item2);
  4057. }
  4058. }, StateTuple.Create(this, awaiter));
  4059. }
  4060. }
  4061. {
  4062. var awaiter = task3.GetAwaiter();
  4063. if (awaiter.IsCompleted)
  4064. {
  4065. TryInvokeContinuationT3(this, awaiter);
  4066. }
  4067. else
  4068. {
  4069. awaiter.SourceOnCompleted(state =>
  4070. {
  4071. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T3>.Awaiter>)state)
  4072. {
  4073. TryInvokeContinuationT3(t.Item1, t.Item2);
  4074. }
  4075. }, StateTuple.Create(this, awaiter));
  4076. }
  4077. }
  4078. {
  4079. var awaiter = task4.GetAwaiter();
  4080. if (awaiter.IsCompleted)
  4081. {
  4082. TryInvokeContinuationT4(this, awaiter);
  4083. }
  4084. else
  4085. {
  4086. awaiter.SourceOnCompleted(state =>
  4087. {
  4088. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T4>.Awaiter>)state)
  4089. {
  4090. TryInvokeContinuationT4(t.Item1, t.Item2);
  4091. }
  4092. }, StateTuple.Create(this, awaiter));
  4093. }
  4094. }
  4095. {
  4096. var awaiter = task5.GetAwaiter();
  4097. if (awaiter.IsCompleted)
  4098. {
  4099. TryInvokeContinuationT5(this, awaiter);
  4100. }
  4101. else
  4102. {
  4103. awaiter.SourceOnCompleted(state =>
  4104. {
  4105. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T5>.Awaiter>)state)
  4106. {
  4107. TryInvokeContinuationT5(t.Item1, t.Item2);
  4108. }
  4109. }, StateTuple.Create(this, awaiter));
  4110. }
  4111. }
  4112. {
  4113. var awaiter = task6.GetAwaiter();
  4114. if (awaiter.IsCompleted)
  4115. {
  4116. TryInvokeContinuationT6(this, awaiter);
  4117. }
  4118. else
  4119. {
  4120. awaiter.SourceOnCompleted(state =>
  4121. {
  4122. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T6>.Awaiter>)state)
  4123. {
  4124. TryInvokeContinuationT6(t.Item1, t.Item2);
  4125. }
  4126. }, StateTuple.Create(this, awaiter));
  4127. }
  4128. }
  4129. {
  4130. var awaiter = task7.GetAwaiter();
  4131. if (awaiter.IsCompleted)
  4132. {
  4133. TryInvokeContinuationT7(this, awaiter);
  4134. }
  4135. else
  4136. {
  4137. awaiter.SourceOnCompleted(state =>
  4138. {
  4139. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T7>.Awaiter>)state)
  4140. {
  4141. TryInvokeContinuationT7(t.Item1, t.Item2);
  4142. }
  4143. }, StateTuple.Create(this, awaiter));
  4144. }
  4145. }
  4146. {
  4147. var awaiter = task8.GetAwaiter();
  4148. if (awaiter.IsCompleted)
  4149. {
  4150. TryInvokeContinuationT8(this, awaiter);
  4151. }
  4152. else
  4153. {
  4154. awaiter.SourceOnCompleted(state =>
  4155. {
  4156. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T8>.Awaiter>)state)
  4157. {
  4158. TryInvokeContinuationT8(t.Item1, t.Item2);
  4159. }
  4160. }, StateTuple.Create(this, awaiter));
  4161. }
  4162. }
  4163. {
  4164. var awaiter = task9.GetAwaiter();
  4165. if (awaiter.IsCompleted)
  4166. {
  4167. TryInvokeContinuationT9(this, awaiter);
  4168. }
  4169. else
  4170. {
  4171. awaiter.SourceOnCompleted(state =>
  4172. {
  4173. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T9>.Awaiter>)state)
  4174. {
  4175. TryInvokeContinuationT9(t.Item1, t.Item2);
  4176. }
  4177. }, StateTuple.Create(this, awaiter));
  4178. }
  4179. }
  4180. {
  4181. var awaiter = task10.GetAwaiter();
  4182. if (awaiter.IsCompleted)
  4183. {
  4184. TryInvokeContinuationT10(this, awaiter);
  4185. }
  4186. else
  4187. {
  4188. awaiter.SourceOnCompleted(state =>
  4189. {
  4190. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T10>.Awaiter>)state)
  4191. {
  4192. TryInvokeContinuationT10(t.Item1, t.Item2);
  4193. }
  4194. }, StateTuple.Create(this, awaiter));
  4195. }
  4196. }
  4197. {
  4198. var awaiter = task11.GetAwaiter();
  4199. if (awaiter.IsCompleted)
  4200. {
  4201. TryInvokeContinuationT11(this, awaiter);
  4202. }
  4203. else
  4204. {
  4205. awaiter.SourceOnCompleted(state =>
  4206. {
  4207. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T11>.Awaiter>)state)
  4208. {
  4209. TryInvokeContinuationT11(t.Item1, t.Item2);
  4210. }
  4211. }, StateTuple.Create(this, awaiter));
  4212. }
  4213. }
  4214. {
  4215. var awaiter = task12.GetAwaiter();
  4216. if (awaiter.IsCompleted)
  4217. {
  4218. TryInvokeContinuationT12(this, awaiter);
  4219. }
  4220. else
  4221. {
  4222. awaiter.SourceOnCompleted(state =>
  4223. {
  4224. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T12>.Awaiter>)state)
  4225. {
  4226. TryInvokeContinuationT12(t.Item1, t.Item2);
  4227. }
  4228. }, StateTuple.Create(this, awaiter));
  4229. }
  4230. }
  4231. {
  4232. var awaiter = task13.GetAwaiter();
  4233. if (awaiter.IsCompleted)
  4234. {
  4235. TryInvokeContinuationT13(this, awaiter);
  4236. }
  4237. else
  4238. {
  4239. awaiter.SourceOnCompleted(state =>
  4240. {
  4241. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T13>.Awaiter>)state)
  4242. {
  4243. TryInvokeContinuationT13(t.Item1, t.Item2);
  4244. }
  4245. }, StateTuple.Create(this, awaiter));
  4246. }
  4247. }
  4248. {
  4249. var awaiter = task14.GetAwaiter();
  4250. if (awaiter.IsCompleted)
  4251. {
  4252. TryInvokeContinuationT14(this, awaiter);
  4253. }
  4254. else
  4255. {
  4256. awaiter.SourceOnCompleted(state =>
  4257. {
  4258. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T14>.Awaiter>)state)
  4259. {
  4260. TryInvokeContinuationT14(t.Item1, t.Item2);
  4261. }
  4262. }, StateTuple.Create(this, awaiter));
  4263. }
  4264. }
  4265. {
  4266. var awaiter = task15.GetAwaiter();
  4267. if (awaiter.IsCompleted)
  4268. {
  4269. TryInvokeContinuationT15(this, awaiter);
  4270. }
  4271. else
  4272. {
  4273. awaiter.SourceOnCompleted(state =>
  4274. {
  4275. using (var t = (StateTuple<WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, UniTask<T15>.Awaiter>)state)
  4276. {
  4277. TryInvokeContinuationT15(t.Item1, t.Item2);
  4278. }
  4279. }, StateTuple.Create(this, awaiter));
  4280. }
  4281. }
  4282. }
  4283. static void TryInvokeContinuationT1(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T1>.Awaiter awaiter)
  4284. {
  4285. T1 result;
  4286. try
  4287. {
  4288. result = awaiter.GetResult();
  4289. }
  4290. catch (Exception ex)
  4291. {
  4292. self.core.TrySetException(ex);
  4293. return;
  4294. }
  4295. if (Interlocked.Increment(ref self.completedCount) == 1)
  4296. {
  4297. self.core.TrySetResult((0, result, default, default, default, default, default, default, default, default, default, default, default, default, default, default));
  4298. }
  4299. }
  4300. static void TryInvokeContinuationT2(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T2>.Awaiter awaiter)
  4301. {
  4302. T2 result;
  4303. try
  4304. {
  4305. result = awaiter.GetResult();
  4306. }
  4307. catch (Exception ex)
  4308. {
  4309. self.core.TrySetException(ex);
  4310. return;
  4311. }
  4312. if (Interlocked.Increment(ref self.completedCount) == 1)
  4313. {
  4314. self.core.TrySetResult((1, default, result, default, default, default, default, default, default, default, default, default, default, default, default, default));
  4315. }
  4316. }
  4317. static void TryInvokeContinuationT3(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T3>.Awaiter awaiter)
  4318. {
  4319. T3 result;
  4320. try
  4321. {
  4322. result = awaiter.GetResult();
  4323. }
  4324. catch (Exception ex)
  4325. {
  4326. self.core.TrySetException(ex);
  4327. return;
  4328. }
  4329. if (Interlocked.Increment(ref self.completedCount) == 1)
  4330. {
  4331. self.core.TrySetResult((2, default, default, result, default, default, default, default, default, default, default, default, default, default, default, default));
  4332. }
  4333. }
  4334. static void TryInvokeContinuationT4(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T4>.Awaiter awaiter)
  4335. {
  4336. T4 result;
  4337. try
  4338. {
  4339. result = awaiter.GetResult();
  4340. }
  4341. catch (Exception ex)
  4342. {
  4343. self.core.TrySetException(ex);
  4344. return;
  4345. }
  4346. if (Interlocked.Increment(ref self.completedCount) == 1)
  4347. {
  4348. self.core.TrySetResult((3, default, default, default, result, default, default, default, default, default, default, default, default, default, default, default));
  4349. }
  4350. }
  4351. static void TryInvokeContinuationT5(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T5>.Awaiter awaiter)
  4352. {
  4353. T5 result;
  4354. try
  4355. {
  4356. result = awaiter.GetResult();
  4357. }
  4358. catch (Exception ex)
  4359. {
  4360. self.core.TrySetException(ex);
  4361. return;
  4362. }
  4363. if (Interlocked.Increment(ref self.completedCount) == 1)
  4364. {
  4365. self.core.TrySetResult((4, default, default, default, default, result, default, default, default, default, default, default, default, default, default, default));
  4366. }
  4367. }
  4368. static void TryInvokeContinuationT6(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T6>.Awaiter awaiter)
  4369. {
  4370. T6 result;
  4371. try
  4372. {
  4373. result = awaiter.GetResult();
  4374. }
  4375. catch (Exception ex)
  4376. {
  4377. self.core.TrySetException(ex);
  4378. return;
  4379. }
  4380. if (Interlocked.Increment(ref self.completedCount) == 1)
  4381. {
  4382. self.core.TrySetResult((5, default, default, default, default, default, result, default, default, default, default, default, default, default, default, default));
  4383. }
  4384. }
  4385. static void TryInvokeContinuationT7(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T7>.Awaiter awaiter)
  4386. {
  4387. T7 result;
  4388. try
  4389. {
  4390. result = awaiter.GetResult();
  4391. }
  4392. catch (Exception ex)
  4393. {
  4394. self.core.TrySetException(ex);
  4395. return;
  4396. }
  4397. if (Interlocked.Increment(ref self.completedCount) == 1)
  4398. {
  4399. self.core.TrySetResult((6, default, default, default, default, default, default, result, default, default, default, default, default, default, default, default));
  4400. }
  4401. }
  4402. static void TryInvokeContinuationT8(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T8>.Awaiter awaiter)
  4403. {
  4404. T8 result;
  4405. try
  4406. {
  4407. result = awaiter.GetResult();
  4408. }
  4409. catch (Exception ex)
  4410. {
  4411. self.core.TrySetException(ex);
  4412. return;
  4413. }
  4414. if (Interlocked.Increment(ref self.completedCount) == 1)
  4415. {
  4416. self.core.TrySetResult((7, default, default, default, default, default, default, default, result, default, default, default, default, default, default, default));
  4417. }
  4418. }
  4419. static void TryInvokeContinuationT9(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T9>.Awaiter awaiter)
  4420. {
  4421. T9 result;
  4422. try
  4423. {
  4424. result = awaiter.GetResult();
  4425. }
  4426. catch (Exception ex)
  4427. {
  4428. self.core.TrySetException(ex);
  4429. return;
  4430. }
  4431. if (Interlocked.Increment(ref self.completedCount) == 1)
  4432. {
  4433. self.core.TrySetResult((8, default, default, default, default, default, default, default, default, result, default, default, default, default, default, default));
  4434. }
  4435. }
  4436. static void TryInvokeContinuationT10(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T10>.Awaiter awaiter)
  4437. {
  4438. T10 result;
  4439. try
  4440. {
  4441. result = awaiter.GetResult();
  4442. }
  4443. catch (Exception ex)
  4444. {
  4445. self.core.TrySetException(ex);
  4446. return;
  4447. }
  4448. if (Interlocked.Increment(ref self.completedCount) == 1)
  4449. {
  4450. self.core.TrySetResult((9, default, default, default, default, default, default, default, default, default, result, default, default, default, default, default));
  4451. }
  4452. }
  4453. static void TryInvokeContinuationT11(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T11>.Awaiter awaiter)
  4454. {
  4455. T11 result;
  4456. try
  4457. {
  4458. result = awaiter.GetResult();
  4459. }
  4460. catch (Exception ex)
  4461. {
  4462. self.core.TrySetException(ex);
  4463. return;
  4464. }
  4465. if (Interlocked.Increment(ref self.completedCount) == 1)
  4466. {
  4467. self.core.TrySetResult((10, default, default, default, default, default, default, default, default, default, default, result, default, default, default, default));
  4468. }
  4469. }
  4470. static void TryInvokeContinuationT12(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T12>.Awaiter awaiter)
  4471. {
  4472. T12 result;
  4473. try
  4474. {
  4475. result = awaiter.GetResult();
  4476. }
  4477. catch (Exception ex)
  4478. {
  4479. self.core.TrySetException(ex);
  4480. return;
  4481. }
  4482. if (Interlocked.Increment(ref self.completedCount) == 1)
  4483. {
  4484. self.core.TrySetResult((11, default, default, default, default, default, default, default, default, default, default, default, result, default, default, default));
  4485. }
  4486. }
  4487. static void TryInvokeContinuationT13(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T13>.Awaiter awaiter)
  4488. {
  4489. T13 result;
  4490. try
  4491. {
  4492. result = awaiter.GetResult();
  4493. }
  4494. catch (Exception ex)
  4495. {
  4496. self.core.TrySetException(ex);
  4497. return;
  4498. }
  4499. if (Interlocked.Increment(ref self.completedCount) == 1)
  4500. {
  4501. self.core.TrySetResult((12, default, default, default, default, default, default, default, default, default, default, default, default, result, default, default));
  4502. }
  4503. }
  4504. static void TryInvokeContinuationT14(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T14>.Awaiter awaiter)
  4505. {
  4506. T14 result;
  4507. try
  4508. {
  4509. result = awaiter.GetResult();
  4510. }
  4511. catch (Exception ex)
  4512. {
  4513. self.core.TrySetException(ex);
  4514. return;
  4515. }
  4516. if (Interlocked.Increment(ref self.completedCount) == 1)
  4517. {
  4518. self.core.TrySetResult((13, default, default, default, default, default, default, default, default, default, default, default, default, default, result, default));
  4519. }
  4520. }
  4521. static void TryInvokeContinuationT15(WhenAnyPromise<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> self, in UniTask<T15>.Awaiter awaiter)
  4522. {
  4523. T15 result;
  4524. try
  4525. {
  4526. result = awaiter.GetResult();
  4527. }
  4528. catch (Exception ex)
  4529. {
  4530. self.core.TrySetException(ex);
  4531. return;
  4532. }
  4533. if (Interlocked.Increment(ref self.completedCount) == 1)
  4534. {
  4535. self.core.TrySetResult((14, default, default, default, default, default, default, default, default, default, default, default, default, default, default, result));
  4536. }
  4537. }
  4538. 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)
  4539. {
  4540. TaskTracker.RemoveTracking(this);
  4541. GC.SuppressFinalize(this);
  4542. return core.GetResult(token);
  4543. }
  4544. public UniTaskStatus GetStatus(short token)
  4545. {
  4546. return core.GetStatus(token);
  4547. }
  4548. public void OnCompleted(Action<object> continuation, object state, short token)
  4549. {
  4550. core.OnCompleted(continuation, state, token);
  4551. }
  4552. public UniTaskStatus UnsafeGetStatus()
  4553. {
  4554. return core.UnsafeGetStatus();
  4555. }
  4556. void IUniTaskSource.GetResult(short token)
  4557. {
  4558. GetResult(token);
  4559. }
  4560. }
  4561. }
  4562. }