CombineLatest.Generated.cs 415 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Reactive.Disposables;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace System.Reactive.Linq
  8. {
  9. partial class AsyncObservable
  10. {
  11. public static IAsyncObservable<TResult> CombineLatest<T1, T2, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, Func<T1, T2, TResult> selector)
  12. {
  13. if (source1 == null)
  14. throw new ArgumentNullException(nameof(source1));
  15. if (source2 == null)
  16. throw new ArgumentNullException(nameof(source2));
  17. if (selector == null)
  18. throw new ArgumentNullException(nameof(selector));
  19. return Create<TResult>(async observer =>
  20. {
  21. var d = new CompositeAsyncDisposable();
  22. var (observer1, observer2) = observer.CombineLatest(selector);
  23. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  24. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  25. await Task.WhenAll(sub1, sub2).ConfigureAwait(false);
  26. return d;
  27. });
  28. }
  29. public static IAsyncObservable<TResult> CombineLatest<T1, T2, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, Func<T1, T2, Task<TResult>> selector)
  30. {
  31. if (source1 == null)
  32. throw new ArgumentNullException(nameof(source1));
  33. if (source2 == null)
  34. throw new ArgumentNullException(nameof(source2));
  35. if (selector == null)
  36. throw new ArgumentNullException(nameof(selector));
  37. return Create<TResult>(async observer =>
  38. {
  39. var d = new CompositeAsyncDisposable();
  40. var (observer1, observer2) = observer.CombineLatest(selector);
  41. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  42. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  43. await Task.WhenAll(sub1, sub2).ConfigureAwait(false);
  44. return d;
  45. });
  46. }
  47. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, Func<T1, T2, T3, TResult> selector)
  48. {
  49. if (source1 == null)
  50. throw new ArgumentNullException(nameof(source1));
  51. if (source2 == null)
  52. throw new ArgumentNullException(nameof(source2));
  53. if (source3 == null)
  54. throw new ArgumentNullException(nameof(source3));
  55. if (selector == null)
  56. throw new ArgumentNullException(nameof(selector));
  57. return Create<TResult>(async observer =>
  58. {
  59. var d = new CompositeAsyncDisposable();
  60. var (observer1, observer2, observer3) = observer.CombineLatest(selector);
  61. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  62. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  63. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  64. await Task.WhenAll(sub1, sub2, sub3).ConfigureAwait(false);
  65. return d;
  66. });
  67. }
  68. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, Func<T1, T2, T3, Task<TResult>> selector)
  69. {
  70. if (source1 == null)
  71. throw new ArgumentNullException(nameof(source1));
  72. if (source2 == null)
  73. throw new ArgumentNullException(nameof(source2));
  74. if (source3 == null)
  75. throw new ArgumentNullException(nameof(source3));
  76. if (selector == null)
  77. throw new ArgumentNullException(nameof(selector));
  78. return Create<TResult>(async observer =>
  79. {
  80. var d = new CompositeAsyncDisposable();
  81. var (observer1, observer2, observer3) = observer.CombineLatest(selector);
  82. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  83. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  84. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  85. await Task.WhenAll(sub1, sub2, sub3).ConfigureAwait(false);
  86. return d;
  87. });
  88. }
  89. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, Func<T1, T2, T3, T4, TResult> selector)
  90. {
  91. if (source1 == null)
  92. throw new ArgumentNullException(nameof(source1));
  93. if (source2 == null)
  94. throw new ArgumentNullException(nameof(source2));
  95. if (source3 == null)
  96. throw new ArgumentNullException(nameof(source3));
  97. if (source4 == null)
  98. throw new ArgumentNullException(nameof(source4));
  99. if (selector == null)
  100. throw new ArgumentNullException(nameof(selector));
  101. return Create<TResult>(async observer =>
  102. {
  103. var d = new CompositeAsyncDisposable();
  104. var (observer1, observer2, observer3, observer4) = observer.CombineLatest(selector);
  105. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  106. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  107. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  108. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  109. await Task.WhenAll(sub1, sub2, sub3, sub4).ConfigureAwait(false);
  110. return d;
  111. });
  112. }
  113. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, Func<T1, T2, T3, T4, Task<TResult>> selector)
  114. {
  115. if (source1 == null)
  116. throw new ArgumentNullException(nameof(source1));
  117. if (source2 == null)
  118. throw new ArgumentNullException(nameof(source2));
  119. if (source3 == null)
  120. throw new ArgumentNullException(nameof(source3));
  121. if (source4 == null)
  122. throw new ArgumentNullException(nameof(source4));
  123. if (selector == null)
  124. throw new ArgumentNullException(nameof(selector));
  125. return Create<TResult>(async observer =>
  126. {
  127. var d = new CompositeAsyncDisposable();
  128. var (observer1, observer2, observer3, observer4) = observer.CombineLatest(selector);
  129. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  130. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  131. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  132. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  133. await Task.WhenAll(sub1, sub2, sub3, sub4).ConfigureAwait(false);
  134. return d;
  135. });
  136. }
  137. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, Func<T1, T2, T3, T4, T5, TResult> selector)
  138. {
  139. if (source1 == null)
  140. throw new ArgumentNullException(nameof(source1));
  141. if (source2 == null)
  142. throw new ArgumentNullException(nameof(source2));
  143. if (source3 == null)
  144. throw new ArgumentNullException(nameof(source3));
  145. if (source4 == null)
  146. throw new ArgumentNullException(nameof(source4));
  147. if (source5 == null)
  148. throw new ArgumentNullException(nameof(source5));
  149. if (selector == null)
  150. throw new ArgumentNullException(nameof(selector));
  151. return Create<TResult>(async observer =>
  152. {
  153. var d = new CompositeAsyncDisposable();
  154. var (observer1, observer2, observer3, observer4, observer5) = observer.CombineLatest(selector);
  155. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  156. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  157. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  158. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  159. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  160. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5).ConfigureAwait(false);
  161. return d;
  162. });
  163. }
  164. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, Func<T1, T2, T3, T4, T5, Task<TResult>> selector)
  165. {
  166. if (source1 == null)
  167. throw new ArgumentNullException(nameof(source1));
  168. if (source2 == null)
  169. throw new ArgumentNullException(nameof(source2));
  170. if (source3 == null)
  171. throw new ArgumentNullException(nameof(source3));
  172. if (source4 == null)
  173. throw new ArgumentNullException(nameof(source4));
  174. if (source5 == null)
  175. throw new ArgumentNullException(nameof(source5));
  176. if (selector == null)
  177. throw new ArgumentNullException(nameof(selector));
  178. return Create<TResult>(async observer =>
  179. {
  180. var d = new CompositeAsyncDisposable();
  181. var (observer1, observer2, observer3, observer4, observer5) = observer.CombineLatest(selector);
  182. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  183. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  184. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  185. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  186. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  187. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5).ConfigureAwait(false);
  188. return d;
  189. });
  190. }
  191. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, Func<T1, T2, T3, T4, T5, T6, TResult> selector)
  192. {
  193. if (source1 == null)
  194. throw new ArgumentNullException(nameof(source1));
  195. if (source2 == null)
  196. throw new ArgumentNullException(nameof(source2));
  197. if (source3 == null)
  198. throw new ArgumentNullException(nameof(source3));
  199. if (source4 == null)
  200. throw new ArgumentNullException(nameof(source4));
  201. if (source5 == null)
  202. throw new ArgumentNullException(nameof(source5));
  203. if (source6 == null)
  204. throw new ArgumentNullException(nameof(source6));
  205. if (selector == null)
  206. throw new ArgumentNullException(nameof(selector));
  207. return Create<TResult>(async observer =>
  208. {
  209. var d = new CompositeAsyncDisposable();
  210. var (observer1, observer2, observer3, observer4, observer5, observer6) = observer.CombineLatest(selector);
  211. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  212. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  213. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  214. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  215. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  216. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  217. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6).ConfigureAwait(false);
  218. return d;
  219. });
  220. }
  221. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, Func<T1, T2, T3, T4, T5, T6, Task<TResult>> selector)
  222. {
  223. if (source1 == null)
  224. throw new ArgumentNullException(nameof(source1));
  225. if (source2 == null)
  226. throw new ArgumentNullException(nameof(source2));
  227. if (source3 == null)
  228. throw new ArgumentNullException(nameof(source3));
  229. if (source4 == null)
  230. throw new ArgumentNullException(nameof(source4));
  231. if (source5 == null)
  232. throw new ArgumentNullException(nameof(source5));
  233. if (source6 == null)
  234. throw new ArgumentNullException(nameof(source6));
  235. if (selector == null)
  236. throw new ArgumentNullException(nameof(selector));
  237. return Create<TResult>(async observer =>
  238. {
  239. var d = new CompositeAsyncDisposable();
  240. var (observer1, observer2, observer3, observer4, observer5, observer6) = observer.CombineLatest(selector);
  241. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  242. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  243. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  244. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  245. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  246. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  247. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6).ConfigureAwait(false);
  248. return d;
  249. });
  250. }
  251. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, Func<T1, T2, T3, T4, T5, T6, T7, TResult> selector)
  252. {
  253. if (source1 == null)
  254. throw new ArgumentNullException(nameof(source1));
  255. if (source2 == null)
  256. throw new ArgumentNullException(nameof(source2));
  257. if (source3 == null)
  258. throw new ArgumentNullException(nameof(source3));
  259. if (source4 == null)
  260. throw new ArgumentNullException(nameof(source4));
  261. if (source5 == null)
  262. throw new ArgumentNullException(nameof(source5));
  263. if (source6 == null)
  264. throw new ArgumentNullException(nameof(source6));
  265. if (source7 == null)
  266. throw new ArgumentNullException(nameof(source7));
  267. if (selector == null)
  268. throw new ArgumentNullException(nameof(selector));
  269. return Create<TResult>(async observer =>
  270. {
  271. var d = new CompositeAsyncDisposable();
  272. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7) = observer.CombineLatest(selector);
  273. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  274. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  275. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  276. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  277. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  278. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  279. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  280. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7).ConfigureAwait(false);
  281. return d;
  282. });
  283. }
  284. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, Func<T1, T2, T3, T4, T5, T6, T7, Task<TResult>> selector)
  285. {
  286. if (source1 == null)
  287. throw new ArgumentNullException(nameof(source1));
  288. if (source2 == null)
  289. throw new ArgumentNullException(nameof(source2));
  290. if (source3 == null)
  291. throw new ArgumentNullException(nameof(source3));
  292. if (source4 == null)
  293. throw new ArgumentNullException(nameof(source4));
  294. if (source5 == null)
  295. throw new ArgumentNullException(nameof(source5));
  296. if (source6 == null)
  297. throw new ArgumentNullException(nameof(source6));
  298. if (source7 == null)
  299. throw new ArgumentNullException(nameof(source7));
  300. if (selector == null)
  301. throw new ArgumentNullException(nameof(selector));
  302. return Create<TResult>(async observer =>
  303. {
  304. var d = new CompositeAsyncDisposable();
  305. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7) = observer.CombineLatest(selector);
  306. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  307. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  308. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  309. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  310. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  311. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  312. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  313. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7).ConfigureAwait(false);
  314. return d;
  315. });
  316. }
  317. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> selector)
  318. {
  319. if (source1 == null)
  320. throw new ArgumentNullException(nameof(source1));
  321. if (source2 == null)
  322. throw new ArgumentNullException(nameof(source2));
  323. if (source3 == null)
  324. throw new ArgumentNullException(nameof(source3));
  325. if (source4 == null)
  326. throw new ArgumentNullException(nameof(source4));
  327. if (source5 == null)
  328. throw new ArgumentNullException(nameof(source5));
  329. if (source6 == null)
  330. throw new ArgumentNullException(nameof(source6));
  331. if (source7 == null)
  332. throw new ArgumentNullException(nameof(source7));
  333. if (source8 == null)
  334. throw new ArgumentNullException(nameof(source8));
  335. if (selector == null)
  336. throw new ArgumentNullException(nameof(selector));
  337. return Create<TResult>(async observer =>
  338. {
  339. var d = new CompositeAsyncDisposable();
  340. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8) = observer.CombineLatest(selector);
  341. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  342. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  343. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  344. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  345. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  346. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  347. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  348. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  349. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8).ConfigureAwait(false);
  350. return d;
  351. });
  352. }
  353. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, Func<T1, T2, T3, T4, T5, T6, T7, T8, Task<TResult>> selector)
  354. {
  355. if (source1 == null)
  356. throw new ArgumentNullException(nameof(source1));
  357. if (source2 == null)
  358. throw new ArgumentNullException(nameof(source2));
  359. if (source3 == null)
  360. throw new ArgumentNullException(nameof(source3));
  361. if (source4 == null)
  362. throw new ArgumentNullException(nameof(source4));
  363. if (source5 == null)
  364. throw new ArgumentNullException(nameof(source5));
  365. if (source6 == null)
  366. throw new ArgumentNullException(nameof(source6));
  367. if (source7 == null)
  368. throw new ArgumentNullException(nameof(source7));
  369. if (source8 == null)
  370. throw new ArgumentNullException(nameof(source8));
  371. if (selector == null)
  372. throw new ArgumentNullException(nameof(selector));
  373. return Create<TResult>(async observer =>
  374. {
  375. var d = new CompositeAsyncDisposable();
  376. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8) = observer.CombineLatest(selector);
  377. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  378. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  379. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  380. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  381. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  382. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  383. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  384. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  385. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8).ConfigureAwait(false);
  386. return d;
  387. });
  388. }
  389. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> selector)
  390. {
  391. if (source1 == null)
  392. throw new ArgumentNullException(nameof(source1));
  393. if (source2 == null)
  394. throw new ArgumentNullException(nameof(source2));
  395. if (source3 == null)
  396. throw new ArgumentNullException(nameof(source3));
  397. if (source4 == null)
  398. throw new ArgumentNullException(nameof(source4));
  399. if (source5 == null)
  400. throw new ArgumentNullException(nameof(source5));
  401. if (source6 == null)
  402. throw new ArgumentNullException(nameof(source6));
  403. if (source7 == null)
  404. throw new ArgumentNullException(nameof(source7));
  405. if (source8 == null)
  406. throw new ArgumentNullException(nameof(source8));
  407. if (source9 == null)
  408. throw new ArgumentNullException(nameof(source9));
  409. if (selector == null)
  410. throw new ArgumentNullException(nameof(selector));
  411. return Create<TResult>(async observer =>
  412. {
  413. var d = new CompositeAsyncDisposable();
  414. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9) = observer.CombineLatest(selector);
  415. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  416. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  417. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  418. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  419. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  420. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  421. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  422. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  423. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  424. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9).ConfigureAwait(false);
  425. return d;
  426. });
  427. }
  428. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, Task<TResult>> selector)
  429. {
  430. if (source1 == null)
  431. throw new ArgumentNullException(nameof(source1));
  432. if (source2 == null)
  433. throw new ArgumentNullException(nameof(source2));
  434. if (source3 == null)
  435. throw new ArgumentNullException(nameof(source3));
  436. if (source4 == null)
  437. throw new ArgumentNullException(nameof(source4));
  438. if (source5 == null)
  439. throw new ArgumentNullException(nameof(source5));
  440. if (source6 == null)
  441. throw new ArgumentNullException(nameof(source6));
  442. if (source7 == null)
  443. throw new ArgumentNullException(nameof(source7));
  444. if (source8 == null)
  445. throw new ArgumentNullException(nameof(source8));
  446. if (source9 == null)
  447. throw new ArgumentNullException(nameof(source9));
  448. if (selector == null)
  449. throw new ArgumentNullException(nameof(selector));
  450. return Create<TResult>(async observer =>
  451. {
  452. var d = new CompositeAsyncDisposable();
  453. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9) = observer.CombineLatest(selector);
  454. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  455. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  456. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  457. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  458. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  459. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  460. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  461. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  462. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  463. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9).ConfigureAwait(false);
  464. return d;
  465. });
  466. }
  467. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> selector)
  468. {
  469. if (source1 == null)
  470. throw new ArgumentNullException(nameof(source1));
  471. if (source2 == null)
  472. throw new ArgumentNullException(nameof(source2));
  473. if (source3 == null)
  474. throw new ArgumentNullException(nameof(source3));
  475. if (source4 == null)
  476. throw new ArgumentNullException(nameof(source4));
  477. if (source5 == null)
  478. throw new ArgumentNullException(nameof(source5));
  479. if (source6 == null)
  480. throw new ArgumentNullException(nameof(source6));
  481. if (source7 == null)
  482. throw new ArgumentNullException(nameof(source7));
  483. if (source8 == null)
  484. throw new ArgumentNullException(nameof(source8));
  485. if (source9 == null)
  486. throw new ArgumentNullException(nameof(source9));
  487. if (source10 == null)
  488. throw new ArgumentNullException(nameof(source10));
  489. if (selector == null)
  490. throw new ArgumentNullException(nameof(selector));
  491. return Create<TResult>(async observer =>
  492. {
  493. var d = new CompositeAsyncDisposable();
  494. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10) = observer.CombineLatest(selector);
  495. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  496. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  497. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  498. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  499. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  500. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  501. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  502. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  503. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  504. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  505. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10).ConfigureAwait(false);
  506. return d;
  507. });
  508. }
  509. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Task<TResult>> selector)
  510. {
  511. if (source1 == null)
  512. throw new ArgumentNullException(nameof(source1));
  513. if (source2 == null)
  514. throw new ArgumentNullException(nameof(source2));
  515. if (source3 == null)
  516. throw new ArgumentNullException(nameof(source3));
  517. if (source4 == null)
  518. throw new ArgumentNullException(nameof(source4));
  519. if (source5 == null)
  520. throw new ArgumentNullException(nameof(source5));
  521. if (source6 == null)
  522. throw new ArgumentNullException(nameof(source6));
  523. if (source7 == null)
  524. throw new ArgumentNullException(nameof(source7));
  525. if (source8 == null)
  526. throw new ArgumentNullException(nameof(source8));
  527. if (source9 == null)
  528. throw new ArgumentNullException(nameof(source9));
  529. if (source10 == null)
  530. throw new ArgumentNullException(nameof(source10));
  531. if (selector == null)
  532. throw new ArgumentNullException(nameof(selector));
  533. return Create<TResult>(async observer =>
  534. {
  535. var d = new CompositeAsyncDisposable();
  536. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10) = observer.CombineLatest(selector);
  537. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  538. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  539. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  540. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  541. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  542. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  543. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  544. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  545. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  546. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  547. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10).ConfigureAwait(false);
  548. return d;
  549. });
  550. }
  551. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> selector)
  552. {
  553. if (source1 == null)
  554. throw new ArgumentNullException(nameof(source1));
  555. if (source2 == null)
  556. throw new ArgumentNullException(nameof(source2));
  557. if (source3 == null)
  558. throw new ArgumentNullException(nameof(source3));
  559. if (source4 == null)
  560. throw new ArgumentNullException(nameof(source4));
  561. if (source5 == null)
  562. throw new ArgumentNullException(nameof(source5));
  563. if (source6 == null)
  564. throw new ArgumentNullException(nameof(source6));
  565. if (source7 == null)
  566. throw new ArgumentNullException(nameof(source7));
  567. if (source8 == null)
  568. throw new ArgumentNullException(nameof(source8));
  569. if (source9 == null)
  570. throw new ArgumentNullException(nameof(source9));
  571. if (source10 == null)
  572. throw new ArgumentNullException(nameof(source10));
  573. if (source11 == null)
  574. throw new ArgumentNullException(nameof(source11));
  575. if (selector == null)
  576. throw new ArgumentNullException(nameof(selector));
  577. return Create<TResult>(async observer =>
  578. {
  579. var d = new CompositeAsyncDisposable();
  580. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11) = observer.CombineLatest(selector);
  581. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  582. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  583. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  584. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  585. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  586. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  587. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  588. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  589. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  590. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  591. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  592. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11).ConfigureAwait(false);
  593. return d;
  594. });
  595. }
  596. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Task<TResult>> selector)
  597. {
  598. if (source1 == null)
  599. throw new ArgumentNullException(nameof(source1));
  600. if (source2 == null)
  601. throw new ArgumentNullException(nameof(source2));
  602. if (source3 == null)
  603. throw new ArgumentNullException(nameof(source3));
  604. if (source4 == null)
  605. throw new ArgumentNullException(nameof(source4));
  606. if (source5 == null)
  607. throw new ArgumentNullException(nameof(source5));
  608. if (source6 == null)
  609. throw new ArgumentNullException(nameof(source6));
  610. if (source7 == null)
  611. throw new ArgumentNullException(nameof(source7));
  612. if (source8 == null)
  613. throw new ArgumentNullException(nameof(source8));
  614. if (source9 == null)
  615. throw new ArgumentNullException(nameof(source9));
  616. if (source10 == null)
  617. throw new ArgumentNullException(nameof(source10));
  618. if (source11 == null)
  619. throw new ArgumentNullException(nameof(source11));
  620. if (selector == null)
  621. throw new ArgumentNullException(nameof(selector));
  622. return Create<TResult>(async observer =>
  623. {
  624. var d = new CompositeAsyncDisposable();
  625. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11) = observer.CombineLatest(selector);
  626. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  627. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  628. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  629. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  630. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  631. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  632. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  633. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  634. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  635. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  636. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  637. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11).ConfigureAwait(false);
  638. return d;
  639. });
  640. }
  641. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> selector)
  642. {
  643. if (source1 == null)
  644. throw new ArgumentNullException(nameof(source1));
  645. if (source2 == null)
  646. throw new ArgumentNullException(nameof(source2));
  647. if (source3 == null)
  648. throw new ArgumentNullException(nameof(source3));
  649. if (source4 == null)
  650. throw new ArgumentNullException(nameof(source4));
  651. if (source5 == null)
  652. throw new ArgumentNullException(nameof(source5));
  653. if (source6 == null)
  654. throw new ArgumentNullException(nameof(source6));
  655. if (source7 == null)
  656. throw new ArgumentNullException(nameof(source7));
  657. if (source8 == null)
  658. throw new ArgumentNullException(nameof(source8));
  659. if (source9 == null)
  660. throw new ArgumentNullException(nameof(source9));
  661. if (source10 == null)
  662. throw new ArgumentNullException(nameof(source10));
  663. if (source11 == null)
  664. throw new ArgumentNullException(nameof(source11));
  665. if (source12 == null)
  666. throw new ArgumentNullException(nameof(source12));
  667. if (selector == null)
  668. throw new ArgumentNullException(nameof(selector));
  669. return Create<TResult>(async observer =>
  670. {
  671. var d = new CompositeAsyncDisposable();
  672. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12) = observer.CombineLatest(selector);
  673. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  674. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  675. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  676. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  677. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  678. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  679. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  680. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  681. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  682. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  683. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  684. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  685. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12).ConfigureAwait(false);
  686. return d;
  687. });
  688. }
  689. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Task<TResult>> selector)
  690. {
  691. if (source1 == null)
  692. throw new ArgumentNullException(nameof(source1));
  693. if (source2 == null)
  694. throw new ArgumentNullException(nameof(source2));
  695. if (source3 == null)
  696. throw new ArgumentNullException(nameof(source3));
  697. if (source4 == null)
  698. throw new ArgumentNullException(nameof(source4));
  699. if (source5 == null)
  700. throw new ArgumentNullException(nameof(source5));
  701. if (source6 == null)
  702. throw new ArgumentNullException(nameof(source6));
  703. if (source7 == null)
  704. throw new ArgumentNullException(nameof(source7));
  705. if (source8 == null)
  706. throw new ArgumentNullException(nameof(source8));
  707. if (source9 == null)
  708. throw new ArgumentNullException(nameof(source9));
  709. if (source10 == null)
  710. throw new ArgumentNullException(nameof(source10));
  711. if (source11 == null)
  712. throw new ArgumentNullException(nameof(source11));
  713. if (source12 == null)
  714. throw new ArgumentNullException(nameof(source12));
  715. if (selector == null)
  716. throw new ArgumentNullException(nameof(selector));
  717. return Create<TResult>(async observer =>
  718. {
  719. var d = new CompositeAsyncDisposable();
  720. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12) = observer.CombineLatest(selector);
  721. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  722. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  723. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  724. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  725. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  726. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  727. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  728. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  729. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  730. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  731. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  732. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  733. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12).ConfigureAwait(false);
  734. return d;
  735. });
  736. }
  737. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, IAsyncObservable<T13> source13, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> selector)
  738. {
  739. if (source1 == null)
  740. throw new ArgumentNullException(nameof(source1));
  741. if (source2 == null)
  742. throw new ArgumentNullException(nameof(source2));
  743. if (source3 == null)
  744. throw new ArgumentNullException(nameof(source3));
  745. if (source4 == null)
  746. throw new ArgumentNullException(nameof(source4));
  747. if (source5 == null)
  748. throw new ArgumentNullException(nameof(source5));
  749. if (source6 == null)
  750. throw new ArgumentNullException(nameof(source6));
  751. if (source7 == null)
  752. throw new ArgumentNullException(nameof(source7));
  753. if (source8 == null)
  754. throw new ArgumentNullException(nameof(source8));
  755. if (source9 == null)
  756. throw new ArgumentNullException(nameof(source9));
  757. if (source10 == null)
  758. throw new ArgumentNullException(nameof(source10));
  759. if (source11 == null)
  760. throw new ArgumentNullException(nameof(source11));
  761. if (source12 == null)
  762. throw new ArgumentNullException(nameof(source12));
  763. if (source13 == null)
  764. throw new ArgumentNullException(nameof(source13));
  765. if (selector == null)
  766. throw new ArgumentNullException(nameof(selector));
  767. return Create<TResult>(async observer =>
  768. {
  769. var d = new CompositeAsyncDisposable();
  770. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12, observer13) = observer.CombineLatest(selector);
  771. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  772. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  773. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  774. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  775. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  776. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  777. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  778. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  779. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  780. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  781. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  782. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  783. var sub13 = source13.SubscribeAsync(observer13).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  784. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12, sub13).ConfigureAwait(false);
  785. return d;
  786. });
  787. }
  788. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, IAsyncObservable<T13> source13, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Task<TResult>> selector)
  789. {
  790. if (source1 == null)
  791. throw new ArgumentNullException(nameof(source1));
  792. if (source2 == null)
  793. throw new ArgumentNullException(nameof(source2));
  794. if (source3 == null)
  795. throw new ArgumentNullException(nameof(source3));
  796. if (source4 == null)
  797. throw new ArgumentNullException(nameof(source4));
  798. if (source5 == null)
  799. throw new ArgumentNullException(nameof(source5));
  800. if (source6 == null)
  801. throw new ArgumentNullException(nameof(source6));
  802. if (source7 == null)
  803. throw new ArgumentNullException(nameof(source7));
  804. if (source8 == null)
  805. throw new ArgumentNullException(nameof(source8));
  806. if (source9 == null)
  807. throw new ArgumentNullException(nameof(source9));
  808. if (source10 == null)
  809. throw new ArgumentNullException(nameof(source10));
  810. if (source11 == null)
  811. throw new ArgumentNullException(nameof(source11));
  812. if (source12 == null)
  813. throw new ArgumentNullException(nameof(source12));
  814. if (source13 == null)
  815. throw new ArgumentNullException(nameof(source13));
  816. if (selector == null)
  817. throw new ArgumentNullException(nameof(selector));
  818. return Create<TResult>(async observer =>
  819. {
  820. var d = new CompositeAsyncDisposable();
  821. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12, observer13) = observer.CombineLatest(selector);
  822. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  823. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  824. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  825. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  826. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  827. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  828. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  829. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  830. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  831. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  832. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  833. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  834. var sub13 = source13.SubscribeAsync(observer13).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  835. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12, sub13).ConfigureAwait(false);
  836. return d;
  837. });
  838. }
  839. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, IAsyncObservable<T13> source13, IAsyncObservable<T14> source14, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> selector)
  840. {
  841. if (source1 == null)
  842. throw new ArgumentNullException(nameof(source1));
  843. if (source2 == null)
  844. throw new ArgumentNullException(nameof(source2));
  845. if (source3 == null)
  846. throw new ArgumentNullException(nameof(source3));
  847. if (source4 == null)
  848. throw new ArgumentNullException(nameof(source4));
  849. if (source5 == null)
  850. throw new ArgumentNullException(nameof(source5));
  851. if (source6 == null)
  852. throw new ArgumentNullException(nameof(source6));
  853. if (source7 == null)
  854. throw new ArgumentNullException(nameof(source7));
  855. if (source8 == null)
  856. throw new ArgumentNullException(nameof(source8));
  857. if (source9 == null)
  858. throw new ArgumentNullException(nameof(source9));
  859. if (source10 == null)
  860. throw new ArgumentNullException(nameof(source10));
  861. if (source11 == null)
  862. throw new ArgumentNullException(nameof(source11));
  863. if (source12 == null)
  864. throw new ArgumentNullException(nameof(source12));
  865. if (source13 == null)
  866. throw new ArgumentNullException(nameof(source13));
  867. if (source14 == null)
  868. throw new ArgumentNullException(nameof(source14));
  869. if (selector == null)
  870. throw new ArgumentNullException(nameof(selector));
  871. return Create<TResult>(async observer =>
  872. {
  873. var d = new CompositeAsyncDisposable();
  874. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12, observer13, observer14) = observer.CombineLatest(selector);
  875. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  876. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  877. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  878. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  879. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  880. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  881. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  882. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  883. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  884. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  885. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  886. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  887. var sub13 = source13.SubscribeAsync(observer13).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  888. var sub14 = source14.SubscribeAsync(observer14).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  889. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12, sub13, sub14).ConfigureAwait(false);
  890. return d;
  891. });
  892. }
  893. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, IAsyncObservable<T13> source13, IAsyncObservable<T14> source14, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Task<TResult>> selector)
  894. {
  895. if (source1 == null)
  896. throw new ArgumentNullException(nameof(source1));
  897. if (source2 == null)
  898. throw new ArgumentNullException(nameof(source2));
  899. if (source3 == null)
  900. throw new ArgumentNullException(nameof(source3));
  901. if (source4 == null)
  902. throw new ArgumentNullException(nameof(source4));
  903. if (source5 == null)
  904. throw new ArgumentNullException(nameof(source5));
  905. if (source6 == null)
  906. throw new ArgumentNullException(nameof(source6));
  907. if (source7 == null)
  908. throw new ArgumentNullException(nameof(source7));
  909. if (source8 == null)
  910. throw new ArgumentNullException(nameof(source8));
  911. if (source9 == null)
  912. throw new ArgumentNullException(nameof(source9));
  913. if (source10 == null)
  914. throw new ArgumentNullException(nameof(source10));
  915. if (source11 == null)
  916. throw new ArgumentNullException(nameof(source11));
  917. if (source12 == null)
  918. throw new ArgumentNullException(nameof(source12));
  919. if (source13 == null)
  920. throw new ArgumentNullException(nameof(source13));
  921. if (source14 == null)
  922. throw new ArgumentNullException(nameof(source14));
  923. if (selector == null)
  924. throw new ArgumentNullException(nameof(selector));
  925. return Create<TResult>(async observer =>
  926. {
  927. var d = new CompositeAsyncDisposable();
  928. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12, observer13, observer14) = observer.CombineLatest(selector);
  929. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  930. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  931. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  932. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  933. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  934. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  935. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  936. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  937. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  938. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  939. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  940. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  941. var sub13 = source13.SubscribeAsync(observer13).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  942. var sub14 = source14.SubscribeAsync(observer14).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  943. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12, sub13, sub14).ConfigureAwait(false);
  944. return d;
  945. });
  946. }
  947. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, IAsyncObservable<T13> source13, IAsyncObservable<T14> source14, IAsyncObservable<T15> source15, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> selector)
  948. {
  949. if (source1 == null)
  950. throw new ArgumentNullException(nameof(source1));
  951. if (source2 == null)
  952. throw new ArgumentNullException(nameof(source2));
  953. if (source3 == null)
  954. throw new ArgumentNullException(nameof(source3));
  955. if (source4 == null)
  956. throw new ArgumentNullException(nameof(source4));
  957. if (source5 == null)
  958. throw new ArgumentNullException(nameof(source5));
  959. if (source6 == null)
  960. throw new ArgumentNullException(nameof(source6));
  961. if (source7 == null)
  962. throw new ArgumentNullException(nameof(source7));
  963. if (source8 == null)
  964. throw new ArgumentNullException(nameof(source8));
  965. if (source9 == null)
  966. throw new ArgumentNullException(nameof(source9));
  967. if (source10 == null)
  968. throw new ArgumentNullException(nameof(source10));
  969. if (source11 == null)
  970. throw new ArgumentNullException(nameof(source11));
  971. if (source12 == null)
  972. throw new ArgumentNullException(nameof(source12));
  973. if (source13 == null)
  974. throw new ArgumentNullException(nameof(source13));
  975. if (source14 == null)
  976. throw new ArgumentNullException(nameof(source14));
  977. if (source15 == null)
  978. throw new ArgumentNullException(nameof(source15));
  979. if (selector == null)
  980. throw new ArgumentNullException(nameof(selector));
  981. return Create<TResult>(async observer =>
  982. {
  983. var d = new CompositeAsyncDisposable();
  984. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12, observer13, observer14, observer15) = observer.CombineLatest(selector);
  985. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  986. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  987. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  988. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  989. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  990. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  991. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  992. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  993. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  994. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  995. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  996. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  997. var sub13 = source13.SubscribeAsync(observer13).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  998. var sub14 = source14.SubscribeAsync(observer14).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  999. var sub15 = source15.SubscribeAsync(observer15).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1000. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12, sub13, sub14, sub15).ConfigureAwait(false);
  1001. return d;
  1002. });
  1003. }
  1004. public static IAsyncObservable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, IAsyncObservable<T8> source8, IAsyncObservable<T9> source9, IAsyncObservable<T10> source10, IAsyncObservable<T11> source11, IAsyncObservable<T12> source12, IAsyncObservable<T13> source13, IAsyncObservable<T14> source14, IAsyncObservable<T15> source15, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Task<TResult>> selector)
  1005. {
  1006. if (source1 == null)
  1007. throw new ArgumentNullException(nameof(source1));
  1008. if (source2 == null)
  1009. throw new ArgumentNullException(nameof(source2));
  1010. if (source3 == null)
  1011. throw new ArgumentNullException(nameof(source3));
  1012. if (source4 == null)
  1013. throw new ArgumentNullException(nameof(source4));
  1014. if (source5 == null)
  1015. throw new ArgumentNullException(nameof(source5));
  1016. if (source6 == null)
  1017. throw new ArgumentNullException(nameof(source6));
  1018. if (source7 == null)
  1019. throw new ArgumentNullException(nameof(source7));
  1020. if (source8 == null)
  1021. throw new ArgumentNullException(nameof(source8));
  1022. if (source9 == null)
  1023. throw new ArgumentNullException(nameof(source9));
  1024. if (source10 == null)
  1025. throw new ArgumentNullException(nameof(source10));
  1026. if (source11 == null)
  1027. throw new ArgumentNullException(nameof(source11));
  1028. if (source12 == null)
  1029. throw new ArgumentNullException(nameof(source12));
  1030. if (source13 == null)
  1031. throw new ArgumentNullException(nameof(source13));
  1032. if (source14 == null)
  1033. throw new ArgumentNullException(nameof(source14));
  1034. if (source15 == null)
  1035. throw new ArgumentNullException(nameof(source15));
  1036. if (selector == null)
  1037. throw new ArgumentNullException(nameof(selector));
  1038. return Create<TResult>(async observer =>
  1039. {
  1040. var d = new CompositeAsyncDisposable();
  1041. var (observer1, observer2, observer3, observer4, observer5, observer6, observer7, observer8, observer9, observer10, observer11, observer12, observer13, observer14, observer15) = observer.CombineLatest(selector);
  1042. var sub1 = source1.SubscribeAsync(observer1).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1043. var sub2 = source2.SubscribeAsync(observer2).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1044. var sub3 = source3.SubscribeAsync(observer3).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1045. var sub4 = source4.SubscribeAsync(observer4).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1046. var sub5 = source5.SubscribeAsync(observer5).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1047. var sub6 = source6.SubscribeAsync(observer6).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1048. var sub7 = source7.SubscribeAsync(observer7).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1049. var sub8 = source8.SubscribeAsync(observer8).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1050. var sub9 = source9.SubscribeAsync(observer9).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1051. var sub10 = source10.SubscribeAsync(observer10).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1052. var sub11 = source11.SubscribeAsync(observer11).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1053. var sub12 = source12.SubscribeAsync(observer12).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1054. var sub13 = source13.SubscribeAsync(observer13).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1055. var sub14 = source14.SubscribeAsync(observer14).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1056. var sub15 = source15.SubscribeAsync(observer15).ContinueWith(disposable => d.AddAsync(disposable.Result)).Unwrap();
  1057. await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10, sub11, sub12, sub13, sub14, sub15).ConfigureAwait(false);
  1058. return d;
  1059. });
  1060. }
  1061. }
  1062. partial class AsyncObserver
  1063. {
  1064. public static (IAsyncObserver<T1>, IAsyncObserver<T2>) CombineLatest<T1, T2, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, TResult> selector)
  1065. {
  1066. if (observer == null)
  1067. throw new ArgumentNullException(nameof(observer));
  1068. if (selector == null)
  1069. throw new ArgumentNullException(nameof(selector));
  1070. return CombineLatest<T1, T2, TResult>(observer, (x1, x2) => Task.FromResult(selector(x1, x2)));
  1071. }
  1072. public static (IAsyncObserver<T1>, IAsyncObserver<T2>) CombineLatest<T1, T2, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, Task<TResult>> selector)
  1073. {
  1074. if (observer == null)
  1075. throw new ArgumentNullException(nameof(observer));
  1076. if (selector == null)
  1077. throw new ArgumentNullException(nameof(selector));
  1078. bool allHasValue = false;
  1079. bool hasValue1 = false;
  1080. bool isDone1 = false;
  1081. T1 latestValue1 = default(T1);
  1082. bool hasValue2 = false;
  1083. bool isDone2 = false;
  1084. T2 latestValue2 = default(T2);
  1085. var gate = new AsyncLock();
  1086. return
  1087. (
  1088. Create<T1>(
  1089. async x =>
  1090. {
  1091. using (await gate.LockAsync().ConfigureAwait(false))
  1092. {
  1093. if (!hasValue1)
  1094. {
  1095. hasValue1 = true;
  1096. allHasValue = hasValue1 && hasValue2;
  1097. }
  1098. latestValue1 = x;
  1099. if (allHasValue)
  1100. {
  1101. TResult res;
  1102. try
  1103. {
  1104. res = await selector(latestValue1, latestValue2).ConfigureAwait(false);
  1105. }
  1106. catch (Exception ex)
  1107. {
  1108. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1109. return;
  1110. }
  1111. await observer.OnNextAsync(res).ConfigureAwait(false);
  1112. }
  1113. else if (isDone2)
  1114. {
  1115. await observer.OnCompletedAsync().ConfigureAwait(false);
  1116. }
  1117. }
  1118. },
  1119. async ex =>
  1120. {
  1121. using (await gate.LockAsync().ConfigureAwait(false))
  1122. {
  1123. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1124. }
  1125. },
  1126. async () =>
  1127. {
  1128. using (await gate.LockAsync().ConfigureAwait(false))
  1129. {
  1130. isDone1 = true;
  1131. if (isDone1 && isDone2)
  1132. {
  1133. await observer.OnCompletedAsync().ConfigureAwait(false);
  1134. }
  1135. }
  1136. }
  1137. ),
  1138. Create<T2>(
  1139. async x =>
  1140. {
  1141. using (await gate.LockAsync().ConfigureAwait(false))
  1142. {
  1143. if (!hasValue2)
  1144. {
  1145. hasValue2 = true;
  1146. allHasValue = hasValue1 && hasValue2;
  1147. }
  1148. latestValue2 = x;
  1149. if (allHasValue)
  1150. {
  1151. TResult res;
  1152. try
  1153. {
  1154. res = await selector(latestValue1, latestValue2).ConfigureAwait(false);
  1155. }
  1156. catch (Exception ex)
  1157. {
  1158. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1159. return;
  1160. }
  1161. await observer.OnNextAsync(res).ConfigureAwait(false);
  1162. }
  1163. else if (isDone1)
  1164. {
  1165. await observer.OnCompletedAsync().ConfigureAwait(false);
  1166. }
  1167. }
  1168. },
  1169. async ex =>
  1170. {
  1171. using (await gate.LockAsync().ConfigureAwait(false))
  1172. {
  1173. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1174. }
  1175. },
  1176. async () =>
  1177. {
  1178. using (await gate.LockAsync().ConfigureAwait(false))
  1179. {
  1180. isDone2 = true;
  1181. if (isDone1 && isDone2)
  1182. {
  1183. await observer.OnCompletedAsync().ConfigureAwait(false);
  1184. }
  1185. }
  1186. }
  1187. )
  1188. );
  1189. }
  1190. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>) CombineLatest<T1, T2, T3, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, TResult> selector)
  1191. {
  1192. if (observer == null)
  1193. throw new ArgumentNullException(nameof(observer));
  1194. if (selector == null)
  1195. throw new ArgumentNullException(nameof(selector));
  1196. return CombineLatest<T1, T2, T3, TResult>(observer, (x1, x2, x3) => Task.FromResult(selector(x1, x2, x3)));
  1197. }
  1198. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>) CombineLatest<T1, T2, T3, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, Task<TResult>> selector)
  1199. {
  1200. if (observer == null)
  1201. throw new ArgumentNullException(nameof(observer));
  1202. if (selector == null)
  1203. throw new ArgumentNullException(nameof(selector));
  1204. bool allHasValue = false;
  1205. bool hasValue1 = false;
  1206. bool isDone1 = false;
  1207. T1 latestValue1 = default(T1);
  1208. bool hasValue2 = false;
  1209. bool isDone2 = false;
  1210. T2 latestValue2 = default(T2);
  1211. bool hasValue3 = false;
  1212. bool isDone3 = false;
  1213. T3 latestValue3 = default(T3);
  1214. var gate = new AsyncLock();
  1215. return
  1216. (
  1217. Create<T1>(
  1218. async x =>
  1219. {
  1220. using (await gate.LockAsync().ConfigureAwait(false))
  1221. {
  1222. if (!hasValue1)
  1223. {
  1224. hasValue1 = true;
  1225. allHasValue = hasValue1 && hasValue2 && hasValue3;
  1226. }
  1227. latestValue1 = x;
  1228. if (allHasValue)
  1229. {
  1230. TResult res;
  1231. try
  1232. {
  1233. res = await selector(latestValue1, latestValue2, latestValue3).ConfigureAwait(false);
  1234. }
  1235. catch (Exception ex)
  1236. {
  1237. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1238. return;
  1239. }
  1240. await observer.OnNextAsync(res).ConfigureAwait(false);
  1241. }
  1242. else if (isDone2 && isDone3)
  1243. {
  1244. await observer.OnCompletedAsync().ConfigureAwait(false);
  1245. }
  1246. }
  1247. },
  1248. async ex =>
  1249. {
  1250. using (await gate.LockAsync().ConfigureAwait(false))
  1251. {
  1252. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1253. }
  1254. },
  1255. async () =>
  1256. {
  1257. using (await gate.LockAsync().ConfigureAwait(false))
  1258. {
  1259. isDone1 = true;
  1260. if (isDone1 && isDone2 && isDone3)
  1261. {
  1262. await observer.OnCompletedAsync().ConfigureAwait(false);
  1263. }
  1264. }
  1265. }
  1266. ),
  1267. Create<T2>(
  1268. async x =>
  1269. {
  1270. using (await gate.LockAsync().ConfigureAwait(false))
  1271. {
  1272. if (!hasValue2)
  1273. {
  1274. hasValue2 = true;
  1275. allHasValue = hasValue1 && hasValue2 && hasValue3;
  1276. }
  1277. latestValue2 = x;
  1278. if (allHasValue)
  1279. {
  1280. TResult res;
  1281. try
  1282. {
  1283. res = await selector(latestValue1, latestValue2, latestValue3).ConfigureAwait(false);
  1284. }
  1285. catch (Exception ex)
  1286. {
  1287. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1288. return;
  1289. }
  1290. await observer.OnNextAsync(res).ConfigureAwait(false);
  1291. }
  1292. else if (isDone1 && isDone3)
  1293. {
  1294. await observer.OnCompletedAsync().ConfigureAwait(false);
  1295. }
  1296. }
  1297. },
  1298. async ex =>
  1299. {
  1300. using (await gate.LockAsync().ConfigureAwait(false))
  1301. {
  1302. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1303. }
  1304. },
  1305. async () =>
  1306. {
  1307. using (await gate.LockAsync().ConfigureAwait(false))
  1308. {
  1309. isDone2 = true;
  1310. if (isDone1 && isDone2 && isDone3)
  1311. {
  1312. await observer.OnCompletedAsync().ConfigureAwait(false);
  1313. }
  1314. }
  1315. }
  1316. ),
  1317. Create<T3>(
  1318. async x =>
  1319. {
  1320. using (await gate.LockAsync().ConfigureAwait(false))
  1321. {
  1322. if (!hasValue3)
  1323. {
  1324. hasValue3 = true;
  1325. allHasValue = hasValue1 && hasValue2 && hasValue3;
  1326. }
  1327. latestValue3 = x;
  1328. if (allHasValue)
  1329. {
  1330. TResult res;
  1331. try
  1332. {
  1333. res = await selector(latestValue1, latestValue2, latestValue3).ConfigureAwait(false);
  1334. }
  1335. catch (Exception ex)
  1336. {
  1337. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1338. return;
  1339. }
  1340. await observer.OnNextAsync(res).ConfigureAwait(false);
  1341. }
  1342. else if (isDone1 && isDone2)
  1343. {
  1344. await observer.OnCompletedAsync().ConfigureAwait(false);
  1345. }
  1346. }
  1347. },
  1348. async ex =>
  1349. {
  1350. using (await gate.LockAsync().ConfigureAwait(false))
  1351. {
  1352. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1353. }
  1354. },
  1355. async () =>
  1356. {
  1357. using (await gate.LockAsync().ConfigureAwait(false))
  1358. {
  1359. isDone3 = true;
  1360. if (isDone1 && isDone2 && isDone3)
  1361. {
  1362. await observer.OnCompletedAsync().ConfigureAwait(false);
  1363. }
  1364. }
  1365. }
  1366. )
  1367. );
  1368. }
  1369. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>) CombineLatest<T1, T2, T3, T4, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, TResult> selector)
  1370. {
  1371. if (observer == null)
  1372. throw new ArgumentNullException(nameof(observer));
  1373. if (selector == null)
  1374. throw new ArgumentNullException(nameof(selector));
  1375. return CombineLatest<T1, T2, T3, T4, TResult>(observer, (x1, x2, x3, x4) => Task.FromResult(selector(x1, x2, x3, x4)));
  1376. }
  1377. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>) CombineLatest<T1, T2, T3, T4, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, Task<TResult>> selector)
  1378. {
  1379. if (observer == null)
  1380. throw new ArgumentNullException(nameof(observer));
  1381. if (selector == null)
  1382. throw new ArgumentNullException(nameof(selector));
  1383. bool allHasValue = false;
  1384. bool hasValue1 = false;
  1385. bool isDone1 = false;
  1386. T1 latestValue1 = default(T1);
  1387. bool hasValue2 = false;
  1388. bool isDone2 = false;
  1389. T2 latestValue2 = default(T2);
  1390. bool hasValue3 = false;
  1391. bool isDone3 = false;
  1392. T3 latestValue3 = default(T3);
  1393. bool hasValue4 = false;
  1394. bool isDone4 = false;
  1395. T4 latestValue4 = default(T4);
  1396. var gate = new AsyncLock();
  1397. return
  1398. (
  1399. Create<T1>(
  1400. async x =>
  1401. {
  1402. using (await gate.LockAsync().ConfigureAwait(false))
  1403. {
  1404. if (!hasValue1)
  1405. {
  1406. hasValue1 = true;
  1407. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4;
  1408. }
  1409. latestValue1 = x;
  1410. if (allHasValue)
  1411. {
  1412. TResult res;
  1413. try
  1414. {
  1415. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4).ConfigureAwait(false);
  1416. }
  1417. catch (Exception ex)
  1418. {
  1419. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1420. return;
  1421. }
  1422. await observer.OnNextAsync(res).ConfigureAwait(false);
  1423. }
  1424. else if (isDone2 && isDone3 && isDone4)
  1425. {
  1426. await observer.OnCompletedAsync().ConfigureAwait(false);
  1427. }
  1428. }
  1429. },
  1430. async ex =>
  1431. {
  1432. using (await gate.LockAsync().ConfigureAwait(false))
  1433. {
  1434. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1435. }
  1436. },
  1437. async () =>
  1438. {
  1439. using (await gate.LockAsync().ConfigureAwait(false))
  1440. {
  1441. isDone1 = true;
  1442. if (isDone1 && isDone2 && isDone3 && isDone4)
  1443. {
  1444. await observer.OnCompletedAsync().ConfigureAwait(false);
  1445. }
  1446. }
  1447. }
  1448. ),
  1449. Create<T2>(
  1450. async x =>
  1451. {
  1452. using (await gate.LockAsync().ConfigureAwait(false))
  1453. {
  1454. if (!hasValue2)
  1455. {
  1456. hasValue2 = true;
  1457. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4;
  1458. }
  1459. latestValue2 = x;
  1460. if (allHasValue)
  1461. {
  1462. TResult res;
  1463. try
  1464. {
  1465. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4).ConfigureAwait(false);
  1466. }
  1467. catch (Exception ex)
  1468. {
  1469. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1470. return;
  1471. }
  1472. await observer.OnNextAsync(res).ConfigureAwait(false);
  1473. }
  1474. else if (isDone1 && isDone3 && isDone4)
  1475. {
  1476. await observer.OnCompletedAsync().ConfigureAwait(false);
  1477. }
  1478. }
  1479. },
  1480. async ex =>
  1481. {
  1482. using (await gate.LockAsync().ConfigureAwait(false))
  1483. {
  1484. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1485. }
  1486. },
  1487. async () =>
  1488. {
  1489. using (await gate.LockAsync().ConfigureAwait(false))
  1490. {
  1491. isDone2 = true;
  1492. if (isDone1 && isDone2 && isDone3 && isDone4)
  1493. {
  1494. await observer.OnCompletedAsync().ConfigureAwait(false);
  1495. }
  1496. }
  1497. }
  1498. ),
  1499. Create<T3>(
  1500. async x =>
  1501. {
  1502. using (await gate.LockAsync().ConfigureAwait(false))
  1503. {
  1504. if (!hasValue3)
  1505. {
  1506. hasValue3 = true;
  1507. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4;
  1508. }
  1509. latestValue3 = x;
  1510. if (allHasValue)
  1511. {
  1512. TResult res;
  1513. try
  1514. {
  1515. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4).ConfigureAwait(false);
  1516. }
  1517. catch (Exception ex)
  1518. {
  1519. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1520. return;
  1521. }
  1522. await observer.OnNextAsync(res).ConfigureAwait(false);
  1523. }
  1524. else if (isDone1 && isDone2 && isDone4)
  1525. {
  1526. await observer.OnCompletedAsync().ConfigureAwait(false);
  1527. }
  1528. }
  1529. },
  1530. async ex =>
  1531. {
  1532. using (await gate.LockAsync().ConfigureAwait(false))
  1533. {
  1534. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1535. }
  1536. },
  1537. async () =>
  1538. {
  1539. using (await gate.LockAsync().ConfigureAwait(false))
  1540. {
  1541. isDone3 = true;
  1542. if (isDone1 && isDone2 && isDone3 && isDone4)
  1543. {
  1544. await observer.OnCompletedAsync().ConfigureAwait(false);
  1545. }
  1546. }
  1547. }
  1548. ),
  1549. Create<T4>(
  1550. async x =>
  1551. {
  1552. using (await gate.LockAsync().ConfigureAwait(false))
  1553. {
  1554. if (!hasValue4)
  1555. {
  1556. hasValue4 = true;
  1557. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4;
  1558. }
  1559. latestValue4 = x;
  1560. if (allHasValue)
  1561. {
  1562. TResult res;
  1563. try
  1564. {
  1565. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4).ConfigureAwait(false);
  1566. }
  1567. catch (Exception ex)
  1568. {
  1569. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1570. return;
  1571. }
  1572. await observer.OnNextAsync(res).ConfigureAwait(false);
  1573. }
  1574. else if (isDone1 && isDone2 && isDone3)
  1575. {
  1576. await observer.OnCompletedAsync().ConfigureAwait(false);
  1577. }
  1578. }
  1579. },
  1580. async ex =>
  1581. {
  1582. using (await gate.LockAsync().ConfigureAwait(false))
  1583. {
  1584. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1585. }
  1586. },
  1587. async () =>
  1588. {
  1589. using (await gate.LockAsync().ConfigureAwait(false))
  1590. {
  1591. isDone4 = true;
  1592. if (isDone1 && isDone2 && isDone3 && isDone4)
  1593. {
  1594. await observer.OnCompletedAsync().ConfigureAwait(false);
  1595. }
  1596. }
  1597. }
  1598. )
  1599. );
  1600. }
  1601. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>) CombineLatest<T1, T2, T3, T4, T5, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, TResult> selector)
  1602. {
  1603. if (observer == null)
  1604. throw new ArgumentNullException(nameof(observer));
  1605. if (selector == null)
  1606. throw new ArgumentNullException(nameof(selector));
  1607. return CombineLatest<T1, T2, T3, T4, T5, TResult>(observer, (x1, x2, x3, x4, x5) => Task.FromResult(selector(x1, x2, x3, x4, x5)));
  1608. }
  1609. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>) CombineLatest<T1, T2, T3, T4, T5, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, Task<TResult>> selector)
  1610. {
  1611. if (observer == null)
  1612. throw new ArgumentNullException(nameof(observer));
  1613. if (selector == null)
  1614. throw new ArgumentNullException(nameof(selector));
  1615. bool allHasValue = false;
  1616. bool hasValue1 = false;
  1617. bool isDone1 = false;
  1618. T1 latestValue1 = default(T1);
  1619. bool hasValue2 = false;
  1620. bool isDone2 = false;
  1621. T2 latestValue2 = default(T2);
  1622. bool hasValue3 = false;
  1623. bool isDone3 = false;
  1624. T3 latestValue3 = default(T3);
  1625. bool hasValue4 = false;
  1626. bool isDone4 = false;
  1627. T4 latestValue4 = default(T4);
  1628. bool hasValue5 = false;
  1629. bool isDone5 = false;
  1630. T5 latestValue5 = default(T5);
  1631. var gate = new AsyncLock();
  1632. return
  1633. (
  1634. Create<T1>(
  1635. async x =>
  1636. {
  1637. using (await gate.LockAsync().ConfigureAwait(false))
  1638. {
  1639. if (!hasValue1)
  1640. {
  1641. hasValue1 = true;
  1642. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5;
  1643. }
  1644. latestValue1 = x;
  1645. if (allHasValue)
  1646. {
  1647. TResult res;
  1648. try
  1649. {
  1650. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5).ConfigureAwait(false);
  1651. }
  1652. catch (Exception ex)
  1653. {
  1654. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1655. return;
  1656. }
  1657. await observer.OnNextAsync(res).ConfigureAwait(false);
  1658. }
  1659. else if (isDone2 && isDone3 && isDone4 && isDone5)
  1660. {
  1661. await observer.OnCompletedAsync().ConfigureAwait(false);
  1662. }
  1663. }
  1664. },
  1665. async ex =>
  1666. {
  1667. using (await gate.LockAsync().ConfigureAwait(false))
  1668. {
  1669. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1670. }
  1671. },
  1672. async () =>
  1673. {
  1674. using (await gate.LockAsync().ConfigureAwait(false))
  1675. {
  1676. isDone1 = true;
  1677. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5)
  1678. {
  1679. await observer.OnCompletedAsync().ConfigureAwait(false);
  1680. }
  1681. }
  1682. }
  1683. ),
  1684. Create<T2>(
  1685. async x =>
  1686. {
  1687. using (await gate.LockAsync().ConfigureAwait(false))
  1688. {
  1689. if (!hasValue2)
  1690. {
  1691. hasValue2 = true;
  1692. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5;
  1693. }
  1694. latestValue2 = x;
  1695. if (allHasValue)
  1696. {
  1697. TResult res;
  1698. try
  1699. {
  1700. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5).ConfigureAwait(false);
  1701. }
  1702. catch (Exception ex)
  1703. {
  1704. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1705. return;
  1706. }
  1707. await observer.OnNextAsync(res).ConfigureAwait(false);
  1708. }
  1709. else if (isDone1 && isDone3 && isDone4 && isDone5)
  1710. {
  1711. await observer.OnCompletedAsync().ConfigureAwait(false);
  1712. }
  1713. }
  1714. },
  1715. async ex =>
  1716. {
  1717. using (await gate.LockAsync().ConfigureAwait(false))
  1718. {
  1719. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1720. }
  1721. },
  1722. async () =>
  1723. {
  1724. using (await gate.LockAsync().ConfigureAwait(false))
  1725. {
  1726. isDone2 = true;
  1727. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5)
  1728. {
  1729. await observer.OnCompletedAsync().ConfigureAwait(false);
  1730. }
  1731. }
  1732. }
  1733. ),
  1734. Create<T3>(
  1735. async x =>
  1736. {
  1737. using (await gate.LockAsync().ConfigureAwait(false))
  1738. {
  1739. if (!hasValue3)
  1740. {
  1741. hasValue3 = true;
  1742. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5;
  1743. }
  1744. latestValue3 = x;
  1745. if (allHasValue)
  1746. {
  1747. TResult res;
  1748. try
  1749. {
  1750. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5).ConfigureAwait(false);
  1751. }
  1752. catch (Exception ex)
  1753. {
  1754. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1755. return;
  1756. }
  1757. await observer.OnNextAsync(res).ConfigureAwait(false);
  1758. }
  1759. else if (isDone1 && isDone2 && isDone4 && isDone5)
  1760. {
  1761. await observer.OnCompletedAsync().ConfigureAwait(false);
  1762. }
  1763. }
  1764. },
  1765. async ex =>
  1766. {
  1767. using (await gate.LockAsync().ConfigureAwait(false))
  1768. {
  1769. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1770. }
  1771. },
  1772. async () =>
  1773. {
  1774. using (await gate.LockAsync().ConfigureAwait(false))
  1775. {
  1776. isDone3 = true;
  1777. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5)
  1778. {
  1779. await observer.OnCompletedAsync().ConfigureAwait(false);
  1780. }
  1781. }
  1782. }
  1783. ),
  1784. Create<T4>(
  1785. async x =>
  1786. {
  1787. using (await gate.LockAsync().ConfigureAwait(false))
  1788. {
  1789. if (!hasValue4)
  1790. {
  1791. hasValue4 = true;
  1792. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5;
  1793. }
  1794. latestValue4 = x;
  1795. if (allHasValue)
  1796. {
  1797. TResult res;
  1798. try
  1799. {
  1800. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5).ConfigureAwait(false);
  1801. }
  1802. catch (Exception ex)
  1803. {
  1804. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1805. return;
  1806. }
  1807. await observer.OnNextAsync(res).ConfigureAwait(false);
  1808. }
  1809. else if (isDone1 && isDone2 && isDone3 && isDone5)
  1810. {
  1811. await observer.OnCompletedAsync().ConfigureAwait(false);
  1812. }
  1813. }
  1814. },
  1815. async ex =>
  1816. {
  1817. using (await gate.LockAsync().ConfigureAwait(false))
  1818. {
  1819. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1820. }
  1821. },
  1822. async () =>
  1823. {
  1824. using (await gate.LockAsync().ConfigureAwait(false))
  1825. {
  1826. isDone4 = true;
  1827. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5)
  1828. {
  1829. await observer.OnCompletedAsync().ConfigureAwait(false);
  1830. }
  1831. }
  1832. }
  1833. ),
  1834. Create<T5>(
  1835. async x =>
  1836. {
  1837. using (await gate.LockAsync().ConfigureAwait(false))
  1838. {
  1839. if (!hasValue5)
  1840. {
  1841. hasValue5 = true;
  1842. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5;
  1843. }
  1844. latestValue5 = x;
  1845. if (allHasValue)
  1846. {
  1847. TResult res;
  1848. try
  1849. {
  1850. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5).ConfigureAwait(false);
  1851. }
  1852. catch (Exception ex)
  1853. {
  1854. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1855. return;
  1856. }
  1857. await observer.OnNextAsync(res).ConfigureAwait(false);
  1858. }
  1859. else if (isDone1 && isDone2 && isDone3 && isDone4)
  1860. {
  1861. await observer.OnCompletedAsync().ConfigureAwait(false);
  1862. }
  1863. }
  1864. },
  1865. async ex =>
  1866. {
  1867. using (await gate.LockAsync().ConfigureAwait(false))
  1868. {
  1869. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1870. }
  1871. },
  1872. async () =>
  1873. {
  1874. using (await gate.LockAsync().ConfigureAwait(false))
  1875. {
  1876. isDone5 = true;
  1877. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5)
  1878. {
  1879. await observer.OnCompletedAsync().ConfigureAwait(false);
  1880. }
  1881. }
  1882. }
  1883. )
  1884. );
  1885. }
  1886. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>) CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, TResult> selector)
  1887. {
  1888. if (observer == null)
  1889. throw new ArgumentNullException(nameof(observer));
  1890. if (selector == null)
  1891. throw new ArgumentNullException(nameof(selector));
  1892. return CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(observer, (x1, x2, x3, x4, x5, x6) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6)));
  1893. }
  1894. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>) CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, Task<TResult>> selector)
  1895. {
  1896. if (observer == null)
  1897. throw new ArgumentNullException(nameof(observer));
  1898. if (selector == null)
  1899. throw new ArgumentNullException(nameof(selector));
  1900. bool allHasValue = false;
  1901. bool hasValue1 = false;
  1902. bool isDone1 = false;
  1903. T1 latestValue1 = default(T1);
  1904. bool hasValue2 = false;
  1905. bool isDone2 = false;
  1906. T2 latestValue2 = default(T2);
  1907. bool hasValue3 = false;
  1908. bool isDone3 = false;
  1909. T3 latestValue3 = default(T3);
  1910. bool hasValue4 = false;
  1911. bool isDone4 = false;
  1912. T4 latestValue4 = default(T4);
  1913. bool hasValue5 = false;
  1914. bool isDone5 = false;
  1915. T5 latestValue5 = default(T5);
  1916. bool hasValue6 = false;
  1917. bool isDone6 = false;
  1918. T6 latestValue6 = default(T6);
  1919. var gate = new AsyncLock();
  1920. return
  1921. (
  1922. Create<T1>(
  1923. async x =>
  1924. {
  1925. using (await gate.LockAsync().ConfigureAwait(false))
  1926. {
  1927. if (!hasValue1)
  1928. {
  1929. hasValue1 = true;
  1930. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6;
  1931. }
  1932. latestValue1 = x;
  1933. if (allHasValue)
  1934. {
  1935. TResult res;
  1936. try
  1937. {
  1938. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6).ConfigureAwait(false);
  1939. }
  1940. catch (Exception ex)
  1941. {
  1942. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1943. return;
  1944. }
  1945. await observer.OnNextAsync(res).ConfigureAwait(false);
  1946. }
  1947. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  1948. {
  1949. await observer.OnCompletedAsync().ConfigureAwait(false);
  1950. }
  1951. }
  1952. },
  1953. async ex =>
  1954. {
  1955. using (await gate.LockAsync().ConfigureAwait(false))
  1956. {
  1957. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1958. }
  1959. },
  1960. async () =>
  1961. {
  1962. using (await gate.LockAsync().ConfigureAwait(false))
  1963. {
  1964. isDone1 = true;
  1965. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  1966. {
  1967. await observer.OnCompletedAsync().ConfigureAwait(false);
  1968. }
  1969. }
  1970. }
  1971. ),
  1972. Create<T2>(
  1973. async x =>
  1974. {
  1975. using (await gate.LockAsync().ConfigureAwait(false))
  1976. {
  1977. if (!hasValue2)
  1978. {
  1979. hasValue2 = true;
  1980. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6;
  1981. }
  1982. latestValue2 = x;
  1983. if (allHasValue)
  1984. {
  1985. TResult res;
  1986. try
  1987. {
  1988. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6).ConfigureAwait(false);
  1989. }
  1990. catch (Exception ex)
  1991. {
  1992. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  1993. return;
  1994. }
  1995. await observer.OnNextAsync(res).ConfigureAwait(false);
  1996. }
  1997. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6)
  1998. {
  1999. await observer.OnCompletedAsync().ConfigureAwait(false);
  2000. }
  2001. }
  2002. },
  2003. async ex =>
  2004. {
  2005. using (await gate.LockAsync().ConfigureAwait(false))
  2006. {
  2007. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2008. }
  2009. },
  2010. async () =>
  2011. {
  2012. using (await gate.LockAsync().ConfigureAwait(false))
  2013. {
  2014. isDone2 = true;
  2015. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  2016. {
  2017. await observer.OnCompletedAsync().ConfigureAwait(false);
  2018. }
  2019. }
  2020. }
  2021. ),
  2022. Create<T3>(
  2023. async x =>
  2024. {
  2025. using (await gate.LockAsync().ConfigureAwait(false))
  2026. {
  2027. if (!hasValue3)
  2028. {
  2029. hasValue3 = true;
  2030. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6;
  2031. }
  2032. latestValue3 = x;
  2033. if (allHasValue)
  2034. {
  2035. TResult res;
  2036. try
  2037. {
  2038. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6).ConfigureAwait(false);
  2039. }
  2040. catch (Exception ex)
  2041. {
  2042. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2043. return;
  2044. }
  2045. await observer.OnNextAsync(res).ConfigureAwait(false);
  2046. }
  2047. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6)
  2048. {
  2049. await observer.OnCompletedAsync().ConfigureAwait(false);
  2050. }
  2051. }
  2052. },
  2053. async ex =>
  2054. {
  2055. using (await gate.LockAsync().ConfigureAwait(false))
  2056. {
  2057. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2058. }
  2059. },
  2060. async () =>
  2061. {
  2062. using (await gate.LockAsync().ConfigureAwait(false))
  2063. {
  2064. isDone3 = true;
  2065. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  2066. {
  2067. await observer.OnCompletedAsync().ConfigureAwait(false);
  2068. }
  2069. }
  2070. }
  2071. ),
  2072. Create<T4>(
  2073. async x =>
  2074. {
  2075. using (await gate.LockAsync().ConfigureAwait(false))
  2076. {
  2077. if (!hasValue4)
  2078. {
  2079. hasValue4 = true;
  2080. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6;
  2081. }
  2082. latestValue4 = x;
  2083. if (allHasValue)
  2084. {
  2085. TResult res;
  2086. try
  2087. {
  2088. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6).ConfigureAwait(false);
  2089. }
  2090. catch (Exception ex)
  2091. {
  2092. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2093. return;
  2094. }
  2095. await observer.OnNextAsync(res).ConfigureAwait(false);
  2096. }
  2097. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6)
  2098. {
  2099. await observer.OnCompletedAsync().ConfigureAwait(false);
  2100. }
  2101. }
  2102. },
  2103. async ex =>
  2104. {
  2105. using (await gate.LockAsync().ConfigureAwait(false))
  2106. {
  2107. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2108. }
  2109. },
  2110. async () =>
  2111. {
  2112. using (await gate.LockAsync().ConfigureAwait(false))
  2113. {
  2114. isDone4 = true;
  2115. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  2116. {
  2117. await observer.OnCompletedAsync().ConfigureAwait(false);
  2118. }
  2119. }
  2120. }
  2121. ),
  2122. Create<T5>(
  2123. async x =>
  2124. {
  2125. using (await gate.LockAsync().ConfigureAwait(false))
  2126. {
  2127. if (!hasValue5)
  2128. {
  2129. hasValue5 = true;
  2130. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6;
  2131. }
  2132. latestValue5 = x;
  2133. if (allHasValue)
  2134. {
  2135. TResult res;
  2136. try
  2137. {
  2138. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6).ConfigureAwait(false);
  2139. }
  2140. catch (Exception ex)
  2141. {
  2142. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2143. return;
  2144. }
  2145. await observer.OnNextAsync(res).ConfigureAwait(false);
  2146. }
  2147. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6)
  2148. {
  2149. await observer.OnCompletedAsync().ConfigureAwait(false);
  2150. }
  2151. }
  2152. },
  2153. async ex =>
  2154. {
  2155. using (await gate.LockAsync().ConfigureAwait(false))
  2156. {
  2157. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2158. }
  2159. },
  2160. async () =>
  2161. {
  2162. using (await gate.LockAsync().ConfigureAwait(false))
  2163. {
  2164. isDone5 = true;
  2165. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  2166. {
  2167. await observer.OnCompletedAsync().ConfigureAwait(false);
  2168. }
  2169. }
  2170. }
  2171. ),
  2172. Create<T6>(
  2173. async x =>
  2174. {
  2175. using (await gate.LockAsync().ConfigureAwait(false))
  2176. {
  2177. if (!hasValue6)
  2178. {
  2179. hasValue6 = true;
  2180. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6;
  2181. }
  2182. latestValue6 = x;
  2183. if (allHasValue)
  2184. {
  2185. TResult res;
  2186. try
  2187. {
  2188. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6).ConfigureAwait(false);
  2189. }
  2190. catch (Exception ex)
  2191. {
  2192. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2193. return;
  2194. }
  2195. await observer.OnNextAsync(res).ConfigureAwait(false);
  2196. }
  2197. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5)
  2198. {
  2199. await observer.OnCompletedAsync().ConfigureAwait(false);
  2200. }
  2201. }
  2202. },
  2203. async ex =>
  2204. {
  2205. using (await gate.LockAsync().ConfigureAwait(false))
  2206. {
  2207. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2208. }
  2209. },
  2210. async () =>
  2211. {
  2212. using (await gate.LockAsync().ConfigureAwait(false))
  2213. {
  2214. isDone6 = true;
  2215. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  2216. {
  2217. await observer.OnCompletedAsync().ConfigureAwait(false);
  2218. }
  2219. }
  2220. }
  2221. )
  2222. );
  2223. }
  2224. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, TResult> selector)
  2225. {
  2226. if (observer == null)
  2227. throw new ArgumentNullException(nameof(observer));
  2228. if (selector == null)
  2229. throw new ArgumentNullException(nameof(selector));
  2230. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7)));
  2231. }
  2232. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, Task<TResult>> selector)
  2233. {
  2234. if (observer == null)
  2235. throw new ArgumentNullException(nameof(observer));
  2236. if (selector == null)
  2237. throw new ArgumentNullException(nameof(selector));
  2238. bool allHasValue = false;
  2239. bool hasValue1 = false;
  2240. bool isDone1 = false;
  2241. T1 latestValue1 = default(T1);
  2242. bool hasValue2 = false;
  2243. bool isDone2 = false;
  2244. T2 latestValue2 = default(T2);
  2245. bool hasValue3 = false;
  2246. bool isDone3 = false;
  2247. T3 latestValue3 = default(T3);
  2248. bool hasValue4 = false;
  2249. bool isDone4 = false;
  2250. T4 latestValue4 = default(T4);
  2251. bool hasValue5 = false;
  2252. bool isDone5 = false;
  2253. T5 latestValue5 = default(T5);
  2254. bool hasValue6 = false;
  2255. bool isDone6 = false;
  2256. T6 latestValue6 = default(T6);
  2257. bool hasValue7 = false;
  2258. bool isDone7 = false;
  2259. T7 latestValue7 = default(T7);
  2260. var gate = new AsyncLock();
  2261. return
  2262. (
  2263. Create<T1>(
  2264. async x =>
  2265. {
  2266. using (await gate.LockAsync().ConfigureAwait(false))
  2267. {
  2268. if (!hasValue1)
  2269. {
  2270. hasValue1 = true;
  2271. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7;
  2272. }
  2273. latestValue1 = x;
  2274. if (allHasValue)
  2275. {
  2276. TResult res;
  2277. try
  2278. {
  2279. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7).ConfigureAwait(false);
  2280. }
  2281. catch (Exception ex)
  2282. {
  2283. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2284. return;
  2285. }
  2286. await observer.OnNextAsync(res).ConfigureAwait(false);
  2287. }
  2288. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2289. {
  2290. await observer.OnCompletedAsync().ConfigureAwait(false);
  2291. }
  2292. }
  2293. },
  2294. async ex =>
  2295. {
  2296. using (await gate.LockAsync().ConfigureAwait(false))
  2297. {
  2298. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2299. }
  2300. },
  2301. async () =>
  2302. {
  2303. using (await gate.LockAsync().ConfigureAwait(false))
  2304. {
  2305. isDone1 = true;
  2306. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2307. {
  2308. await observer.OnCompletedAsync().ConfigureAwait(false);
  2309. }
  2310. }
  2311. }
  2312. ),
  2313. Create<T2>(
  2314. async x =>
  2315. {
  2316. using (await gate.LockAsync().ConfigureAwait(false))
  2317. {
  2318. if (!hasValue2)
  2319. {
  2320. hasValue2 = true;
  2321. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7;
  2322. }
  2323. latestValue2 = x;
  2324. if (allHasValue)
  2325. {
  2326. TResult res;
  2327. try
  2328. {
  2329. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7).ConfigureAwait(false);
  2330. }
  2331. catch (Exception ex)
  2332. {
  2333. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2334. return;
  2335. }
  2336. await observer.OnNextAsync(res).ConfigureAwait(false);
  2337. }
  2338. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2339. {
  2340. await observer.OnCompletedAsync().ConfigureAwait(false);
  2341. }
  2342. }
  2343. },
  2344. async ex =>
  2345. {
  2346. using (await gate.LockAsync().ConfigureAwait(false))
  2347. {
  2348. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2349. }
  2350. },
  2351. async () =>
  2352. {
  2353. using (await gate.LockAsync().ConfigureAwait(false))
  2354. {
  2355. isDone2 = true;
  2356. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2357. {
  2358. await observer.OnCompletedAsync().ConfigureAwait(false);
  2359. }
  2360. }
  2361. }
  2362. ),
  2363. Create<T3>(
  2364. async x =>
  2365. {
  2366. using (await gate.LockAsync().ConfigureAwait(false))
  2367. {
  2368. if (!hasValue3)
  2369. {
  2370. hasValue3 = true;
  2371. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7;
  2372. }
  2373. latestValue3 = x;
  2374. if (allHasValue)
  2375. {
  2376. TResult res;
  2377. try
  2378. {
  2379. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7).ConfigureAwait(false);
  2380. }
  2381. catch (Exception ex)
  2382. {
  2383. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2384. return;
  2385. }
  2386. await observer.OnNextAsync(res).ConfigureAwait(false);
  2387. }
  2388. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7)
  2389. {
  2390. await observer.OnCompletedAsync().ConfigureAwait(false);
  2391. }
  2392. }
  2393. },
  2394. async ex =>
  2395. {
  2396. using (await gate.LockAsync().ConfigureAwait(false))
  2397. {
  2398. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2399. }
  2400. },
  2401. async () =>
  2402. {
  2403. using (await gate.LockAsync().ConfigureAwait(false))
  2404. {
  2405. isDone3 = true;
  2406. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2407. {
  2408. await observer.OnCompletedAsync().ConfigureAwait(false);
  2409. }
  2410. }
  2411. }
  2412. ),
  2413. Create<T4>(
  2414. async x =>
  2415. {
  2416. using (await gate.LockAsync().ConfigureAwait(false))
  2417. {
  2418. if (!hasValue4)
  2419. {
  2420. hasValue4 = true;
  2421. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7;
  2422. }
  2423. latestValue4 = x;
  2424. if (allHasValue)
  2425. {
  2426. TResult res;
  2427. try
  2428. {
  2429. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7).ConfigureAwait(false);
  2430. }
  2431. catch (Exception ex)
  2432. {
  2433. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2434. return;
  2435. }
  2436. await observer.OnNextAsync(res).ConfigureAwait(false);
  2437. }
  2438. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7)
  2439. {
  2440. await observer.OnCompletedAsync().ConfigureAwait(false);
  2441. }
  2442. }
  2443. },
  2444. async ex =>
  2445. {
  2446. using (await gate.LockAsync().ConfigureAwait(false))
  2447. {
  2448. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2449. }
  2450. },
  2451. async () =>
  2452. {
  2453. using (await gate.LockAsync().ConfigureAwait(false))
  2454. {
  2455. isDone4 = true;
  2456. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2457. {
  2458. await observer.OnCompletedAsync().ConfigureAwait(false);
  2459. }
  2460. }
  2461. }
  2462. ),
  2463. Create<T5>(
  2464. async x =>
  2465. {
  2466. using (await gate.LockAsync().ConfigureAwait(false))
  2467. {
  2468. if (!hasValue5)
  2469. {
  2470. hasValue5 = true;
  2471. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7;
  2472. }
  2473. latestValue5 = x;
  2474. if (allHasValue)
  2475. {
  2476. TResult res;
  2477. try
  2478. {
  2479. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7).ConfigureAwait(false);
  2480. }
  2481. catch (Exception ex)
  2482. {
  2483. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2484. return;
  2485. }
  2486. await observer.OnNextAsync(res).ConfigureAwait(false);
  2487. }
  2488. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7)
  2489. {
  2490. await observer.OnCompletedAsync().ConfigureAwait(false);
  2491. }
  2492. }
  2493. },
  2494. async ex =>
  2495. {
  2496. using (await gate.LockAsync().ConfigureAwait(false))
  2497. {
  2498. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2499. }
  2500. },
  2501. async () =>
  2502. {
  2503. using (await gate.LockAsync().ConfigureAwait(false))
  2504. {
  2505. isDone5 = true;
  2506. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2507. {
  2508. await observer.OnCompletedAsync().ConfigureAwait(false);
  2509. }
  2510. }
  2511. }
  2512. ),
  2513. Create<T6>(
  2514. async x =>
  2515. {
  2516. using (await gate.LockAsync().ConfigureAwait(false))
  2517. {
  2518. if (!hasValue6)
  2519. {
  2520. hasValue6 = true;
  2521. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7;
  2522. }
  2523. latestValue6 = x;
  2524. if (allHasValue)
  2525. {
  2526. TResult res;
  2527. try
  2528. {
  2529. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7).ConfigureAwait(false);
  2530. }
  2531. catch (Exception ex)
  2532. {
  2533. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2534. return;
  2535. }
  2536. await observer.OnNextAsync(res).ConfigureAwait(false);
  2537. }
  2538. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7)
  2539. {
  2540. await observer.OnCompletedAsync().ConfigureAwait(false);
  2541. }
  2542. }
  2543. },
  2544. async ex =>
  2545. {
  2546. using (await gate.LockAsync().ConfigureAwait(false))
  2547. {
  2548. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2549. }
  2550. },
  2551. async () =>
  2552. {
  2553. using (await gate.LockAsync().ConfigureAwait(false))
  2554. {
  2555. isDone6 = true;
  2556. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2557. {
  2558. await observer.OnCompletedAsync().ConfigureAwait(false);
  2559. }
  2560. }
  2561. }
  2562. ),
  2563. Create<T7>(
  2564. async x =>
  2565. {
  2566. using (await gate.LockAsync().ConfigureAwait(false))
  2567. {
  2568. if (!hasValue7)
  2569. {
  2570. hasValue7 = true;
  2571. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7;
  2572. }
  2573. latestValue7 = x;
  2574. if (allHasValue)
  2575. {
  2576. TResult res;
  2577. try
  2578. {
  2579. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7).ConfigureAwait(false);
  2580. }
  2581. catch (Exception ex)
  2582. {
  2583. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2584. return;
  2585. }
  2586. await observer.OnNextAsync(res).ConfigureAwait(false);
  2587. }
  2588. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6)
  2589. {
  2590. await observer.OnCompletedAsync().ConfigureAwait(false);
  2591. }
  2592. }
  2593. },
  2594. async ex =>
  2595. {
  2596. using (await gate.LockAsync().ConfigureAwait(false))
  2597. {
  2598. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2599. }
  2600. },
  2601. async () =>
  2602. {
  2603. using (await gate.LockAsync().ConfigureAwait(false))
  2604. {
  2605. isDone7 = true;
  2606. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  2607. {
  2608. await observer.OnCompletedAsync().ConfigureAwait(false);
  2609. }
  2610. }
  2611. }
  2612. )
  2613. );
  2614. }
  2615. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> selector)
  2616. {
  2617. if (observer == null)
  2618. throw new ArgumentNullException(nameof(observer));
  2619. if (selector == null)
  2620. throw new ArgumentNullException(nameof(selector));
  2621. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8)));
  2622. }
  2623. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, Task<TResult>> selector)
  2624. {
  2625. if (observer == null)
  2626. throw new ArgumentNullException(nameof(observer));
  2627. if (selector == null)
  2628. throw new ArgumentNullException(nameof(selector));
  2629. bool allHasValue = false;
  2630. bool hasValue1 = false;
  2631. bool isDone1 = false;
  2632. T1 latestValue1 = default(T1);
  2633. bool hasValue2 = false;
  2634. bool isDone2 = false;
  2635. T2 latestValue2 = default(T2);
  2636. bool hasValue3 = false;
  2637. bool isDone3 = false;
  2638. T3 latestValue3 = default(T3);
  2639. bool hasValue4 = false;
  2640. bool isDone4 = false;
  2641. T4 latestValue4 = default(T4);
  2642. bool hasValue5 = false;
  2643. bool isDone5 = false;
  2644. T5 latestValue5 = default(T5);
  2645. bool hasValue6 = false;
  2646. bool isDone6 = false;
  2647. T6 latestValue6 = default(T6);
  2648. bool hasValue7 = false;
  2649. bool isDone7 = false;
  2650. T7 latestValue7 = default(T7);
  2651. bool hasValue8 = false;
  2652. bool isDone8 = false;
  2653. T8 latestValue8 = default(T8);
  2654. var gate = new AsyncLock();
  2655. return
  2656. (
  2657. Create<T1>(
  2658. async x =>
  2659. {
  2660. using (await gate.LockAsync().ConfigureAwait(false))
  2661. {
  2662. if (!hasValue1)
  2663. {
  2664. hasValue1 = true;
  2665. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  2666. }
  2667. latestValue1 = x;
  2668. if (allHasValue)
  2669. {
  2670. TResult res;
  2671. try
  2672. {
  2673. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  2674. }
  2675. catch (Exception ex)
  2676. {
  2677. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2678. return;
  2679. }
  2680. await observer.OnNextAsync(res).ConfigureAwait(false);
  2681. }
  2682. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2683. {
  2684. await observer.OnCompletedAsync().ConfigureAwait(false);
  2685. }
  2686. }
  2687. },
  2688. async ex =>
  2689. {
  2690. using (await gate.LockAsync().ConfigureAwait(false))
  2691. {
  2692. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2693. }
  2694. },
  2695. async () =>
  2696. {
  2697. using (await gate.LockAsync().ConfigureAwait(false))
  2698. {
  2699. isDone1 = true;
  2700. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2701. {
  2702. await observer.OnCompletedAsync().ConfigureAwait(false);
  2703. }
  2704. }
  2705. }
  2706. ),
  2707. Create<T2>(
  2708. async x =>
  2709. {
  2710. using (await gate.LockAsync().ConfigureAwait(false))
  2711. {
  2712. if (!hasValue2)
  2713. {
  2714. hasValue2 = true;
  2715. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  2716. }
  2717. latestValue2 = x;
  2718. if (allHasValue)
  2719. {
  2720. TResult res;
  2721. try
  2722. {
  2723. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  2724. }
  2725. catch (Exception ex)
  2726. {
  2727. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2728. return;
  2729. }
  2730. await observer.OnNextAsync(res).ConfigureAwait(false);
  2731. }
  2732. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2733. {
  2734. await observer.OnCompletedAsync().ConfigureAwait(false);
  2735. }
  2736. }
  2737. },
  2738. async ex =>
  2739. {
  2740. using (await gate.LockAsync().ConfigureAwait(false))
  2741. {
  2742. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2743. }
  2744. },
  2745. async () =>
  2746. {
  2747. using (await gate.LockAsync().ConfigureAwait(false))
  2748. {
  2749. isDone2 = true;
  2750. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2751. {
  2752. await observer.OnCompletedAsync().ConfigureAwait(false);
  2753. }
  2754. }
  2755. }
  2756. ),
  2757. Create<T3>(
  2758. async x =>
  2759. {
  2760. using (await gate.LockAsync().ConfigureAwait(false))
  2761. {
  2762. if (!hasValue3)
  2763. {
  2764. hasValue3 = true;
  2765. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  2766. }
  2767. latestValue3 = x;
  2768. if (allHasValue)
  2769. {
  2770. TResult res;
  2771. try
  2772. {
  2773. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  2774. }
  2775. catch (Exception ex)
  2776. {
  2777. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2778. return;
  2779. }
  2780. await observer.OnNextAsync(res).ConfigureAwait(false);
  2781. }
  2782. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2783. {
  2784. await observer.OnCompletedAsync().ConfigureAwait(false);
  2785. }
  2786. }
  2787. },
  2788. async ex =>
  2789. {
  2790. using (await gate.LockAsync().ConfigureAwait(false))
  2791. {
  2792. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2793. }
  2794. },
  2795. async () =>
  2796. {
  2797. using (await gate.LockAsync().ConfigureAwait(false))
  2798. {
  2799. isDone3 = true;
  2800. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2801. {
  2802. await observer.OnCompletedAsync().ConfigureAwait(false);
  2803. }
  2804. }
  2805. }
  2806. ),
  2807. Create<T4>(
  2808. async x =>
  2809. {
  2810. using (await gate.LockAsync().ConfigureAwait(false))
  2811. {
  2812. if (!hasValue4)
  2813. {
  2814. hasValue4 = true;
  2815. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  2816. }
  2817. latestValue4 = x;
  2818. if (allHasValue)
  2819. {
  2820. TResult res;
  2821. try
  2822. {
  2823. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  2824. }
  2825. catch (Exception ex)
  2826. {
  2827. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2828. return;
  2829. }
  2830. await observer.OnNextAsync(res).ConfigureAwait(false);
  2831. }
  2832. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8)
  2833. {
  2834. await observer.OnCompletedAsync().ConfigureAwait(false);
  2835. }
  2836. }
  2837. },
  2838. async ex =>
  2839. {
  2840. using (await gate.LockAsync().ConfigureAwait(false))
  2841. {
  2842. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2843. }
  2844. },
  2845. async () =>
  2846. {
  2847. using (await gate.LockAsync().ConfigureAwait(false))
  2848. {
  2849. isDone4 = true;
  2850. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2851. {
  2852. await observer.OnCompletedAsync().ConfigureAwait(false);
  2853. }
  2854. }
  2855. }
  2856. ),
  2857. Create<T5>(
  2858. async x =>
  2859. {
  2860. using (await gate.LockAsync().ConfigureAwait(false))
  2861. {
  2862. if (!hasValue5)
  2863. {
  2864. hasValue5 = true;
  2865. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  2866. }
  2867. latestValue5 = x;
  2868. if (allHasValue)
  2869. {
  2870. TResult res;
  2871. try
  2872. {
  2873. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  2874. }
  2875. catch (Exception ex)
  2876. {
  2877. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2878. return;
  2879. }
  2880. await observer.OnNextAsync(res).ConfigureAwait(false);
  2881. }
  2882. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8)
  2883. {
  2884. await observer.OnCompletedAsync().ConfigureAwait(false);
  2885. }
  2886. }
  2887. },
  2888. async ex =>
  2889. {
  2890. using (await gate.LockAsync().ConfigureAwait(false))
  2891. {
  2892. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2893. }
  2894. },
  2895. async () =>
  2896. {
  2897. using (await gate.LockAsync().ConfigureAwait(false))
  2898. {
  2899. isDone5 = true;
  2900. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2901. {
  2902. await observer.OnCompletedAsync().ConfigureAwait(false);
  2903. }
  2904. }
  2905. }
  2906. ),
  2907. Create<T6>(
  2908. async x =>
  2909. {
  2910. using (await gate.LockAsync().ConfigureAwait(false))
  2911. {
  2912. if (!hasValue6)
  2913. {
  2914. hasValue6 = true;
  2915. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  2916. }
  2917. latestValue6 = x;
  2918. if (allHasValue)
  2919. {
  2920. TResult res;
  2921. try
  2922. {
  2923. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  2924. }
  2925. catch (Exception ex)
  2926. {
  2927. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2928. return;
  2929. }
  2930. await observer.OnNextAsync(res).ConfigureAwait(false);
  2931. }
  2932. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8)
  2933. {
  2934. await observer.OnCompletedAsync().ConfigureAwait(false);
  2935. }
  2936. }
  2937. },
  2938. async ex =>
  2939. {
  2940. using (await gate.LockAsync().ConfigureAwait(false))
  2941. {
  2942. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2943. }
  2944. },
  2945. async () =>
  2946. {
  2947. using (await gate.LockAsync().ConfigureAwait(false))
  2948. {
  2949. isDone6 = true;
  2950. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  2951. {
  2952. await observer.OnCompletedAsync().ConfigureAwait(false);
  2953. }
  2954. }
  2955. }
  2956. ),
  2957. Create<T7>(
  2958. async x =>
  2959. {
  2960. using (await gate.LockAsync().ConfigureAwait(false))
  2961. {
  2962. if (!hasValue7)
  2963. {
  2964. hasValue7 = true;
  2965. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  2966. }
  2967. latestValue7 = x;
  2968. if (allHasValue)
  2969. {
  2970. TResult res;
  2971. try
  2972. {
  2973. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  2974. }
  2975. catch (Exception ex)
  2976. {
  2977. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2978. return;
  2979. }
  2980. await observer.OnNextAsync(res).ConfigureAwait(false);
  2981. }
  2982. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8)
  2983. {
  2984. await observer.OnCompletedAsync().ConfigureAwait(false);
  2985. }
  2986. }
  2987. },
  2988. async ex =>
  2989. {
  2990. using (await gate.LockAsync().ConfigureAwait(false))
  2991. {
  2992. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  2993. }
  2994. },
  2995. async () =>
  2996. {
  2997. using (await gate.LockAsync().ConfigureAwait(false))
  2998. {
  2999. isDone7 = true;
  3000. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  3001. {
  3002. await observer.OnCompletedAsync().ConfigureAwait(false);
  3003. }
  3004. }
  3005. }
  3006. ),
  3007. Create<T8>(
  3008. async x =>
  3009. {
  3010. using (await gate.LockAsync().ConfigureAwait(false))
  3011. {
  3012. if (!hasValue8)
  3013. {
  3014. hasValue8 = true;
  3015. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8;
  3016. }
  3017. latestValue8 = x;
  3018. if (allHasValue)
  3019. {
  3020. TResult res;
  3021. try
  3022. {
  3023. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8).ConfigureAwait(false);
  3024. }
  3025. catch (Exception ex)
  3026. {
  3027. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3028. return;
  3029. }
  3030. await observer.OnNextAsync(res).ConfigureAwait(false);
  3031. }
  3032. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7)
  3033. {
  3034. await observer.OnCompletedAsync().ConfigureAwait(false);
  3035. }
  3036. }
  3037. },
  3038. async ex =>
  3039. {
  3040. using (await gate.LockAsync().ConfigureAwait(false))
  3041. {
  3042. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3043. }
  3044. },
  3045. async () =>
  3046. {
  3047. using (await gate.LockAsync().ConfigureAwait(false))
  3048. {
  3049. isDone8 = true;
  3050. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  3051. {
  3052. await observer.OnCompletedAsync().ConfigureAwait(false);
  3053. }
  3054. }
  3055. }
  3056. )
  3057. );
  3058. }
  3059. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> selector)
  3060. {
  3061. if (observer == null)
  3062. throw new ArgumentNullException(nameof(observer));
  3063. if (selector == null)
  3064. throw new ArgumentNullException(nameof(selector));
  3065. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8, x9) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8, x9)));
  3066. }
  3067. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, Task<TResult>> selector)
  3068. {
  3069. if (observer == null)
  3070. throw new ArgumentNullException(nameof(observer));
  3071. if (selector == null)
  3072. throw new ArgumentNullException(nameof(selector));
  3073. bool allHasValue = false;
  3074. bool hasValue1 = false;
  3075. bool isDone1 = false;
  3076. T1 latestValue1 = default(T1);
  3077. bool hasValue2 = false;
  3078. bool isDone2 = false;
  3079. T2 latestValue2 = default(T2);
  3080. bool hasValue3 = false;
  3081. bool isDone3 = false;
  3082. T3 latestValue3 = default(T3);
  3083. bool hasValue4 = false;
  3084. bool isDone4 = false;
  3085. T4 latestValue4 = default(T4);
  3086. bool hasValue5 = false;
  3087. bool isDone5 = false;
  3088. T5 latestValue5 = default(T5);
  3089. bool hasValue6 = false;
  3090. bool isDone6 = false;
  3091. T6 latestValue6 = default(T6);
  3092. bool hasValue7 = false;
  3093. bool isDone7 = false;
  3094. T7 latestValue7 = default(T7);
  3095. bool hasValue8 = false;
  3096. bool isDone8 = false;
  3097. T8 latestValue8 = default(T8);
  3098. bool hasValue9 = false;
  3099. bool isDone9 = false;
  3100. T9 latestValue9 = default(T9);
  3101. var gate = new AsyncLock();
  3102. return
  3103. (
  3104. Create<T1>(
  3105. async x =>
  3106. {
  3107. using (await gate.LockAsync().ConfigureAwait(false))
  3108. {
  3109. if (!hasValue1)
  3110. {
  3111. hasValue1 = true;
  3112. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3113. }
  3114. latestValue1 = x;
  3115. if (allHasValue)
  3116. {
  3117. TResult res;
  3118. try
  3119. {
  3120. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3121. }
  3122. catch (Exception ex)
  3123. {
  3124. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3125. return;
  3126. }
  3127. await observer.OnNextAsync(res).ConfigureAwait(false);
  3128. }
  3129. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3130. {
  3131. await observer.OnCompletedAsync().ConfigureAwait(false);
  3132. }
  3133. }
  3134. },
  3135. async ex =>
  3136. {
  3137. using (await gate.LockAsync().ConfigureAwait(false))
  3138. {
  3139. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3140. }
  3141. },
  3142. async () =>
  3143. {
  3144. using (await gate.LockAsync().ConfigureAwait(false))
  3145. {
  3146. isDone1 = true;
  3147. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3148. {
  3149. await observer.OnCompletedAsync().ConfigureAwait(false);
  3150. }
  3151. }
  3152. }
  3153. ),
  3154. Create<T2>(
  3155. async x =>
  3156. {
  3157. using (await gate.LockAsync().ConfigureAwait(false))
  3158. {
  3159. if (!hasValue2)
  3160. {
  3161. hasValue2 = true;
  3162. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3163. }
  3164. latestValue2 = x;
  3165. if (allHasValue)
  3166. {
  3167. TResult res;
  3168. try
  3169. {
  3170. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3171. }
  3172. catch (Exception ex)
  3173. {
  3174. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3175. return;
  3176. }
  3177. await observer.OnNextAsync(res).ConfigureAwait(false);
  3178. }
  3179. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3180. {
  3181. await observer.OnCompletedAsync().ConfigureAwait(false);
  3182. }
  3183. }
  3184. },
  3185. async ex =>
  3186. {
  3187. using (await gate.LockAsync().ConfigureAwait(false))
  3188. {
  3189. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3190. }
  3191. },
  3192. async () =>
  3193. {
  3194. using (await gate.LockAsync().ConfigureAwait(false))
  3195. {
  3196. isDone2 = true;
  3197. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3198. {
  3199. await observer.OnCompletedAsync().ConfigureAwait(false);
  3200. }
  3201. }
  3202. }
  3203. ),
  3204. Create<T3>(
  3205. async x =>
  3206. {
  3207. using (await gate.LockAsync().ConfigureAwait(false))
  3208. {
  3209. if (!hasValue3)
  3210. {
  3211. hasValue3 = true;
  3212. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3213. }
  3214. latestValue3 = x;
  3215. if (allHasValue)
  3216. {
  3217. TResult res;
  3218. try
  3219. {
  3220. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3221. }
  3222. catch (Exception ex)
  3223. {
  3224. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3225. return;
  3226. }
  3227. await observer.OnNextAsync(res).ConfigureAwait(false);
  3228. }
  3229. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3230. {
  3231. await observer.OnCompletedAsync().ConfigureAwait(false);
  3232. }
  3233. }
  3234. },
  3235. async ex =>
  3236. {
  3237. using (await gate.LockAsync().ConfigureAwait(false))
  3238. {
  3239. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3240. }
  3241. },
  3242. async () =>
  3243. {
  3244. using (await gate.LockAsync().ConfigureAwait(false))
  3245. {
  3246. isDone3 = true;
  3247. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3248. {
  3249. await observer.OnCompletedAsync().ConfigureAwait(false);
  3250. }
  3251. }
  3252. }
  3253. ),
  3254. Create<T4>(
  3255. async x =>
  3256. {
  3257. using (await gate.LockAsync().ConfigureAwait(false))
  3258. {
  3259. if (!hasValue4)
  3260. {
  3261. hasValue4 = true;
  3262. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3263. }
  3264. latestValue4 = x;
  3265. if (allHasValue)
  3266. {
  3267. TResult res;
  3268. try
  3269. {
  3270. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3271. }
  3272. catch (Exception ex)
  3273. {
  3274. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3275. return;
  3276. }
  3277. await observer.OnNextAsync(res).ConfigureAwait(false);
  3278. }
  3279. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3280. {
  3281. await observer.OnCompletedAsync().ConfigureAwait(false);
  3282. }
  3283. }
  3284. },
  3285. async ex =>
  3286. {
  3287. using (await gate.LockAsync().ConfigureAwait(false))
  3288. {
  3289. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3290. }
  3291. },
  3292. async () =>
  3293. {
  3294. using (await gate.LockAsync().ConfigureAwait(false))
  3295. {
  3296. isDone4 = true;
  3297. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3298. {
  3299. await observer.OnCompletedAsync().ConfigureAwait(false);
  3300. }
  3301. }
  3302. }
  3303. ),
  3304. Create<T5>(
  3305. async x =>
  3306. {
  3307. using (await gate.LockAsync().ConfigureAwait(false))
  3308. {
  3309. if (!hasValue5)
  3310. {
  3311. hasValue5 = true;
  3312. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3313. }
  3314. latestValue5 = x;
  3315. if (allHasValue)
  3316. {
  3317. TResult res;
  3318. try
  3319. {
  3320. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3321. }
  3322. catch (Exception ex)
  3323. {
  3324. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3325. return;
  3326. }
  3327. await observer.OnNextAsync(res).ConfigureAwait(false);
  3328. }
  3329. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8 && isDone9)
  3330. {
  3331. await observer.OnCompletedAsync().ConfigureAwait(false);
  3332. }
  3333. }
  3334. },
  3335. async ex =>
  3336. {
  3337. using (await gate.LockAsync().ConfigureAwait(false))
  3338. {
  3339. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3340. }
  3341. },
  3342. async () =>
  3343. {
  3344. using (await gate.LockAsync().ConfigureAwait(false))
  3345. {
  3346. isDone5 = true;
  3347. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3348. {
  3349. await observer.OnCompletedAsync().ConfigureAwait(false);
  3350. }
  3351. }
  3352. }
  3353. ),
  3354. Create<T6>(
  3355. async x =>
  3356. {
  3357. using (await gate.LockAsync().ConfigureAwait(false))
  3358. {
  3359. if (!hasValue6)
  3360. {
  3361. hasValue6 = true;
  3362. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3363. }
  3364. latestValue6 = x;
  3365. if (allHasValue)
  3366. {
  3367. TResult res;
  3368. try
  3369. {
  3370. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3371. }
  3372. catch (Exception ex)
  3373. {
  3374. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3375. return;
  3376. }
  3377. await observer.OnNextAsync(res).ConfigureAwait(false);
  3378. }
  3379. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8 && isDone9)
  3380. {
  3381. await observer.OnCompletedAsync().ConfigureAwait(false);
  3382. }
  3383. }
  3384. },
  3385. async ex =>
  3386. {
  3387. using (await gate.LockAsync().ConfigureAwait(false))
  3388. {
  3389. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3390. }
  3391. },
  3392. async () =>
  3393. {
  3394. using (await gate.LockAsync().ConfigureAwait(false))
  3395. {
  3396. isDone6 = true;
  3397. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3398. {
  3399. await observer.OnCompletedAsync().ConfigureAwait(false);
  3400. }
  3401. }
  3402. }
  3403. ),
  3404. Create<T7>(
  3405. async x =>
  3406. {
  3407. using (await gate.LockAsync().ConfigureAwait(false))
  3408. {
  3409. if (!hasValue7)
  3410. {
  3411. hasValue7 = true;
  3412. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3413. }
  3414. latestValue7 = x;
  3415. if (allHasValue)
  3416. {
  3417. TResult res;
  3418. try
  3419. {
  3420. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3421. }
  3422. catch (Exception ex)
  3423. {
  3424. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3425. return;
  3426. }
  3427. await observer.OnNextAsync(res).ConfigureAwait(false);
  3428. }
  3429. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8 && isDone9)
  3430. {
  3431. await observer.OnCompletedAsync().ConfigureAwait(false);
  3432. }
  3433. }
  3434. },
  3435. async ex =>
  3436. {
  3437. using (await gate.LockAsync().ConfigureAwait(false))
  3438. {
  3439. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3440. }
  3441. },
  3442. async () =>
  3443. {
  3444. using (await gate.LockAsync().ConfigureAwait(false))
  3445. {
  3446. isDone7 = true;
  3447. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3448. {
  3449. await observer.OnCompletedAsync().ConfigureAwait(false);
  3450. }
  3451. }
  3452. }
  3453. ),
  3454. Create<T8>(
  3455. async x =>
  3456. {
  3457. using (await gate.LockAsync().ConfigureAwait(false))
  3458. {
  3459. if (!hasValue8)
  3460. {
  3461. hasValue8 = true;
  3462. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3463. }
  3464. latestValue8 = x;
  3465. if (allHasValue)
  3466. {
  3467. TResult res;
  3468. try
  3469. {
  3470. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3471. }
  3472. catch (Exception ex)
  3473. {
  3474. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3475. return;
  3476. }
  3477. await observer.OnNextAsync(res).ConfigureAwait(false);
  3478. }
  3479. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone9)
  3480. {
  3481. await observer.OnCompletedAsync().ConfigureAwait(false);
  3482. }
  3483. }
  3484. },
  3485. async ex =>
  3486. {
  3487. using (await gate.LockAsync().ConfigureAwait(false))
  3488. {
  3489. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3490. }
  3491. },
  3492. async () =>
  3493. {
  3494. using (await gate.LockAsync().ConfigureAwait(false))
  3495. {
  3496. isDone8 = true;
  3497. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3498. {
  3499. await observer.OnCompletedAsync().ConfigureAwait(false);
  3500. }
  3501. }
  3502. }
  3503. ),
  3504. Create<T9>(
  3505. async x =>
  3506. {
  3507. using (await gate.LockAsync().ConfigureAwait(false))
  3508. {
  3509. if (!hasValue9)
  3510. {
  3511. hasValue9 = true;
  3512. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9;
  3513. }
  3514. latestValue9 = x;
  3515. if (allHasValue)
  3516. {
  3517. TResult res;
  3518. try
  3519. {
  3520. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9).ConfigureAwait(false);
  3521. }
  3522. catch (Exception ex)
  3523. {
  3524. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3525. return;
  3526. }
  3527. await observer.OnNextAsync(res).ConfigureAwait(false);
  3528. }
  3529. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8)
  3530. {
  3531. await observer.OnCompletedAsync().ConfigureAwait(false);
  3532. }
  3533. }
  3534. },
  3535. async ex =>
  3536. {
  3537. using (await gate.LockAsync().ConfigureAwait(false))
  3538. {
  3539. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3540. }
  3541. },
  3542. async () =>
  3543. {
  3544. using (await gate.LockAsync().ConfigureAwait(false))
  3545. {
  3546. isDone9 = true;
  3547. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  3548. {
  3549. await observer.OnCompletedAsync().ConfigureAwait(false);
  3550. }
  3551. }
  3552. }
  3553. )
  3554. );
  3555. }
  3556. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> selector)
  3557. {
  3558. if (observer == null)
  3559. throw new ArgumentNullException(nameof(observer));
  3560. if (selector == null)
  3561. throw new ArgumentNullException(nameof(selector));
  3562. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)));
  3563. }
  3564. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Task<TResult>> selector)
  3565. {
  3566. if (observer == null)
  3567. throw new ArgumentNullException(nameof(observer));
  3568. if (selector == null)
  3569. throw new ArgumentNullException(nameof(selector));
  3570. bool allHasValue = false;
  3571. bool hasValue1 = false;
  3572. bool isDone1 = false;
  3573. T1 latestValue1 = default(T1);
  3574. bool hasValue2 = false;
  3575. bool isDone2 = false;
  3576. T2 latestValue2 = default(T2);
  3577. bool hasValue3 = false;
  3578. bool isDone3 = false;
  3579. T3 latestValue3 = default(T3);
  3580. bool hasValue4 = false;
  3581. bool isDone4 = false;
  3582. T4 latestValue4 = default(T4);
  3583. bool hasValue5 = false;
  3584. bool isDone5 = false;
  3585. T5 latestValue5 = default(T5);
  3586. bool hasValue6 = false;
  3587. bool isDone6 = false;
  3588. T6 latestValue6 = default(T6);
  3589. bool hasValue7 = false;
  3590. bool isDone7 = false;
  3591. T7 latestValue7 = default(T7);
  3592. bool hasValue8 = false;
  3593. bool isDone8 = false;
  3594. T8 latestValue8 = default(T8);
  3595. bool hasValue9 = false;
  3596. bool isDone9 = false;
  3597. T9 latestValue9 = default(T9);
  3598. bool hasValue10 = false;
  3599. bool isDone10 = false;
  3600. T10 latestValue10 = default(T10);
  3601. var gate = new AsyncLock();
  3602. return
  3603. (
  3604. Create<T1>(
  3605. async x =>
  3606. {
  3607. using (await gate.LockAsync().ConfigureAwait(false))
  3608. {
  3609. if (!hasValue1)
  3610. {
  3611. hasValue1 = true;
  3612. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3613. }
  3614. latestValue1 = x;
  3615. if (allHasValue)
  3616. {
  3617. TResult res;
  3618. try
  3619. {
  3620. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3621. }
  3622. catch (Exception ex)
  3623. {
  3624. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3625. return;
  3626. }
  3627. await observer.OnNextAsync(res).ConfigureAwait(false);
  3628. }
  3629. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3630. {
  3631. await observer.OnCompletedAsync().ConfigureAwait(false);
  3632. }
  3633. }
  3634. },
  3635. async ex =>
  3636. {
  3637. using (await gate.LockAsync().ConfigureAwait(false))
  3638. {
  3639. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3640. }
  3641. },
  3642. async () =>
  3643. {
  3644. using (await gate.LockAsync().ConfigureAwait(false))
  3645. {
  3646. isDone1 = true;
  3647. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3648. {
  3649. await observer.OnCompletedAsync().ConfigureAwait(false);
  3650. }
  3651. }
  3652. }
  3653. ),
  3654. Create<T2>(
  3655. async x =>
  3656. {
  3657. using (await gate.LockAsync().ConfigureAwait(false))
  3658. {
  3659. if (!hasValue2)
  3660. {
  3661. hasValue2 = true;
  3662. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3663. }
  3664. latestValue2 = x;
  3665. if (allHasValue)
  3666. {
  3667. TResult res;
  3668. try
  3669. {
  3670. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3671. }
  3672. catch (Exception ex)
  3673. {
  3674. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3675. return;
  3676. }
  3677. await observer.OnNextAsync(res).ConfigureAwait(false);
  3678. }
  3679. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3680. {
  3681. await observer.OnCompletedAsync().ConfigureAwait(false);
  3682. }
  3683. }
  3684. },
  3685. async ex =>
  3686. {
  3687. using (await gate.LockAsync().ConfigureAwait(false))
  3688. {
  3689. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3690. }
  3691. },
  3692. async () =>
  3693. {
  3694. using (await gate.LockAsync().ConfigureAwait(false))
  3695. {
  3696. isDone2 = true;
  3697. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3698. {
  3699. await observer.OnCompletedAsync().ConfigureAwait(false);
  3700. }
  3701. }
  3702. }
  3703. ),
  3704. Create<T3>(
  3705. async x =>
  3706. {
  3707. using (await gate.LockAsync().ConfigureAwait(false))
  3708. {
  3709. if (!hasValue3)
  3710. {
  3711. hasValue3 = true;
  3712. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3713. }
  3714. latestValue3 = x;
  3715. if (allHasValue)
  3716. {
  3717. TResult res;
  3718. try
  3719. {
  3720. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3721. }
  3722. catch (Exception ex)
  3723. {
  3724. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3725. return;
  3726. }
  3727. await observer.OnNextAsync(res).ConfigureAwait(false);
  3728. }
  3729. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3730. {
  3731. await observer.OnCompletedAsync().ConfigureAwait(false);
  3732. }
  3733. }
  3734. },
  3735. async ex =>
  3736. {
  3737. using (await gate.LockAsync().ConfigureAwait(false))
  3738. {
  3739. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3740. }
  3741. },
  3742. async () =>
  3743. {
  3744. using (await gate.LockAsync().ConfigureAwait(false))
  3745. {
  3746. isDone3 = true;
  3747. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3748. {
  3749. await observer.OnCompletedAsync().ConfigureAwait(false);
  3750. }
  3751. }
  3752. }
  3753. ),
  3754. Create<T4>(
  3755. async x =>
  3756. {
  3757. using (await gate.LockAsync().ConfigureAwait(false))
  3758. {
  3759. if (!hasValue4)
  3760. {
  3761. hasValue4 = true;
  3762. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3763. }
  3764. latestValue4 = x;
  3765. if (allHasValue)
  3766. {
  3767. TResult res;
  3768. try
  3769. {
  3770. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3771. }
  3772. catch (Exception ex)
  3773. {
  3774. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3775. return;
  3776. }
  3777. await observer.OnNextAsync(res).ConfigureAwait(false);
  3778. }
  3779. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3780. {
  3781. await observer.OnCompletedAsync().ConfigureAwait(false);
  3782. }
  3783. }
  3784. },
  3785. async ex =>
  3786. {
  3787. using (await gate.LockAsync().ConfigureAwait(false))
  3788. {
  3789. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3790. }
  3791. },
  3792. async () =>
  3793. {
  3794. using (await gate.LockAsync().ConfigureAwait(false))
  3795. {
  3796. isDone4 = true;
  3797. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3798. {
  3799. await observer.OnCompletedAsync().ConfigureAwait(false);
  3800. }
  3801. }
  3802. }
  3803. ),
  3804. Create<T5>(
  3805. async x =>
  3806. {
  3807. using (await gate.LockAsync().ConfigureAwait(false))
  3808. {
  3809. if (!hasValue5)
  3810. {
  3811. hasValue5 = true;
  3812. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3813. }
  3814. latestValue5 = x;
  3815. if (allHasValue)
  3816. {
  3817. TResult res;
  3818. try
  3819. {
  3820. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3821. }
  3822. catch (Exception ex)
  3823. {
  3824. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3825. return;
  3826. }
  3827. await observer.OnNextAsync(res).ConfigureAwait(false);
  3828. }
  3829. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3830. {
  3831. await observer.OnCompletedAsync().ConfigureAwait(false);
  3832. }
  3833. }
  3834. },
  3835. async ex =>
  3836. {
  3837. using (await gate.LockAsync().ConfigureAwait(false))
  3838. {
  3839. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3840. }
  3841. },
  3842. async () =>
  3843. {
  3844. using (await gate.LockAsync().ConfigureAwait(false))
  3845. {
  3846. isDone5 = true;
  3847. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3848. {
  3849. await observer.OnCompletedAsync().ConfigureAwait(false);
  3850. }
  3851. }
  3852. }
  3853. ),
  3854. Create<T6>(
  3855. async x =>
  3856. {
  3857. using (await gate.LockAsync().ConfigureAwait(false))
  3858. {
  3859. if (!hasValue6)
  3860. {
  3861. hasValue6 = true;
  3862. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3863. }
  3864. latestValue6 = x;
  3865. if (allHasValue)
  3866. {
  3867. TResult res;
  3868. try
  3869. {
  3870. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3871. }
  3872. catch (Exception ex)
  3873. {
  3874. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3875. return;
  3876. }
  3877. await observer.OnNextAsync(res).ConfigureAwait(false);
  3878. }
  3879. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8 && isDone9 && isDone10)
  3880. {
  3881. await observer.OnCompletedAsync().ConfigureAwait(false);
  3882. }
  3883. }
  3884. },
  3885. async ex =>
  3886. {
  3887. using (await gate.LockAsync().ConfigureAwait(false))
  3888. {
  3889. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3890. }
  3891. },
  3892. async () =>
  3893. {
  3894. using (await gate.LockAsync().ConfigureAwait(false))
  3895. {
  3896. isDone6 = true;
  3897. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3898. {
  3899. await observer.OnCompletedAsync().ConfigureAwait(false);
  3900. }
  3901. }
  3902. }
  3903. ),
  3904. Create<T7>(
  3905. async x =>
  3906. {
  3907. using (await gate.LockAsync().ConfigureAwait(false))
  3908. {
  3909. if (!hasValue7)
  3910. {
  3911. hasValue7 = true;
  3912. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3913. }
  3914. latestValue7 = x;
  3915. if (allHasValue)
  3916. {
  3917. TResult res;
  3918. try
  3919. {
  3920. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3921. }
  3922. catch (Exception ex)
  3923. {
  3924. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3925. return;
  3926. }
  3927. await observer.OnNextAsync(res).ConfigureAwait(false);
  3928. }
  3929. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8 && isDone9 && isDone10)
  3930. {
  3931. await observer.OnCompletedAsync().ConfigureAwait(false);
  3932. }
  3933. }
  3934. },
  3935. async ex =>
  3936. {
  3937. using (await gate.LockAsync().ConfigureAwait(false))
  3938. {
  3939. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3940. }
  3941. },
  3942. async () =>
  3943. {
  3944. using (await gate.LockAsync().ConfigureAwait(false))
  3945. {
  3946. isDone7 = true;
  3947. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3948. {
  3949. await observer.OnCompletedAsync().ConfigureAwait(false);
  3950. }
  3951. }
  3952. }
  3953. ),
  3954. Create<T8>(
  3955. async x =>
  3956. {
  3957. using (await gate.LockAsync().ConfigureAwait(false))
  3958. {
  3959. if (!hasValue8)
  3960. {
  3961. hasValue8 = true;
  3962. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  3963. }
  3964. latestValue8 = x;
  3965. if (allHasValue)
  3966. {
  3967. TResult res;
  3968. try
  3969. {
  3970. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  3971. }
  3972. catch (Exception ex)
  3973. {
  3974. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3975. return;
  3976. }
  3977. await observer.OnNextAsync(res).ConfigureAwait(false);
  3978. }
  3979. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone9 && isDone10)
  3980. {
  3981. await observer.OnCompletedAsync().ConfigureAwait(false);
  3982. }
  3983. }
  3984. },
  3985. async ex =>
  3986. {
  3987. using (await gate.LockAsync().ConfigureAwait(false))
  3988. {
  3989. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  3990. }
  3991. },
  3992. async () =>
  3993. {
  3994. using (await gate.LockAsync().ConfigureAwait(false))
  3995. {
  3996. isDone8 = true;
  3997. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  3998. {
  3999. await observer.OnCompletedAsync().ConfigureAwait(false);
  4000. }
  4001. }
  4002. }
  4003. ),
  4004. Create<T9>(
  4005. async x =>
  4006. {
  4007. using (await gate.LockAsync().ConfigureAwait(false))
  4008. {
  4009. if (!hasValue9)
  4010. {
  4011. hasValue9 = true;
  4012. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  4013. }
  4014. latestValue9 = x;
  4015. if (allHasValue)
  4016. {
  4017. TResult res;
  4018. try
  4019. {
  4020. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  4021. }
  4022. catch (Exception ex)
  4023. {
  4024. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4025. return;
  4026. }
  4027. await observer.OnNextAsync(res).ConfigureAwait(false);
  4028. }
  4029. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone10)
  4030. {
  4031. await observer.OnCompletedAsync().ConfigureAwait(false);
  4032. }
  4033. }
  4034. },
  4035. async ex =>
  4036. {
  4037. using (await gate.LockAsync().ConfigureAwait(false))
  4038. {
  4039. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4040. }
  4041. },
  4042. async () =>
  4043. {
  4044. using (await gate.LockAsync().ConfigureAwait(false))
  4045. {
  4046. isDone9 = true;
  4047. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  4048. {
  4049. await observer.OnCompletedAsync().ConfigureAwait(false);
  4050. }
  4051. }
  4052. }
  4053. ),
  4054. Create<T10>(
  4055. async x =>
  4056. {
  4057. using (await gate.LockAsync().ConfigureAwait(false))
  4058. {
  4059. if (!hasValue10)
  4060. {
  4061. hasValue10 = true;
  4062. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10;
  4063. }
  4064. latestValue10 = x;
  4065. if (allHasValue)
  4066. {
  4067. TResult res;
  4068. try
  4069. {
  4070. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10).ConfigureAwait(false);
  4071. }
  4072. catch (Exception ex)
  4073. {
  4074. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4075. return;
  4076. }
  4077. await observer.OnNextAsync(res).ConfigureAwait(false);
  4078. }
  4079. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9)
  4080. {
  4081. await observer.OnCompletedAsync().ConfigureAwait(false);
  4082. }
  4083. }
  4084. },
  4085. async ex =>
  4086. {
  4087. using (await gate.LockAsync().ConfigureAwait(false))
  4088. {
  4089. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4090. }
  4091. },
  4092. async () =>
  4093. {
  4094. using (await gate.LockAsync().ConfigureAwait(false))
  4095. {
  4096. isDone10 = true;
  4097. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  4098. {
  4099. await observer.OnCompletedAsync().ConfigureAwait(false);
  4100. }
  4101. }
  4102. }
  4103. )
  4104. );
  4105. }
  4106. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> selector)
  4107. {
  4108. if (observer == null)
  4109. throw new ArgumentNullException(nameof(observer));
  4110. if (selector == null)
  4111. throw new ArgumentNullException(nameof(selector));
  4112. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11)));
  4113. }
  4114. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Task<TResult>> selector)
  4115. {
  4116. if (observer == null)
  4117. throw new ArgumentNullException(nameof(observer));
  4118. if (selector == null)
  4119. throw new ArgumentNullException(nameof(selector));
  4120. bool allHasValue = false;
  4121. bool hasValue1 = false;
  4122. bool isDone1 = false;
  4123. T1 latestValue1 = default(T1);
  4124. bool hasValue2 = false;
  4125. bool isDone2 = false;
  4126. T2 latestValue2 = default(T2);
  4127. bool hasValue3 = false;
  4128. bool isDone3 = false;
  4129. T3 latestValue3 = default(T3);
  4130. bool hasValue4 = false;
  4131. bool isDone4 = false;
  4132. T4 latestValue4 = default(T4);
  4133. bool hasValue5 = false;
  4134. bool isDone5 = false;
  4135. T5 latestValue5 = default(T5);
  4136. bool hasValue6 = false;
  4137. bool isDone6 = false;
  4138. T6 latestValue6 = default(T6);
  4139. bool hasValue7 = false;
  4140. bool isDone7 = false;
  4141. T7 latestValue7 = default(T7);
  4142. bool hasValue8 = false;
  4143. bool isDone8 = false;
  4144. T8 latestValue8 = default(T8);
  4145. bool hasValue9 = false;
  4146. bool isDone9 = false;
  4147. T9 latestValue9 = default(T9);
  4148. bool hasValue10 = false;
  4149. bool isDone10 = false;
  4150. T10 latestValue10 = default(T10);
  4151. bool hasValue11 = false;
  4152. bool isDone11 = false;
  4153. T11 latestValue11 = default(T11);
  4154. var gate = new AsyncLock();
  4155. return
  4156. (
  4157. Create<T1>(
  4158. async x =>
  4159. {
  4160. using (await gate.LockAsync().ConfigureAwait(false))
  4161. {
  4162. if (!hasValue1)
  4163. {
  4164. hasValue1 = true;
  4165. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4166. }
  4167. latestValue1 = x;
  4168. if (allHasValue)
  4169. {
  4170. TResult res;
  4171. try
  4172. {
  4173. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4174. }
  4175. catch (Exception ex)
  4176. {
  4177. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4178. return;
  4179. }
  4180. await observer.OnNextAsync(res).ConfigureAwait(false);
  4181. }
  4182. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4183. {
  4184. await observer.OnCompletedAsync().ConfigureAwait(false);
  4185. }
  4186. }
  4187. },
  4188. async ex =>
  4189. {
  4190. using (await gate.LockAsync().ConfigureAwait(false))
  4191. {
  4192. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4193. }
  4194. },
  4195. async () =>
  4196. {
  4197. using (await gate.LockAsync().ConfigureAwait(false))
  4198. {
  4199. isDone1 = true;
  4200. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4201. {
  4202. await observer.OnCompletedAsync().ConfigureAwait(false);
  4203. }
  4204. }
  4205. }
  4206. ),
  4207. Create<T2>(
  4208. async x =>
  4209. {
  4210. using (await gate.LockAsync().ConfigureAwait(false))
  4211. {
  4212. if (!hasValue2)
  4213. {
  4214. hasValue2 = true;
  4215. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4216. }
  4217. latestValue2 = x;
  4218. if (allHasValue)
  4219. {
  4220. TResult res;
  4221. try
  4222. {
  4223. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4224. }
  4225. catch (Exception ex)
  4226. {
  4227. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4228. return;
  4229. }
  4230. await observer.OnNextAsync(res).ConfigureAwait(false);
  4231. }
  4232. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4233. {
  4234. await observer.OnCompletedAsync().ConfigureAwait(false);
  4235. }
  4236. }
  4237. },
  4238. async ex =>
  4239. {
  4240. using (await gate.LockAsync().ConfigureAwait(false))
  4241. {
  4242. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4243. }
  4244. },
  4245. async () =>
  4246. {
  4247. using (await gate.LockAsync().ConfigureAwait(false))
  4248. {
  4249. isDone2 = true;
  4250. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4251. {
  4252. await observer.OnCompletedAsync().ConfigureAwait(false);
  4253. }
  4254. }
  4255. }
  4256. ),
  4257. Create<T3>(
  4258. async x =>
  4259. {
  4260. using (await gate.LockAsync().ConfigureAwait(false))
  4261. {
  4262. if (!hasValue3)
  4263. {
  4264. hasValue3 = true;
  4265. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4266. }
  4267. latestValue3 = x;
  4268. if (allHasValue)
  4269. {
  4270. TResult res;
  4271. try
  4272. {
  4273. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4274. }
  4275. catch (Exception ex)
  4276. {
  4277. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4278. return;
  4279. }
  4280. await observer.OnNextAsync(res).ConfigureAwait(false);
  4281. }
  4282. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4283. {
  4284. await observer.OnCompletedAsync().ConfigureAwait(false);
  4285. }
  4286. }
  4287. },
  4288. async ex =>
  4289. {
  4290. using (await gate.LockAsync().ConfigureAwait(false))
  4291. {
  4292. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4293. }
  4294. },
  4295. async () =>
  4296. {
  4297. using (await gate.LockAsync().ConfigureAwait(false))
  4298. {
  4299. isDone3 = true;
  4300. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4301. {
  4302. await observer.OnCompletedAsync().ConfigureAwait(false);
  4303. }
  4304. }
  4305. }
  4306. ),
  4307. Create<T4>(
  4308. async x =>
  4309. {
  4310. using (await gate.LockAsync().ConfigureAwait(false))
  4311. {
  4312. if (!hasValue4)
  4313. {
  4314. hasValue4 = true;
  4315. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4316. }
  4317. latestValue4 = x;
  4318. if (allHasValue)
  4319. {
  4320. TResult res;
  4321. try
  4322. {
  4323. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4324. }
  4325. catch (Exception ex)
  4326. {
  4327. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4328. return;
  4329. }
  4330. await observer.OnNextAsync(res).ConfigureAwait(false);
  4331. }
  4332. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4333. {
  4334. await observer.OnCompletedAsync().ConfigureAwait(false);
  4335. }
  4336. }
  4337. },
  4338. async ex =>
  4339. {
  4340. using (await gate.LockAsync().ConfigureAwait(false))
  4341. {
  4342. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4343. }
  4344. },
  4345. async () =>
  4346. {
  4347. using (await gate.LockAsync().ConfigureAwait(false))
  4348. {
  4349. isDone4 = true;
  4350. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4351. {
  4352. await observer.OnCompletedAsync().ConfigureAwait(false);
  4353. }
  4354. }
  4355. }
  4356. ),
  4357. Create<T5>(
  4358. async x =>
  4359. {
  4360. using (await gate.LockAsync().ConfigureAwait(false))
  4361. {
  4362. if (!hasValue5)
  4363. {
  4364. hasValue5 = true;
  4365. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4366. }
  4367. latestValue5 = x;
  4368. if (allHasValue)
  4369. {
  4370. TResult res;
  4371. try
  4372. {
  4373. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4374. }
  4375. catch (Exception ex)
  4376. {
  4377. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4378. return;
  4379. }
  4380. await observer.OnNextAsync(res).ConfigureAwait(false);
  4381. }
  4382. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4383. {
  4384. await observer.OnCompletedAsync().ConfigureAwait(false);
  4385. }
  4386. }
  4387. },
  4388. async ex =>
  4389. {
  4390. using (await gate.LockAsync().ConfigureAwait(false))
  4391. {
  4392. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4393. }
  4394. },
  4395. async () =>
  4396. {
  4397. using (await gate.LockAsync().ConfigureAwait(false))
  4398. {
  4399. isDone5 = true;
  4400. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4401. {
  4402. await observer.OnCompletedAsync().ConfigureAwait(false);
  4403. }
  4404. }
  4405. }
  4406. ),
  4407. Create<T6>(
  4408. async x =>
  4409. {
  4410. using (await gate.LockAsync().ConfigureAwait(false))
  4411. {
  4412. if (!hasValue6)
  4413. {
  4414. hasValue6 = true;
  4415. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4416. }
  4417. latestValue6 = x;
  4418. if (allHasValue)
  4419. {
  4420. TResult res;
  4421. try
  4422. {
  4423. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4424. }
  4425. catch (Exception ex)
  4426. {
  4427. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4428. return;
  4429. }
  4430. await observer.OnNextAsync(res).ConfigureAwait(false);
  4431. }
  4432. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4433. {
  4434. await observer.OnCompletedAsync().ConfigureAwait(false);
  4435. }
  4436. }
  4437. },
  4438. async ex =>
  4439. {
  4440. using (await gate.LockAsync().ConfigureAwait(false))
  4441. {
  4442. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4443. }
  4444. },
  4445. async () =>
  4446. {
  4447. using (await gate.LockAsync().ConfigureAwait(false))
  4448. {
  4449. isDone6 = true;
  4450. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4451. {
  4452. await observer.OnCompletedAsync().ConfigureAwait(false);
  4453. }
  4454. }
  4455. }
  4456. ),
  4457. Create<T7>(
  4458. async x =>
  4459. {
  4460. using (await gate.LockAsync().ConfigureAwait(false))
  4461. {
  4462. if (!hasValue7)
  4463. {
  4464. hasValue7 = true;
  4465. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4466. }
  4467. latestValue7 = x;
  4468. if (allHasValue)
  4469. {
  4470. TResult res;
  4471. try
  4472. {
  4473. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4474. }
  4475. catch (Exception ex)
  4476. {
  4477. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4478. return;
  4479. }
  4480. await observer.OnNextAsync(res).ConfigureAwait(false);
  4481. }
  4482. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8 && isDone9 && isDone10 && isDone11)
  4483. {
  4484. await observer.OnCompletedAsync().ConfigureAwait(false);
  4485. }
  4486. }
  4487. },
  4488. async ex =>
  4489. {
  4490. using (await gate.LockAsync().ConfigureAwait(false))
  4491. {
  4492. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4493. }
  4494. },
  4495. async () =>
  4496. {
  4497. using (await gate.LockAsync().ConfigureAwait(false))
  4498. {
  4499. isDone7 = true;
  4500. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4501. {
  4502. await observer.OnCompletedAsync().ConfigureAwait(false);
  4503. }
  4504. }
  4505. }
  4506. ),
  4507. Create<T8>(
  4508. async x =>
  4509. {
  4510. using (await gate.LockAsync().ConfigureAwait(false))
  4511. {
  4512. if (!hasValue8)
  4513. {
  4514. hasValue8 = true;
  4515. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4516. }
  4517. latestValue8 = x;
  4518. if (allHasValue)
  4519. {
  4520. TResult res;
  4521. try
  4522. {
  4523. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4524. }
  4525. catch (Exception ex)
  4526. {
  4527. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4528. return;
  4529. }
  4530. await observer.OnNextAsync(res).ConfigureAwait(false);
  4531. }
  4532. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone9 && isDone10 && isDone11)
  4533. {
  4534. await observer.OnCompletedAsync().ConfigureAwait(false);
  4535. }
  4536. }
  4537. },
  4538. async ex =>
  4539. {
  4540. using (await gate.LockAsync().ConfigureAwait(false))
  4541. {
  4542. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4543. }
  4544. },
  4545. async () =>
  4546. {
  4547. using (await gate.LockAsync().ConfigureAwait(false))
  4548. {
  4549. isDone8 = true;
  4550. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4551. {
  4552. await observer.OnCompletedAsync().ConfigureAwait(false);
  4553. }
  4554. }
  4555. }
  4556. ),
  4557. Create<T9>(
  4558. async x =>
  4559. {
  4560. using (await gate.LockAsync().ConfigureAwait(false))
  4561. {
  4562. if (!hasValue9)
  4563. {
  4564. hasValue9 = true;
  4565. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4566. }
  4567. latestValue9 = x;
  4568. if (allHasValue)
  4569. {
  4570. TResult res;
  4571. try
  4572. {
  4573. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4574. }
  4575. catch (Exception ex)
  4576. {
  4577. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4578. return;
  4579. }
  4580. await observer.OnNextAsync(res).ConfigureAwait(false);
  4581. }
  4582. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone10 && isDone11)
  4583. {
  4584. await observer.OnCompletedAsync().ConfigureAwait(false);
  4585. }
  4586. }
  4587. },
  4588. async ex =>
  4589. {
  4590. using (await gate.LockAsync().ConfigureAwait(false))
  4591. {
  4592. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4593. }
  4594. },
  4595. async () =>
  4596. {
  4597. using (await gate.LockAsync().ConfigureAwait(false))
  4598. {
  4599. isDone9 = true;
  4600. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4601. {
  4602. await observer.OnCompletedAsync().ConfigureAwait(false);
  4603. }
  4604. }
  4605. }
  4606. ),
  4607. Create<T10>(
  4608. async x =>
  4609. {
  4610. using (await gate.LockAsync().ConfigureAwait(false))
  4611. {
  4612. if (!hasValue10)
  4613. {
  4614. hasValue10 = true;
  4615. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4616. }
  4617. latestValue10 = x;
  4618. if (allHasValue)
  4619. {
  4620. TResult res;
  4621. try
  4622. {
  4623. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4624. }
  4625. catch (Exception ex)
  4626. {
  4627. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4628. return;
  4629. }
  4630. await observer.OnNextAsync(res).ConfigureAwait(false);
  4631. }
  4632. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone11)
  4633. {
  4634. await observer.OnCompletedAsync().ConfigureAwait(false);
  4635. }
  4636. }
  4637. },
  4638. async ex =>
  4639. {
  4640. using (await gate.LockAsync().ConfigureAwait(false))
  4641. {
  4642. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4643. }
  4644. },
  4645. async () =>
  4646. {
  4647. using (await gate.LockAsync().ConfigureAwait(false))
  4648. {
  4649. isDone10 = true;
  4650. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4651. {
  4652. await observer.OnCompletedAsync().ConfigureAwait(false);
  4653. }
  4654. }
  4655. }
  4656. ),
  4657. Create<T11>(
  4658. async x =>
  4659. {
  4660. using (await gate.LockAsync().ConfigureAwait(false))
  4661. {
  4662. if (!hasValue11)
  4663. {
  4664. hasValue11 = true;
  4665. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11;
  4666. }
  4667. latestValue11 = x;
  4668. if (allHasValue)
  4669. {
  4670. TResult res;
  4671. try
  4672. {
  4673. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11).ConfigureAwait(false);
  4674. }
  4675. catch (Exception ex)
  4676. {
  4677. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4678. return;
  4679. }
  4680. await observer.OnNextAsync(res).ConfigureAwait(false);
  4681. }
  4682. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10)
  4683. {
  4684. await observer.OnCompletedAsync().ConfigureAwait(false);
  4685. }
  4686. }
  4687. },
  4688. async ex =>
  4689. {
  4690. using (await gate.LockAsync().ConfigureAwait(false))
  4691. {
  4692. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4693. }
  4694. },
  4695. async () =>
  4696. {
  4697. using (await gate.LockAsync().ConfigureAwait(false))
  4698. {
  4699. isDone11 = true;
  4700. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  4701. {
  4702. await observer.OnCompletedAsync().ConfigureAwait(false);
  4703. }
  4704. }
  4705. }
  4706. )
  4707. );
  4708. }
  4709. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> selector)
  4710. {
  4711. if (observer == null)
  4712. throw new ArgumentNullException(nameof(observer));
  4713. if (selector == null)
  4714. throw new ArgumentNullException(nameof(selector));
  4715. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12)));
  4716. }
  4717. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Task<TResult>> selector)
  4718. {
  4719. if (observer == null)
  4720. throw new ArgumentNullException(nameof(observer));
  4721. if (selector == null)
  4722. throw new ArgumentNullException(nameof(selector));
  4723. bool allHasValue = false;
  4724. bool hasValue1 = false;
  4725. bool isDone1 = false;
  4726. T1 latestValue1 = default(T1);
  4727. bool hasValue2 = false;
  4728. bool isDone2 = false;
  4729. T2 latestValue2 = default(T2);
  4730. bool hasValue3 = false;
  4731. bool isDone3 = false;
  4732. T3 latestValue3 = default(T3);
  4733. bool hasValue4 = false;
  4734. bool isDone4 = false;
  4735. T4 latestValue4 = default(T4);
  4736. bool hasValue5 = false;
  4737. bool isDone5 = false;
  4738. T5 latestValue5 = default(T5);
  4739. bool hasValue6 = false;
  4740. bool isDone6 = false;
  4741. T6 latestValue6 = default(T6);
  4742. bool hasValue7 = false;
  4743. bool isDone7 = false;
  4744. T7 latestValue7 = default(T7);
  4745. bool hasValue8 = false;
  4746. bool isDone8 = false;
  4747. T8 latestValue8 = default(T8);
  4748. bool hasValue9 = false;
  4749. bool isDone9 = false;
  4750. T9 latestValue9 = default(T9);
  4751. bool hasValue10 = false;
  4752. bool isDone10 = false;
  4753. T10 latestValue10 = default(T10);
  4754. bool hasValue11 = false;
  4755. bool isDone11 = false;
  4756. T11 latestValue11 = default(T11);
  4757. bool hasValue12 = false;
  4758. bool isDone12 = false;
  4759. T12 latestValue12 = default(T12);
  4760. var gate = new AsyncLock();
  4761. return
  4762. (
  4763. Create<T1>(
  4764. async x =>
  4765. {
  4766. using (await gate.LockAsync().ConfigureAwait(false))
  4767. {
  4768. if (!hasValue1)
  4769. {
  4770. hasValue1 = true;
  4771. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  4772. }
  4773. latestValue1 = x;
  4774. if (allHasValue)
  4775. {
  4776. TResult res;
  4777. try
  4778. {
  4779. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  4780. }
  4781. catch (Exception ex)
  4782. {
  4783. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4784. return;
  4785. }
  4786. await observer.OnNextAsync(res).ConfigureAwait(false);
  4787. }
  4788. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4789. {
  4790. await observer.OnCompletedAsync().ConfigureAwait(false);
  4791. }
  4792. }
  4793. },
  4794. async ex =>
  4795. {
  4796. using (await gate.LockAsync().ConfigureAwait(false))
  4797. {
  4798. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4799. }
  4800. },
  4801. async () =>
  4802. {
  4803. using (await gate.LockAsync().ConfigureAwait(false))
  4804. {
  4805. isDone1 = true;
  4806. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4807. {
  4808. await observer.OnCompletedAsync().ConfigureAwait(false);
  4809. }
  4810. }
  4811. }
  4812. ),
  4813. Create<T2>(
  4814. async x =>
  4815. {
  4816. using (await gate.LockAsync().ConfigureAwait(false))
  4817. {
  4818. if (!hasValue2)
  4819. {
  4820. hasValue2 = true;
  4821. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  4822. }
  4823. latestValue2 = x;
  4824. if (allHasValue)
  4825. {
  4826. TResult res;
  4827. try
  4828. {
  4829. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  4830. }
  4831. catch (Exception ex)
  4832. {
  4833. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4834. return;
  4835. }
  4836. await observer.OnNextAsync(res).ConfigureAwait(false);
  4837. }
  4838. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4839. {
  4840. await observer.OnCompletedAsync().ConfigureAwait(false);
  4841. }
  4842. }
  4843. },
  4844. async ex =>
  4845. {
  4846. using (await gate.LockAsync().ConfigureAwait(false))
  4847. {
  4848. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4849. }
  4850. },
  4851. async () =>
  4852. {
  4853. using (await gate.LockAsync().ConfigureAwait(false))
  4854. {
  4855. isDone2 = true;
  4856. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4857. {
  4858. await observer.OnCompletedAsync().ConfigureAwait(false);
  4859. }
  4860. }
  4861. }
  4862. ),
  4863. Create<T3>(
  4864. async x =>
  4865. {
  4866. using (await gate.LockAsync().ConfigureAwait(false))
  4867. {
  4868. if (!hasValue3)
  4869. {
  4870. hasValue3 = true;
  4871. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  4872. }
  4873. latestValue3 = x;
  4874. if (allHasValue)
  4875. {
  4876. TResult res;
  4877. try
  4878. {
  4879. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  4880. }
  4881. catch (Exception ex)
  4882. {
  4883. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4884. return;
  4885. }
  4886. await observer.OnNextAsync(res).ConfigureAwait(false);
  4887. }
  4888. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4889. {
  4890. await observer.OnCompletedAsync().ConfigureAwait(false);
  4891. }
  4892. }
  4893. },
  4894. async ex =>
  4895. {
  4896. using (await gate.LockAsync().ConfigureAwait(false))
  4897. {
  4898. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4899. }
  4900. },
  4901. async () =>
  4902. {
  4903. using (await gate.LockAsync().ConfigureAwait(false))
  4904. {
  4905. isDone3 = true;
  4906. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4907. {
  4908. await observer.OnCompletedAsync().ConfigureAwait(false);
  4909. }
  4910. }
  4911. }
  4912. ),
  4913. Create<T4>(
  4914. async x =>
  4915. {
  4916. using (await gate.LockAsync().ConfigureAwait(false))
  4917. {
  4918. if (!hasValue4)
  4919. {
  4920. hasValue4 = true;
  4921. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  4922. }
  4923. latestValue4 = x;
  4924. if (allHasValue)
  4925. {
  4926. TResult res;
  4927. try
  4928. {
  4929. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  4930. }
  4931. catch (Exception ex)
  4932. {
  4933. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4934. return;
  4935. }
  4936. await observer.OnNextAsync(res).ConfigureAwait(false);
  4937. }
  4938. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4939. {
  4940. await observer.OnCompletedAsync().ConfigureAwait(false);
  4941. }
  4942. }
  4943. },
  4944. async ex =>
  4945. {
  4946. using (await gate.LockAsync().ConfigureAwait(false))
  4947. {
  4948. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4949. }
  4950. },
  4951. async () =>
  4952. {
  4953. using (await gate.LockAsync().ConfigureAwait(false))
  4954. {
  4955. isDone4 = true;
  4956. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4957. {
  4958. await observer.OnCompletedAsync().ConfigureAwait(false);
  4959. }
  4960. }
  4961. }
  4962. ),
  4963. Create<T5>(
  4964. async x =>
  4965. {
  4966. using (await gate.LockAsync().ConfigureAwait(false))
  4967. {
  4968. if (!hasValue5)
  4969. {
  4970. hasValue5 = true;
  4971. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  4972. }
  4973. latestValue5 = x;
  4974. if (allHasValue)
  4975. {
  4976. TResult res;
  4977. try
  4978. {
  4979. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  4980. }
  4981. catch (Exception ex)
  4982. {
  4983. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4984. return;
  4985. }
  4986. await observer.OnNextAsync(res).ConfigureAwait(false);
  4987. }
  4988. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  4989. {
  4990. await observer.OnCompletedAsync().ConfigureAwait(false);
  4991. }
  4992. }
  4993. },
  4994. async ex =>
  4995. {
  4996. using (await gate.LockAsync().ConfigureAwait(false))
  4997. {
  4998. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  4999. }
  5000. },
  5001. async () =>
  5002. {
  5003. using (await gate.LockAsync().ConfigureAwait(false))
  5004. {
  5005. isDone5 = true;
  5006. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5007. {
  5008. await observer.OnCompletedAsync().ConfigureAwait(false);
  5009. }
  5010. }
  5011. }
  5012. ),
  5013. Create<T6>(
  5014. async x =>
  5015. {
  5016. using (await gate.LockAsync().ConfigureAwait(false))
  5017. {
  5018. if (!hasValue6)
  5019. {
  5020. hasValue6 = true;
  5021. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  5022. }
  5023. latestValue6 = x;
  5024. if (allHasValue)
  5025. {
  5026. TResult res;
  5027. try
  5028. {
  5029. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  5030. }
  5031. catch (Exception ex)
  5032. {
  5033. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5034. return;
  5035. }
  5036. await observer.OnNextAsync(res).ConfigureAwait(false);
  5037. }
  5038. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5039. {
  5040. await observer.OnCompletedAsync().ConfigureAwait(false);
  5041. }
  5042. }
  5043. },
  5044. async ex =>
  5045. {
  5046. using (await gate.LockAsync().ConfigureAwait(false))
  5047. {
  5048. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5049. }
  5050. },
  5051. async () =>
  5052. {
  5053. using (await gate.LockAsync().ConfigureAwait(false))
  5054. {
  5055. isDone6 = true;
  5056. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5057. {
  5058. await observer.OnCompletedAsync().ConfigureAwait(false);
  5059. }
  5060. }
  5061. }
  5062. ),
  5063. Create<T7>(
  5064. async x =>
  5065. {
  5066. using (await gate.LockAsync().ConfigureAwait(false))
  5067. {
  5068. if (!hasValue7)
  5069. {
  5070. hasValue7 = true;
  5071. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  5072. }
  5073. latestValue7 = x;
  5074. if (allHasValue)
  5075. {
  5076. TResult res;
  5077. try
  5078. {
  5079. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  5080. }
  5081. catch (Exception ex)
  5082. {
  5083. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5084. return;
  5085. }
  5086. await observer.OnNextAsync(res).ConfigureAwait(false);
  5087. }
  5088. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5089. {
  5090. await observer.OnCompletedAsync().ConfigureAwait(false);
  5091. }
  5092. }
  5093. },
  5094. async ex =>
  5095. {
  5096. using (await gate.LockAsync().ConfigureAwait(false))
  5097. {
  5098. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5099. }
  5100. },
  5101. async () =>
  5102. {
  5103. using (await gate.LockAsync().ConfigureAwait(false))
  5104. {
  5105. isDone7 = true;
  5106. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5107. {
  5108. await observer.OnCompletedAsync().ConfigureAwait(false);
  5109. }
  5110. }
  5111. }
  5112. ),
  5113. Create<T8>(
  5114. async x =>
  5115. {
  5116. using (await gate.LockAsync().ConfigureAwait(false))
  5117. {
  5118. if (!hasValue8)
  5119. {
  5120. hasValue8 = true;
  5121. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  5122. }
  5123. latestValue8 = x;
  5124. if (allHasValue)
  5125. {
  5126. TResult res;
  5127. try
  5128. {
  5129. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  5130. }
  5131. catch (Exception ex)
  5132. {
  5133. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5134. return;
  5135. }
  5136. await observer.OnNextAsync(res).ConfigureAwait(false);
  5137. }
  5138. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone9 && isDone10 && isDone11 && isDone12)
  5139. {
  5140. await observer.OnCompletedAsync().ConfigureAwait(false);
  5141. }
  5142. }
  5143. },
  5144. async ex =>
  5145. {
  5146. using (await gate.LockAsync().ConfigureAwait(false))
  5147. {
  5148. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5149. }
  5150. },
  5151. async () =>
  5152. {
  5153. using (await gate.LockAsync().ConfigureAwait(false))
  5154. {
  5155. isDone8 = true;
  5156. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5157. {
  5158. await observer.OnCompletedAsync().ConfigureAwait(false);
  5159. }
  5160. }
  5161. }
  5162. ),
  5163. Create<T9>(
  5164. async x =>
  5165. {
  5166. using (await gate.LockAsync().ConfigureAwait(false))
  5167. {
  5168. if (!hasValue9)
  5169. {
  5170. hasValue9 = true;
  5171. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  5172. }
  5173. latestValue9 = x;
  5174. if (allHasValue)
  5175. {
  5176. TResult res;
  5177. try
  5178. {
  5179. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  5180. }
  5181. catch (Exception ex)
  5182. {
  5183. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5184. return;
  5185. }
  5186. await observer.OnNextAsync(res).ConfigureAwait(false);
  5187. }
  5188. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone10 && isDone11 && isDone12)
  5189. {
  5190. await observer.OnCompletedAsync().ConfigureAwait(false);
  5191. }
  5192. }
  5193. },
  5194. async ex =>
  5195. {
  5196. using (await gate.LockAsync().ConfigureAwait(false))
  5197. {
  5198. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5199. }
  5200. },
  5201. async () =>
  5202. {
  5203. using (await gate.LockAsync().ConfigureAwait(false))
  5204. {
  5205. isDone9 = true;
  5206. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5207. {
  5208. await observer.OnCompletedAsync().ConfigureAwait(false);
  5209. }
  5210. }
  5211. }
  5212. ),
  5213. Create<T10>(
  5214. async x =>
  5215. {
  5216. using (await gate.LockAsync().ConfigureAwait(false))
  5217. {
  5218. if (!hasValue10)
  5219. {
  5220. hasValue10 = true;
  5221. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  5222. }
  5223. latestValue10 = x;
  5224. if (allHasValue)
  5225. {
  5226. TResult res;
  5227. try
  5228. {
  5229. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  5230. }
  5231. catch (Exception ex)
  5232. {
  5233. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5234. return;
  5235. }
  5236. await observer.OnNextAsync(res).ConfigureAwait(false);
  5237. }
  5238. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone11 && isDone12)
  5239. {
  5240. await observer.OnCompletedAsync().ConfigureAwait(false);
  5241. }
  5242. }
  5243. },
  5244. async ex =>
  5245. {
  5246. using (await gate.LockAsync().ConfigureAwait(false))
  5247. {
  5248. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5249. }
  5250. },
  5251. async () =>
  5252. {
  5253. using (await gate.LockAsync().ConfigureAwait(false))
  5254. {
  5255. isDone10 = true;
  5256. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5257. {
  5258. await observer.OnCompletedAsync().ConfigureAwait(false);
  5259. }
  5260. }
  5261. }
  5262. ),
  5263. Create<T11>(
  5264. async x =>
  5265. {
  5266. using (await gate.LockAsync().ConfigureAwait(false))
  5267. {
  5268. if (!hasValue11)
  5269. {
  5270. hasValue11 = true;
  5271. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  5272. }
  5273. latestValue11 = x;
  5274. if (allHasValue)
  5275. {
  5276. TResult res;
  5277. try
  5278. {
  5279. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  5280. }
  5281. catch (Exception ex)
  5282. {
  5283. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5284. return;
  5285. }
  5286. await observer.OnNextAsync(res).ConfigureAwait(false);
  5287. }
  5288. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone12)
  5289. {
  5290. await observer.OnCompletedAsync().ConfigureAwait(false);
  5291. }
  5292. }
  5293. },
  5294. async ex =>
  5295. {
  5296. using (await gate.LockAsync().ConfigureAwait(false))
  5297. {
  5298. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5299. }
  5300. },
  5301. async () =>
  5302. {
  5303. using (await gate.LockAsync().ConfigureAwait(false))
  5304. {
  5305. isDone11 = true;
  5306. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5307. {
  5308. await observer.OnCompletedAsync().ConfigureAwait(false);
  5309. }
  5310. }
  5311. }
  5312. ),
  5313. Create<T12>(
  5314. async x =>
  5315. {
  5316. using (await gate.LockAsync().ConfigureAwait(false))
  5317. {
  5318. if (!hasValue12)
  5319. {
  5320. hasValue12 = true;
  5321. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12;
  5322. }
  5323. latestValue12 = x;
  5324. if (allHasValue)
  5325. {
  5326. TResult res;
  5327. try
  5328. {
  5329. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12).ConfigureAwait(false);
  5330. }
  5331. catch (Exception ex)
  5332. {
  5333. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5334. return;
  5335. }
  5336. await observer.OnNextAsync(res).ConfigureAwait(false);
  5337. }
  5338. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11)
  5339. {
  5340. await observer.OnCompletedAsync().ConfigureAwait(false);
  5341. }
  5342. }
  5343. },
  5344. async ex =>
  5345. {
  5346. using (await gate.LockAsync().ConfigureAwait(false))
  5347. {
  5348. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5349. }
  5350. },
  5351. async () =>
  5352. {
  5353. using (await gate.LockAsync().ConfigureAwait(false))
  5354. {
  5355. isDone12 = true;
  5356. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  5357. {
  5358. await observer.OnCompletedAsync().ConfigureAwait(false);
  5359. }
  5360. }
  5361. }
  5362. )
  5363. );
  5364. }
  5365. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>, IAsyncObserver<T13>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> selector)
  5366. {
  5367. if (observer == null)
  5368. throw new ArgumentNullException(nameof(observer));
  5369. if (selector == null)
  5370. throw new ArgumentNullException(nameof(selector));
  5371. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13)));
  5372. }
  5373. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>, IAsyncObserver<T13>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Task<TResult>> selector)
  5374. {
  5375. if (observer == null)
  5376. throw new ArgumentNullException(nameof(observer));
  5377. if (selector == null)
  5378. throw new ArgumentNullException(nameof(selector));
  5379. bool allHasValue = false;
  5380. bool hasValue1 = false;
  5381. bool isDone1 = false;
  5382. T1 latestValue1 = default(T1);
  5383. bool hasValue2 = false;
  5384. bool isDone2 = false;
  5385. T2 latestValue2 = default(T2);
  5386. bool hasValue3 = false;
  5387. bool isDone3 = false;
  5388. T3 latestValue3 = default(T3);
  5389. bool hasValue4 = false;
  5390. bool isDone4 = false;
  5391. T4 latestValue4 = default(T4);
  5392. bool hasValue5 = false;
  5393. bool isDone5 = false;
  5394. T5 latestValue5 = default(T5);
  5395. bool hasValue6 = false;
  5396. bool isDone6 = false;
  5397. T6 latestValue6 = default(T6);
  5398. bool hasValue7 = false;
  5399. bool isDone7 = false;
  5400. T7 latestValue7 = default(T7);
  5401. bool hasValue8 = false;
  5402. bool isDone8 = false;
  5403. T8 latestValue8 = default(T8);
  5404. bool hasValue9 = false;
  5405. bool isDone9 = false;
  5406. T9 latestValue9 = default(T9);
  5407. bool hasValue10 = false;
  5408. bool isDone10 = false;
  5409. T10 latestValue10 = default(T10);
  5410. bool hasValue11 = false;
  5411. bool isDone11 = false;
  5412. T11 latestValue11 = default(T11);
  5413. bool hasValue12 = false;
  5414. bool isDone12 = false;
  5415. T12 latestValue12 = default(T12);
  5416. bool hasValue13 = false;
  5417. bool isDone13 = false;
  5418. T13 latestValue13 = default(T13);
  5419. var gate = new AsyncLock();
  5420. return
  5421. (
  5422. Create<T1>(
  5423. async x =>
  5424. {
  5425. using (await gate.LockAsync().ConfigureAwait(false))
  5426. {
  5427. if (!hasValue1)
  5428. {
  5429. hasValue1 = true;
  5430. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5431. }
  5432. latestValue1 = x;
  5433. if (allHasValue)
  5434. {
  5435. TResult res;
  5436. try
  5437. {
  5438. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5439. }
  5440. catch (Exception ex)
  5441. {
  5442. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5443. return;
  5444. }
  5445. await observer.OnNextAsync(res).ConfigureAwait(false);
  5446. }
  5447. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5448. {
  5449. await observer.OnCompletedAsync().ConfigureAwait(false);
  5450. }
  5451. }
  5452. },
  5453. async ex =>
  5454. {
  5455. using (await gate.LockAsync().ConfigureAwait(false))
  5456. {
  5457. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5458. }
  5459. },
  5460. async () =>
  5461. {
  5462. using (await gate.LockAsync().ConfigureAwait(false))
  5463. {
  5464. isDone1 = true;
  5465. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5466. {
  5467. await observer.OnCompletedAsync().ConfigureAwait(false);
  5468. }
  5469. }
  5470. }
  5471. ),
  5472. Create<T2>(
  5473. async x =>
  5474. {
  5475. using (await gate.LockAsync().ConfigureAwait(false))
  5476. {
  5477. if (!hasValue2)
  5478. {
  5479. hasValue2 = true;
  5480. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5481. }
  5482. latestValue2 = x;
  5483. if (allHasValue)
  5484. {
  5485. TResult res;
  5486. try
  5487. {
  5488. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5489. }
  5490. catch (Exception ex)
  5491. {
  5492. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5493. return;
  5494. }
  5495. await observer.OnNextAsync(res).ConfigureAwait(false);
  5496. }
  5497. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5498. {
  5499. await observer.OnCompletedAsync().ConfigureAwait(false);
  5500. }
  5501. }
  5502. },
  5503. async ex =>
  5504. {
  5505. using (await gate.LockAsync().ConfigureAwait(false))
  5506. {
  5507. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5508. }
  5509. },
  5510. async () =>
  5511. {
  5512. using (await gate.LockAsync().ConfigureAwait(false))
  5513. {
  5514. isDone2 = true;
  5515. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5516. {
  5517. await observer.OnCompletedAsync().ConfigureAwait(false);
  5518. }
  5519. }
  5520. }
  5521. ),
  5522. Create<T3>(
  5523. async x =>
  5524. {
  5525. using (await gate.LockAsync().ConfigureAwait(false))
  5526. {
  5527. if (!hasValue3)
  5528. {
  5529. hasValue3 = true;
  5530. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5531. }
  5532. latestValue3 = x;
  5533. if (allHasValue)
  5534. {
  5535. TResult res;
  5536. try
  5537. {
  5538. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5539. }
  5540. catch (Exception ex)
  5541. {
  5542. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5543. return;
  5544. }
  5545. await observer.OnNextAsync(res).ConfigureAwait(false);
  5546. }
  5547. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5548. {
  5549. await observer.OnCompletedAsync().ConfigureAwait(false);
  5550. }
  5551. }
  5552. },
  5553. async ex =>
  5554. {
  5555. using (await gate.LockAsync().ConfigureAwait(false))
  5556. {
  5557. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5558. }
  5559. },
  5560. async () =>
  5561. {
  5562. using (await gate.LockAsync().ConfigureAwait(false))
  5563. {
  5564. isDone3 = true;
  5565. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5566. {
  5567. await observer.OnCompletedAsync().ConfigureAwait(false);
  5568. }
  5569. }
  5570. }
  5571. ),
  5572. Create<T4>(
  5573. async x =>
  5574. {
  5575. using (await gate.LockAsync().ConfigureAwait(false))
  5576. {
  5577. if (!hasValue4)
  5578. {
  5579. hasValue4 = true;
  5580. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5581. }
  5582. latestValue4 = x;
  5583. if (allHasValue)
  5584. {
  5585. TResult res;
  5586. try
  5587. {
  5588. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5589. }
  5590. catch (Exception ex)
  5591. {
  5592. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5593. return;
  5594. }
  5595. await observer.OnNextAsync(res).ConfigureAwait(false);
  5596. }
  5597. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5598. {
  5599. await observer.OnCompletedAsync().ConfigureAwait(false);
  5600. }
  5601. }
  5602. },
  5603. async ex =>
  5604. {
  5605. using (await gate.LockAsync().ConfigureAwait(false))
  5606. {
  5607. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5608. }
  5609. },
  5610. async () =>
  5611. {
  5612. using (await gate.LockAsync().ConfigureAwait(false))
  5613. {
  5614. isDone4 = true;
  5615. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5616. {
  5617. await observer.OnCompletedAsync().ConfigureAwait(false);
  5618. }
  5619. }
  5620. }
  5621. ),
  5622. Create<T5>(
  5623. async x =>
  5624. {
  5625. using (await gate.LockAsync().ConfigureAwait(false))
  5626. {
  5627. if (!hasValue5)
  5628. {
  5629. hasValue5 = true;
  5630. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5631. }
  5632. latestValue5 = x;
  5633. if (allHasValue)
  5634. {
  5635. TResult res;
  5636. try
  5637. {
  5638. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5639. }
  5640. catch (Exception ex)
  5641. {
  5642. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5643. return;
  5644. }
  5645. await observer.OnNextAsync(res).ConfigureAwait(false);
  5646. }
  5647. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5648. {
  5649. await observer.OnCompletedAsync().ConfigureAwait(false);
  5650. }
  5651. }
  5652. },
  5653. async ex =>
  5654. {
  5655. using (await gate.LockAsync().ConfigureAwait(false))
  5656. {
  5657. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5658. }
  5659. },
  5660. async () =>
  5661. {
  5662. using (await gate.LockAsync().ConfigureAwait(false))
  5663. {
  5664. isDone5 = true;
  5665. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5666. {
  5667. await observer.OnCompletedAsync().ConfigureAwait(false);
  5668. }
  5669. }
  5670. }
  5671. ),
  5672. Create<T6>(
  5673. async x =>
  5674. {
  5675. using (await gate.LockAsync().ConfigureAwait(false))
  5676. {
  5677. if (!hasValue6)
  5678. {
  5679. hasValue6 = true;
  5680. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5681. }
  5682. latestValue6 = x;
  5683. if (allHasValue)
  5684. {
  5685. TResult res;
  5686. try
  5687. {
  5688. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5689. }
  5690. catch (Exception ex)
  5691. {
  5692. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5693. return;
  5694. }
  5695. await observer.OnNextAsync(res).ConfigureAwait(false);
  5696. }
  5697. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5698. {
  5699. await observer.OnCompletedAsync().ConfigureAwait(false);
  5700. }
  5701. }
  5702. },
  5703. async ex =>
  5704. {
  5705. using (await gate.LockAsync().ConfigureAwait(false))
  5706. {
  5707. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5708. }
  5709. },
  5710. async () =>
  5711. {
  5712. using (await gate.LockAsync().ConfigureAwait(false))
  5713. {
  5714. isDone6 = true;
  5715. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5716. {
  5717. await observer.OnCompletedAsync().ConfigureAwait(false);
  5718. }
  5719. }
  5720. }
  5721. ),
  5722. Create<T7>(
  5723. async x =>
  5724. {
  5725. using (await gate.LockAsync().ConfigureAwait(false))
  5726. {
  5727. if (!hasValue7)
  5728. {
  5729. hasValue7 = true;
  5730. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5731. }
  5732. latestValue7 = x;
  5733. if (allHasValue)
  5734. {
  5735. TResult res;
  5736. try
  5737. {
  5738. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5739. }
  5740. catch (Exception ex)
  5741. {
  5742. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5743. return;
  5744. }
  5745. await observer.OnNextAsync(res).ConfigureAwait(false);
  5746. }
  5747. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5748. {
  5749. await observer.OnCompletedAsync().ConfigureAwait(false);
  5750. }
  5751. }
  5752. },
  5753. async ex =>
  5754. {
  5755. using (await gate.LockAsync().ConfigureAwait(false))
  5756. {
  5757. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5758. }
  5759. },
  5760. async () =>
  5761. {
  5762. using (await gate.LockAsync().ConfigureAwait(false))
  5763. {
  5764. isDone7 = true;
  5765. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5766. {
  5767. await observer.OnCompletedAsync().ConfigureAwait(false);
  5768. }
  5769. }
  5770. }
  5771. ),
  5772. Create<T8>(
  5773. async x =>
  5774. {
  5775. using (await gate.LockAsync().ConfigureAwait(false))
  5776. {
  5777. if (!hasValue8)
  5778. {
  5779. hasValue8 = true;
  5780. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5781. }
  5782. latestValue8 = x;
  5783. if (allHasValue)
  5784. {
  5785. TResult res;
  5786. try
  5787. {
  5788. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5789. }
  5790. catch (Exception ex)
  5791. {
  5792. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5793. return;
  5794. }
  5795. await observer.OnNextAsync(res).ConfigureAwait(false);
  5796. }
  5797. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5798. {
  5799. await observer.OnCompletedAsync().ConfigureAwait(false);
  5800. }
  5801. }
  5802. },
  5803. async ex =>
  5804. {
  5805. using (await gate.LockAsync().ConfigureAwait(false))
  5806. {
  5807. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5808. }
  5809. },
  5810. async () =>
  5811. {
  5812. using (await gate.LockAsync().ConfigureAwait(false))
  5813. {
  5814. isDone8 = true;
  5815. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5816. {
  5817. await observer.OnCompletedAsync().ConfigureAwait(false);
  5818. }
  5819. }
  5820. }
  5821. ),
  5822. Create<T9>(
  5823. async x =>
  5824. {
  5825. using (await gate.LockAsync().ConfigureAwait(false))
  5826. {
  5827. if (!hasValue9)
  5828. {
  5829. hasValue9 = true;
  5830. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5831. }
  5832. latestValue9 = x;
  5833. if (allHasValue)
  5834. {
  5835. TResult res;
  5836. try
  5837. {
  5838. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5839. }
  5840. catch (Exception ex)
  5841. {
  5842. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5843. return;
  5844. }
  5845. await observer.OnNextAsync(res).ConfigureAwait(false);
  5846. }
  5847. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone10 && isDone11 && isDone12 && isDone13)
  5848. {
  5849. await observer.OnCompletedAsync().ConfigureAwait(false);
  5850. }
  5851. }
  5852. },
  5853. async ex =>
  5854. {
  5855. using (await gate.LockAsync().ConfigureAwait(false))
  5856. {
  5857. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5858. }
  5859. },
  5860. async () =>
  5861. {
  5862. using (await gate.LockAsync().ConfigureAwait(false))
  5863. {
  5864. isDone9 = true;
  5865. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5866. {
  5867. await observer.OnCompletedAsync().ConfigureAwait(false);
  5868. }
  5869. }
  5870. }
  5871. ),
  5872. Create<T10>(
  5873. async x =>
  5874. {
  5875. using (await gate.LockAsync().ConfigureAwait(false))
  5876. {
  5877. if (!hasValue10)
  5878. {
  5879. hasValue10 = true;
  5880. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5881. }
  5882. latestValue10 = x;
  5883. if (allHasValue)
  5884. {
  5885. TResult res;
  5886. try
  5887. {
  5888. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5889. }
  5890. catch (Exception ex)
  5891. {
  5892. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5893. return;
  5894. }
  5895. await observer.OnNextAsync(res).ConfigureAwait(false);
  5896. }
  5897. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone11 && isDone12 && isDone13)
  5898. {
  5899. await observer.OnCompletedAsync().ConfigureAwait(false);
  5900. }
  5901. }
  5902. },
  5903. async ex =>
  5904. {
  5905. using (await gate.LockAsync().ConfigureAwait(false))
  5906. {
  5907. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5908. }
  5909. },
  5910. async () =>
  5911. {
  5912. using (await gate.LockAsync().ConfigureAwait(false))
  5913. {
  5914. isDone10 = true;
  5915. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5916. {
  5917. await observer.OnCompletedAsync().ConfigureAwait(false);
  5918. }
  5919. }
  5920. }
  5921. ),
  5922. Create<T11>(
  5923. async x =>
  5924. {
  5925. using (await gate.LockAsync().ConfigureAwait(false))
  5926. {
  5927. if (!hasValue11)
  5928. {
  5929. hasValue11 = true;
  5930. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5931. }
  5932. latestValue11 = x;
  5933. if (allHasValue)
  5934. {
  5935. TResult res;
  5936. try
  5937. {
  5938. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5939. }
  5940. catch (Exception ex)
  5941. {
  5942. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5943. return;
  5944. }
  5945. await observer.OnNextAsync(res).ConfigureAwait(false);
  5946. }
  5947. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone12 && isDone13)
  5948. {
  5949. await observer.OnCompletedAsync().ConfigureAwait(false);
  5950. }
  5951. }
  5952. },
  5953. async ex =>
  5954. {
  5955. using (await gate.LockAsync().ConfigureAwait(false))
  5956. {
  5957. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5958. }
  5959. },
  5960. async () =>
  5961. {
  5962. using (await gate.LockAsync().ConfigureAwait(false))
  5963. {
  5964. isDone11 = true;
  5965. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  5966. {
  5967. await observer.OnCompletedAsync().ConfigureAwait(false);
  5968. }
  5969. }
  5970. }
  5971. ),
  5972. Create<T12>(
  5973. async x =>
  5974. {
  5975. using (await gate.LockAsync().ConfigureAwait(false))
  5976. {
  5977. if (!hasValue12)
  5978. {
  5979. hasValue12 = true;
  5980. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  5981. }
  5982. latestValue12 = x;
  5983. if (allHasValue)
  5984. {
  5985. TResult res;
  5986. try
  5987. {
  5988. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  5989. }
  5990. catch (Exception ex)
  5991. {
  5992. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  5993. return;
  5994. }
  5995. await observer.OnNextAsync(res).ConfigureAwait(false);
  5996. }
  5997. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone13)
  5998. {
  5999. await observer.OnCompletedAsync().ConfigureAwait(false);
  6000. }
  6001. }
  6002. },
  6003. async ex =>
  6004. {
  6005. using (await gate.LockAsync().ConfigureAwait(false))
  6006. {
  6007. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6008. }
  6009. },
  6010. async () =>
  6011. {
  6012. using (await gate.LockAsync().ConfigureAwait(false))
  6013. {
  6014. isDone12 = true;
  6015. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  6016. {
  6017. await observer.OnCompletedAsync().ConfigureAwait(false);
  6018. }
  6019. }
  6020. }
  6021. ),
  6022. Create<T13>(
  6023. async x =>
  6024. {
  6025. using (await gate.LockAsync().ConfigureAwait(false))
  6026. {
  6027. if (!hasValue13)
  6028. {
  6029. hasValue13 = true;
  6030. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13;
  6031. }
  6032. latestValue13 = x;
  6033. if (allHasValue)
  6034. {
  6035. TResult res;
  6036. try
  6037. {
  6038. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13).ConfigureAwait(false);
  6039. }
  6040. catch (Exception ex)
  6041. {
  6042. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6043. return;
  6044. }
  6045. await observer.OnNextAsync(res).ConfigureAwait(false);
  6046. }
  6047. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12)
  6048. {
  6049. await observer.OnCompletedAsync().ConfigureAwait(false);
  6050. }
  6051. }
  6052. },
  6053. async ex =>
  6054. {
  6055. using (await gate.LockAsync().ConfigureAwait(false))
  6056. {
  6057. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6058. }
  6059. },
  6060. async () =>
  6061. {
  6062. using (await gate.LockAsync().ConfigureAwait(false))
  6063. {
  6064. isDone13 = true;
  6065. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  6066. {
  6067. await observer.OnCompletedAsync().ConfigureAwait(false);
  6068. }
  6069. }
  6070. }
  6071. )
  6072. );
  6073. }
  6074. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>, IAsyncObserver<T13>, IAsyncObserver<T14>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> selector)
  6075. {
  6076. if (observer == null)
  6077. throw new ArgumentNullException(nameof(observer));
  6078. if (selector == null)
  6079. throw new ArgumentNullException(nameof(selector));
  6080. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14)));
  6081. }
  6082. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>, IAsyncObserver<T13>, IAsyncObserver<T14>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Task<TResult>> selector)
  6083. {
  6084. if (observer == null)
  6085. throw new ArgumentNullException(nameof(observer));
  6086. if (selector == null)
  6087. throw new ArgumentNullException(nameof(selector));
  6088. bool allHasValue = false;
  6089. bool hasValue1 = false;
  6090. bool isDone1 = false;
  6091. T1 latestValue1 = default(T1);
  6092. bool hasValue2 = false;
  6093. bool isDone2 = false;
  6094. T2 latestValue2 = default(T2);
  6095. bool hasValue3 = false;
  6096. bool isDone3 = false;
  6097. T3 latestValue3 = default(T3);
  6098. bool hasValue4 = false;
  6099. bool isDone4 = false;
  6100. T4 latestValue4 = default(T4);
  6101. bool hasValue5 = false;
  6102. bool isDone5 = false;
  6103. T5 latestValue5 = default(T5);
  6104. bool hasValue6 = false;
  6105. bool isDone6 = false;
  6106. T6 latestValue6 = default(T6);
  6107. bool hasValue7 = false;
  6108. bool isDone7 = false;
  6109. T7 latestValue7 = default(T7);
  6110. bool hasValue8 = false;
  6111. bool isDone8 = false;
  6112. T8 latestValue8 = default(T8);
  6113. bool hasValue9 = false;
  6114. bool isDone9 = false;
  6115. T9 latestValue9 = default(T9);
  6116. bool hasValue10 = false;
  6117. bool isDone10 = false;
  6118. T10 latestValue10 = default(T10);
  6119. bool hasValue11 = false;
  6120. bool isDone11 = false;
  6121. T11 latestValue11 = default(T11);
  6122. bool hasValue12 = false;
  6123. bool isDone12 = false;
  6124. T12 latestValue12 = default(T12);
  6125. bool hasValue13 = false;
  6126. bool isDone13 = false;
  6127. T13 latestValue13 = default(T13);
  6128. bool hasValue14 = false;
  6129. bool isDone14 = false;
  6130. T14 latestValue14 = default(T14);
  6131. var gate = new AsyncLock();
  6132. return
  6133. (
  6134. Create<T1>(
  6135. async x =>
  6136. {
  6137. using (await gate.LockAsync().ConfigureAwait(false))
  6138. {
  6139. if (!hasValue1)
  6140. {
  6141. hasValue1 = true;
  6142. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6143. }
  6144. latestValue1 = x;
  6145. if (allHasValue)
  6146. {
  6147. TResult res;
  6148. try
  6149. {
  6150. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6151. }
  6152. catch (Exception ex)
  6153. {
  6154. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6155. return;
  6156. }
  6157. await observer.OnNextAsync(res).ConfigureAwait(false);
  6158. }
  6159. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6160. {
  6161. await observer.OnCompletedAsync().ConfigureAwait(false);
  6162. }
  6163. }
  6164. },
  6165. async ex =>
  6166. {
  6167. using (await gate.LockAsync().ConfigureAwait(false))
  6168. {
  6169. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6170. }
  6171. },
  6172. async () =>
  6173. {
  6174. using (await gate.LockAsync().ConfigureAwait(false))
  6175. {
  6176. isDone1 = true;
  6177. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6178. {
  6179. await observer.OnCompletedAsync().ConfigureAwait(false);
  6180. }
  6181. }
  6182. }
  6183. ),
  6184. Create<T2>(
  6185. async x =>
  6186. {
  6187. using (await gate.LockAsync().ConfigureAwait(false))
  6188. {
  6189. if (!hasValue2)
  6190. {
  6191. hasValue2 = true;
  6192. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6193. }
  6194. latestValue2 = x;
  6195. if (allHasValue)
  6196. {
  6197. TResult res;
  6198. try
  6199. {
  6200. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6201. }
  6202. catch (Exception ex)
  6203. {
  6204. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6205. return;
  6206. }
  6207. await observer.OnNextAsync(res).ConfigureAwait(false);
  6208. }
  6209. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6210. {
  6211. await observer.OnCompletedAsync().ConfigureAwait(false);
  6212. }
  6213. }
  6214. },
  6215. async ex =>
  6216. {
  6217. using (await gate.LockAsync().ConfigureAwait(false))
  6218. {
  6219. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6220. }
  6221. },
  6222. async () =>
  6223. {
  6224. using (await gate.LockAsync().ConfigureAwait(false))
  6225. {
  6226. isDone2 = true;
  6227. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6228. {
  6229. await observer.OnCompletedAsync().ConfigureAwait(false);
  6230. }
  6231. }
  6232. }
  6233. ),
  6234. Create<T3>(
  6235. async x =>
  6236. {
  6237. using (await gate.LockAsync().ConfigureAwait(false))
  6238. {
  6239. if (!hasValue3)
  6240. {
  6241. hasValue3 = true;
  6242. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6243. }
  6244. latestValue3 = x;
  6245. if (allHasValue)
  6246. {
  6247. TResult res;
  6248. try
  6249. {
  6250. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6251. }
  6252. catch (Exception ex)
  6253. {
  6254. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6255. return;
  6256. }
  6257. await observer.OnNextAsync(res).ConfigureAwait(false);
  6258. }
  6259. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6260. {
  6261. await observer.OnCompletedAsync().ConfigureAwait(false);
  6262. }
  6263. }
  6264. },
  6265. async ex =>
  6266. {
  6267. using (await gate.LockAsync().ConfigureAwait(false))
  6268. {
  6269. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6270. }
  6271. },
  6272. async () =>
  6273. {
  6274. using (await gate.LockAsync().ConfigureAwait(false))
  6275. {
  6276. isDone3 = true;
  6277. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6278. {
  6279. await observer.OnCompletedAsync().ConfigureAwait(false);
  6280. }
  6281. }
  6282. }
  6283. ),
  6284. Create<T4>(
  6285. async x =>
  6286. {
  6287. using (await gate.LockAsync().ConfigureAwait(false))
  6288. {
  6289. if (!hasValue4)
  6290. {
  6291. hasValue4 = true;
  6292. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6293. }
  6294. latestValue4 = x;
  6295. if (allHasValue)
  6296. {
  6297. TResult res;
  6298. try
  6299. {
  6300. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6301. }
  6302. catch (Exception ex)
  6303. {
  6304. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6305. return;
  6306. }
  6307. await observer.OnNextAsync(res).ConfigureAwait(false);
  6308. }
  6309. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6310. {
  6311. await observer.OnCompletedAsync().ConfigureAwait(false);
  6312. }
  6313. }
  6314. },
  6315. async ex =>
  6316. {
  6317. using (await gate.LockAsync().ConfigureAwait(false))
  6318. {
  6319. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6320. }
  6321. },
  6322. async () =>
  6323. {
  6324. using (await gate.LockAsync().ConfigureAwait(false))
  6325. {
  6326. isDone4 = true;
  6327. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6328. {
  6329. await observer.OnCompletedAsync().ConfigureAwait(false);
  6330. }
  6331. }
  6332. }
  6333. ),
  6334. Create<T5>(
  6335. async x =>
  6336. {
  6337. using (await gate.LockAsync().ConfigureAwait(false))
  6338. {
  6339. if (!hasValue5)
  6340. {
  6341. hasValue5 = true;
  6342. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6343. }
  6344. latestValue5 = x;
  6345. if (allHasValue)
  6346. {
  6347. TResult res;
  6348. try
  6349. {
  6350. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6351. }
  6352. catch (Exception ex)
  6353. {
  6354. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6355. return;
  6356. }
  6357. await observer.OnNextAsync(res).ConfigureAwait(false);
  6358. }
  6359. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6360. {
  6361. await observer.OnCompletedAsync().ConfigureAwait(false);
  6362. }
  6363. }
  6364. },
  6365. async ex =>
  6366. {
  6367. using (await gate.LockAsync().ConfigureAwait(false))
  6368. {
  6369. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6370. }
  6371. },
  6372. async () =>
  6373. {
  6374. using (await gate.LockAsync().ConfigureAwait(false))
  6375. {
  6376. isDone5 = true;
  6377. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6378. {
  6379. await observer.OnCompletedAsync().ConfigureAwait(false);
  6380. }
  6381. }
  6382. }
  6383. ),
  6384. Create<T6>(
  6385. async x =>
  6386. {
  6387. using (await gate.LockAsync().ConfigureAwait(false))
  6388. {
  6389. if (!hasValue6)
  6390. {
  6391. hasValue6 = true;
  6392. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6393. }
  6394. latestValue6 = x;
  6395. if (allHasValue)
  6396. {
  6397. TResult res;
  6398. try
  6399. {
  6400. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6401. }
  6402. catch (Exception ex)
  6403. {
  6404. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6405. return;
  6406. }
  6407. await observer.OnNextAsync(res).ConfigureAwait(false);
  6408. }
  6409. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6410. {
  6411. await observer.OnCompletedAsync().ConfigureAwait(false);
  6412. }
  6413. }
  6414. },
  6415. async ex =>
  6416. {
  6417. using (await gate.LockAsync().ConfigureAwait(false))
  6418. {
  6419. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6420. }
  6421. },
  6422. async () =>
  6423. {
  6424. using (await gate.LockAsync().ConfigureAwait(false))
  6425. {
  6426. isDone6 = true;
  6427. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6428. {
  6429. await observer.OnCompletedAsync().ConfigureAwait(false);
  6430. }
  6431. }
  6432. }
  6433. ),
  6434. Create<T7>(
  6435. async x =>
  6436. {
  6437. using (await gate.LockAsync().ConfigureAwait(false))
  6438. {
  6439. if (!hasValue7)
  6440. {
  6441. hasValue7 = true;
  6442. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6443. }
  6444. latestValue7 = x;
  6445. if (allHasValue)
  6446. {
  6447. TResult res;
  6448. try
  6449. {
  6450. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6451. }
  6452. catch (Exception ex)
  6453. {
  6454. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6455. return;
  6456. }
  6457. await observer.OnNextAsync(res).ConfigureAwait(false);
  6458. }
  6459. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6460. {
  6461. await observer.OnCompletedAsync().ConfigureAwait(false);
  6462. }
  6463. }
  6464. },
  6465. async ex =>
  6466. {
  6467. using (await gate.LockAsync().ConfigureAwait(false))
  6468. {
  6469. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6470. }
  6471. },
  6472. async () =>
  6473. {
  6474. using (await gate.LockAsync().ConfigureAwait(false))
  6475. {
  6476. isDone7 = true;
  6477. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6478. {
  6479. await observer.OnCompletedAsync().ConfigureAwait(false);
  6480. }
  6481. }
  6482. }
  6483. ),
  6484. Create<T8>(
  6485. async x =>
  6486. {
  6487. using (await gate.LockAsync().ConfigureAwait(false))
  6488. {
  6489. if (!hasValue8)
  6490. {
  6491. hasValue8 = true;
  6492. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6493. }
  6494. latestValue8 = x;
  6495. if (allHasValue)
  6496. {
  6497. TResult res;
  6498. try
  6499. {
  6500. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6501. }
  6502. catch (Exception ex)
  6503. {
  6504. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6505. return;
  6506. }
  6507. await observer.OnNextAsync(res).ConfigureAwait(false);
  6508. }
  6509. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6510. {
  6511. await observer.OnCompletedAsync().ConfigureAwait(false);
  6512. }
  6513. }
  6514. },
  6515. async ex =>
  6516. {
  6517. using (await gate.LockAsync().ConfigureAwait(false))
  6518. {
  6519. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6520. }
  6521. },
  6522. async () =>
  6523. {
  6524. using (await gate.LockAsync().ConfigureAwait(false))
  6525. {
  6526. isDone8 = true;
  6527. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6528. {
  6529. await observer.OnCompletedAsync().ConfigureAwait(false);
  6530. }
  6531. }
  6532. }
  6533. ),
  6534. Create<T9>(
  6535. async x =>
  6536. {
  6537. using (await gate.LockAsync().ConfigureAwait(false))
  6538. {
  6539. if (!hasValue9)
  6540. {
  6541. hasValue9 = true;
  6542. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6543. }
  6544. latestValue9 = x;
  6545. if (allHasValue)
  6546. {
  6547. TResult res;
  6548. try
  6549. {
  6550. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6551. }
  6552. catch (Exception ex)
  6553. {
  6554. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6555. return;
  6556. }
  6557. await observer.OnNextAsync(res).ConfigureAwait(false);
  6558. }
  6559. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6560. {
  6561. await observer.OnCompletedAsync().ConfigureAwait(false);
  6562. }
  6563. }
  6564. },
  6565. async ex =>
  6566. {
  6567. using (await gate.LockAsync().ConfigureAwait(false))
  6568. {
  6569. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6570. }
  6571. },
  6572. async () =>
  6573. {
  6574. using (await gate.LockAsync().ConfigureAwait(false))
  6575. {
  6576. isDone9 = true;
  6577. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6578. {
  6579. await observer.OnCompletedAsync().ConfigureAwait(false);
  6580. }
  6581. }
  6582. }
  6583. ),
  6584. Create<T10>(
  6585. async x =>
  6586. {
  6587. using (await gate.LockAsync().ConfigureAwait(false))
  6588. {
  6589. if (!hasValue10)
  6590. {
  6591. hasValue10 = true;
  6592. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6593. }
  6594. latestValue10 = x;
  6595. if (allHasValue)
  6596. {
  6597. TResult res;
  6598. try
  6599. {
  6600. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6601. }
  6602. catch (Exception ex)
  6603. {
  6604. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6605. return;
  6606. }
  6607. await observer.OnNextAsync(res).ConfigureAwait(false);
  6608. }
  6609. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone11 && isDone12 && isDone13 && isDone14)
  6610. {
  6611. await observer.OnCompletedAsync().ConfigureAwait(false);
  6612. }
  6613. }
  6614. },
  6615. async ex =>
  6616. {
  6617. using (await gate.LockAsync().ConfigureAwait(false))
  6618. {
  6619. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6620. }
  6621. },
  6622. async () =>
  6623. {
  6624. using (await gate.LockAsync().ConfigureAwait(false))
  6625. {
  6626. isDone10 = true;
  6627. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6628. {
  6629. await observer.OnCompletedAsync().ConfigureAwait(false);
  6630. }
  6631. }
  6632. }
  6633. ),
  6634. Create<T11>(
  6635. async x =>
  6636. {
  6637. using (await gate.LockAsync().ConfigureAwait(false))
  6638. {
  6639. if (!hasValue11)
  6640. {
  6641. hasValue11 = true;
  6642. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6643. }
  6644. latestValue11 = x;
  6645. if (allHasValue)
  6646. {
  6647. TResult res;
  6648. try
  6649. {
  6650. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6651. }
  6652. catch (Exception ex)
  6653. {
  6654. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6655. return;
  6656. }
  6657. await observer.OnNextAsync(res).ConfigureAwait(false);
  6658. }
  6659. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone12 && isDone13 && isDone14)
  6660. {
  6661. await observer.OnCompletedAsync().ConfigureAwait(false);
  6662. }
  6663. }
  6664. },
  6665. async ex =>
  6666. {
  6667. using (await gate.LockAsync().ConfigureAwait(false))
  6668. {
  6669. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6670. }
  6671. },
  6672. async () =>
  6673. {
  6674. using (await gate.LockAsync().ConfigureAwait(false))
  6675. {
  6676. isDone11 = true;
  6677. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6678. {
  6679. await observer.OnCompletedAsync().ConfigureAwait(false);
  6680. }
  6681. }
  6682. }
  6683. ),
  6684. Create<T12>(
  6685. async x =>
  6686. {
  6687. using (await gate.LockAsync().ConfigureAwait(false))
  6688. {
  6689. if (!hasValue12)
  6690. {
  6691. hasValue12 = true;
  6692. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6693. }
  6694. latestValue12 = x;
  6695. if (allHasValue)
  6696. {
  6697. TResult res;
  6698. try
  6699. {
  6700. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6701. }
  6702. catch (Exception ex)
  6703. {
  6704. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6705. return;
  6706. }
  6707. await observer.OnNextAsync(res).ConfigureAwait(false);
  6708. }
  6709. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone13 && isDone14)
  6710. {
  6711. await observer.OnCompletedAsync().ConfigureAwait(false);
  6712. }
  6713. }
  6714. },
  6715. async ex =>
  6716. {
  6717. using (await gate.LockAsync().ConfigureAwait(false))
  6718. {
  6719. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6720. }
  6721. },
  6722. async () =>
  6723. {
  6724. using (await gate.LockAsync().ConfigureAwait(false))
  6725. {
  6726. isDone12 = true;
  6727. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6728. {
  6729. await observer.OnCompletedAsync().ConfigureAwait(false);
  6730. }
  6731. }
  6732. }
  6733. ),
  6734. Create<T13>(
  6735. async x =>
  6736. {
  6737. using (await gate.LockAsync().ConfigureAwait(false))
  6738. {
  6739. if (!hasValue13)
  6740. {
  6741. hasValue13 = true;
  6742. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6743. }
  6744. latestValue13 = x;
  6745. if (allHasValue)
  6746. {
  6747. TResult res;
  6748. try
  6749. {
  6750. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6751. }
  6752. catch (Exception ex)
  6753. {
  6754. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6755. return;
  6756. }
  6757. await observer.OnNextAsync(res).ConfigureAwait(false);
  6758. }
  6759. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone14)
  6760. {
  6761. await observer.OnCompletedAsync().ConfigureAwait(false);
  6762. }
  6763. }
  6764. },
  6765. async ex =>
  6766. {
  6767. using (await gate.LockAsync().ConfigureAwait(false))
  6768. {
  6769. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6770. }
  6771. },
  6772. async () =>
  6773. {
  6774. using (await gate.LockAsync().ConfigureAwait(false))
  6775. {
  6776. isDone13 = true;
  6777. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6778. {
  6779. await observer.OnCompletedAsync().ConfigureAwait(false);
  6780. }
  6781. }
  6782. }
  6783. ),
  6784. Create<T14>(
  6785. async x =>
  6786. {
  6787. using (await gate.LockAsync().ConfigureAwait(false))
  6788. {
  6789. if (!hasValue14)
  6790. {
  6791. hasValue14 = true;
  6792. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14;
  6793. }
  6794. latestValue14 = x;
  6795. if (allHasValue)
  6796. {
  6797. TResult res;
  6798. try
  6799. {
  6800. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14).ConfigureAwait(false);
  6801. }
  6802. catch (Exception ex)
  6803. {
  6804. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6805. return;
  6806. }
  6807. await observer.OnNextAsync(res).ConfigureAwait(false);
  6808. }
  6809. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13)
  6810. {
  6811. await observer.OnCompletedAsync().ConfigureAwait(false);
  6812. }
  6813. }
  6814. },
  6815. async ex =>
  6816. {
  6817. using (await gate.LockAsync().ConfigureAwait(false))
  6818. {
  6819. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6820. }
  6821. },
  6822. async () =>
  6823. {
  6824. using (await gate.LockAsync().ConfigureAwait(false))
  6825. {
  6826. isDone14 = true;
  6827. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  6828. {
  6829. await observer.OnCompletedAsync().ConfigureAwait(false);
  6830. }
  6831. }
  6832. }
  6833. )
  6834. );
  6835. }
  6836. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>, IAsyncObserver<T13>, IAsyncObserver<T14>, IAsyncObserver<T15>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> selector)
  6837. {
  6838. if (observer == null)
  6839. throw new ArgumentNullException(nameof(observer));
  6840. if (selector == null)
  6841. throw new ArgumentNullException(nameof(selector));
  6842. return CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(observer, (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15) => Task.FromResult(selector(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15)));
  6843. }
  6844. public static (IAsyncObserver<T1>, IAsyncObserver<T2>, IAsyncObserver<T3>, IAsyncObserver<T4>, IAsyncObserver<T5>, IAsyncObserver<T6>, IAsyncObserver<T7>, IAsyncObserver<T8>, IAsyncObserver<T9>, IAsyncObserver<T10>, IAsyncObserver<T11>, IAsyncObserver<T12>, IAsyncObserver<T13>, IAsyncObserver<T14>, IAsyncObserver<T15>) CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(this IAsyncObserver<TResult> observer, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Task<TResult>> selector)
  6845. {
  6846. if (observer == null)
  6847. throw new ArgumentNullException(nameof(observer));
  6848. if (selector == null)
  6849. throw new ArgumentNullException(nameof(selector));
  6850. bool allHasValue = false;
  6851. bool hasValue1 = false;
  6852. bool isDone1 = false;
  6853. T1 latestValue1 = default(T1);
  6854. bool hasValue2 = false;
  6855. bool isDone2 = false;
  6856. T2 latestValue2 = default(T2);
  6857. bool hasValue3 = false;
  6858. bool isDone3 = false;
  6859. T3 latestValue3 = default(T3);
  6860. bool hasValue4 = false;
  6861. bool isDone4 = false;
  6862. T4 latestValue4 = default(T4);
  6863. bool hasValue5 = false;
  6864. bool isDone5 = false;
  6865. T5 latestValue5 = default(T5);
  6866. bool hasValue6 = false;
  6867. bool isDone6 = false;
  6868. T6 latestValue6 = default(T6);
  6869. bool hasValue7 = false;
  6870. bool isDone7 = false;
  6871. T7 latestValue7 = default(T7);
  6872. bool hasValue8 = false;
  6873. bool isDone8 = false;
  6874. T8 latestValue8 = default(T8);
  6875. bool hasValue9 = false;
  6876. bool isDone9 = false;
  6877. T9 latestValue9 = default(T9);
  6878. bool hasValue10 = false;
  6879. bool isDone10 = false;
  6880. T10 latestValue10 = default(T10);
  6881. bool hasValue11 = false;
  6882. bool isDone11 = false;
  6883. T11 latestValue11 = default(T11);
  6884. bool hasValue12 = false;
  6885. bool isDone12 = false;
  6886. T12 latestValue12 = default(T12);
  6887. bool hasValue13 = false;
  6888. bool isDone13 = false;
  6889. T13 latestValue13 = default(T13);
  6890. bool hasValue14 = false;
  6891. bool isDone14 = false;
  6892. T14 latestValue14 = default(T14);
  6893. bool hasValue15 = false;
  6894. bool isDone15 = false;
  6895. T15 latestValue15 = default(T15);
  6896. var gate = new AsyncLock();
  6897. return
  6898. (
  6899. Create<T1>(
  6900. async x =>
  6901. {
  6902. using (await gate.LockAsync().ConfigureAwait(false))
  6903. {
  6904. if (!hasValue1)
  6905. {
  6906. hasValue1 = true;
  6907. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  6908. }
  6909. latestValue1 = x;
  6910. if (allHasValue)
  6911. {
  6912. TResult res;
  6913. try
  6914. {
  6915. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  6916. }
  6917. catch (Exception ex)
  6918. {
  6919. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6920. return;
  6921. }
  6922. await observer.OnNextAsync(res).ConfigureAwait(false);
  6923. }
  6924. else if (isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  6925. {
  6926. await observer.OnCompletedAsync().ConfigureAwait(false);
  6927. }
  6928. }
  6929. },
  6930. async ex =>
  6931. {
  6932. using (await gate.LockAsync().ConfigureAwait(false))
  6933. {
  6934. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6935. }
  6936. },
  6937. async () =>
  6938. {
  6939. using (await gate.LockAsync().ConfigureAwait(false))
  6940. {
  6941. isDone1 = true;
  6942. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  6943. {
  6944. await observer.OnCompletedAsync().ConfigureAwait(false);
  6945. }
  6946. }
  6947. }
  6948. ),
  6949. Create<T2>(
  6950. async x =>
  6951. {
  6952. using (await gate.LockAsync().ConfigureAwait(false))
  6953. {
  6954. if (!hasValue2)
  6955. {
  6956. hasValue2 = true;
  6957. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  6958. }
  6959. latestValue2 = x;
  6960. if (allHasValue)
  6961. {
  6962. TResult res;
  6963. try
  6964. {
  6965. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  6966. }
  6967. catch (Exception ex)
  6968. {
  6969. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6970. return;
  6971. }
  6972. await observer.OnNextAsync(res).ConfigureAwait(false);
  6973. }
  6974. else if (isDone1 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  6975. {
  6976. await observer.OnCompletedAsync().ConfigureAwait(false);
  6977. }
  6978. }
  6979. },
  6980. async ex =>
  6981. {
  6982. using (await gate.LockAsync().ConfigureAwait(false))
  6983. {
  6984. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  6985. }
  6986. },
  6987. async () =>
  6988. {
  6989. using (await gate.LockAsync().ConfigureAwait(false))
  6990. {
  6991. isDone2 = true;
  6992. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  6993. {
  6994. await observer.OnCompletedAsync().ConfigureAwait(false);
  6995. }
  6996. }
  6997. }
  6998. ),
  6999. Create<T3>(
  7000. async x =>
  7001. {
  7002. using (await gate.LockAsync().ConfigureAwait(false))
  7003. {
  7004. if (!hasValue3)
  7005. {
  7006. hasValue3 = true;
  7007. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7008. }
  7009. latestValue3 = x;
  7010. if (allHasValue)
  7011. {
  7012. TResult res;
  7013. try
  7014. {
  7015. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7016. }
  7017. catch (Exception ex)
  7018. {
  7019. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7020. return;
  7021. }
  7022. await observer.OnNextAsync(res).ConfigureAwait(false);
  7023. }
  7024. else if (isDone1 && isDone2 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7025. {
  7026. await observer.OnCompletedAsync().ConfigureAwait(false);
  7027. }
  7028. }
  7029. },
  7030. async ex =>
  7031. {
  7032. using (await gate.LockAsync().ConfigureAwait(false))
  7033. {
  7034. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7035. }
  7036. },
  7037. async () =>
  7038. {
  7039. using (await gate.LockAsync().ConfigureAwait(false))
  7040. {
  7041. isDone3 = true;
  7042. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7043. {
  7044. await observer.OnCompletedAsync().ConfigureAwait(false);
  7045. }
  7046. }
  7047. }
  7048. ),
  7049. Create<T4>(
  7050. async x =>
  7051. {
  7052. using (await gate.LockAsync().ConfigureAwait(false))
  7053. {
  7054. if (!hasValue4)
  7055. {
  7056. hasValue4 = true;
  7057. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7058. }
  7059. latestValue4 = x;
  7060. if (allHasValue)
  7061. {
  7062. TResult res;
  7063. try
  7064. {
  7065. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7066. }
  7067. catch (Exception ex)
  7068. {
  7069. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7070. return;
  7071. }
  7072. await observer.OnNextAsync(res).ConfigureAwait(false);
  7073. }
  7074. else if (isDone1 && isDone2 && isDone3 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7075. {
  7076. await observer.OnCompletedAsync().ConfigureAwait(false);
  7077. }
  7078. }
  7079. },
  7080. async ex =>
  7081. {
  7082. using (await gate.LockAsync().ConfigureAwait(false))
  7083. {
  7084. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7085. }
  7086. },
  7087. async () =>
  7088. {
  7089. using (await gate.LockAsync().ConfigureAwait(false))
  7090. {
  7091. isDone4 = true;
  7092. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7093. {
  7094. await observer.OnCompletedAsync().ConfigureAwait(false);
  7095. }
  7096. }
  7097. }
  7098. ),
  7099. Create<T5>(
  7100. async x =>
  7101. {
  7102. using (await gate.LockAsync().ConfigureAwait(false))
  7103. {
  7104. if (!hasValue5)
  7105. {
  7106. hasValue5 = true;
  7107. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7108. }
  7109. latestValue5 = x;
  7110. if (allHasValue)
  7111. {
  7112. TResult res;
  7113. try
  7114. {
  7115. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7116. }
  7117. catch (Exception ex)
  7118. {
  7119. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7120. return;
  7121. }
  7122. await observer.OnNextAsync(res).ConfigureAwait(false);
  7123. }
  7124. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7125. {
  7126. await observer.OnCompletedAsync().ConfigureAwait(false);
  7127. }
  7128. }
  7129. },
  7130. async ex =>
  7131. {
  7132. using (await gate.LockAsync().ConfigureAwait(false))
  7133. {
  7134. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7135. }
  7136. },
  7137. async () =>
  7138. {
  7139. using (await gate.LockAsync().ConfigureAwait(false))
  7140. {
  7141. isDone5 = true;
  7142. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7143. {
  7144. await observer.OnCompletedAsync().ConfigureAwait(false);
  7145. }
  7146. }
  7147. }
  7148. ),
  7149. Create<T6>(
  7150. async x =>
  7151. {
  7152. using (await gate.LockAsync().ConfigureAwait(false))
  7153. {
  7154. if (!hasValue6)
  7155. {
  7156. hasValue6 = true;
  7157. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7158. }
  7159. latestValue6 = x;
  7160. if (allHasValue)
  7161. {
  7162. TResult res;
  7163. try
  7164. {
  7165. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7166. }
  7167. catch (Exception ex)
  7168. {
  7169. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7170. return;
  7171. }
  7172. await observer.OnNextAsync(res).ConfigureAwait(false);
  7173. }
  7174. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7175. {
  7176. await observer.OnCompletedAsync().ConfigureAwait(false);
  7177. }
  7178. }
  7179. },
  7180. async ex =>
  7181. {
  7182. using (await gate.LockAsync().ConfigureAwait(false))
  7183. {
  7184. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7185. }
  7186. },
  7187. async () =>
  7188. {
  7189. using (await gate.LockAsync().ConfigureAwait(false))
  7190. {
  7191. isDone6 = true;
  7192. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7193. {
  7194. await observer.OnCompletedAsync().ConfigureAwait(false);
  7195. }
  7196. }
  7197. }
  7198. ),
  7199. Create<T7>(
  7200. async x =>
  7201. {
  7202. using (await gate.LockAsync().ConfigureAwait(false))
  7203. {
  7204. if (!hasValue7)
  7205. {
  7206. hasValue7 = true;
  7207. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7208. }
  7209. latestValue7 = x;
  7210. if (allHasValue)
  7211. {
  7212. TResult res;
  7213. try
  7214. {
  7215. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7216. }
  7217. catch (Exception ex)
  7218. {
  7219. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7220. return;
  7221. }
  7222. await observer.OnNextAsync(res).ConfigureAwait(false);
  7223. }
  7224. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7225. {
  7226. await observer.OnCompletedAsync().ConfigureAwait(false);
  7227. }
  7228. }
  7229. },
  7230. async ex =>
  7231. {
  7232. using (await gate.LockAsync().ConfigureAwait(false))
  7233. {
  7234. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7235. }
  7236. },
  7237. async () =>
  7238. {
  7239. using (await gate.LockAsync().ConfigureAwait(false))
  7240. {
  7241. isDone7 = true;
  7242. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7243. {
  7244. await observer.OnCompletedAsync().ConfigureAwait(false);
  7245. }
  7246. }
  7247. }
  7248. ),
  7249. Create<T8>(
  7250. async x =>
  7251. {
  7252. using (await gate.LockAsync().ConfigureAwait(false))
  7253. {
  7254. if (!hasValue8)
  7255. {
  7256. hasValue8 = true;
  7257. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7258. }
  7259. latestValue8 = x;
  7260. if (allHasValue)
  7261. {
  7262. TResult res;
  7263. try
  7264. {
  7265. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7266. }
  7267. catch (Exception ex)
  7268. {
  7269. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7270. return;
  7271. }
  7272. await observer.OnNextAsync(res).ConfigureAwait(false);
  7273. }
  7274. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7275. {
  7276. await observer.OnCompletedAsync().ConfigureAwait(false);
  7277. }
  7278. }
  7279. },
  7280. async ex =>
  7281. {
  7282. using (await gate.LockAsync().ConfigureAwait(false))
  7283. {
  7284. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7285. }
  7286. },
  7287. async () =>
  7288. {
  7289. using (await gate.LockAsync().ConfigureAwait(false))
  7290. {
  7291. isDone8 = true;
  7292. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7293. {
  7294. await observer.OnCompletedAsync().ConfigureAwait(false);
  7295. }
  7296. }
  7297. }
  7298. ),
  7299. Create<T9>(
  7300. async x =>
  7301. {
  7302. using (await gate.LockAsync().ConfigureAwait(false))
  7303. {
  7304. if (!hasValue9)
  7305. {
  7306. hasValue9 = true;
  7307. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7308. }
  7309. latestValue9 = x;
  7310. if (allHasValue)
  7311. {
  7312. TResult res;
  7313. try
  7314. {
  7315. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7316. }
  7317. catch (Exception ex)
  7318. {
  7319. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7320. return;
  7321. }
  7322. await observer.OnNextAsync(res).ConfigureAwait(false);
  7323. }
  7324. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7325. {
  7326. await observer.OnCompletedAsync().ConfigureAwait(false);
  7327. }
  7328. }
  7329. },
  7330. async ex =>
  7331. {
  7332. using (await gate.LockAsync().ConfigureAwait(false))
  7333. {
  7334. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7335. }
  7336. },
  7337. async () =>
  7338. {
  7339. using (await gate.LockAsync().ConfigureAwait(false))
  7340. {
  7341. isDone9 = true;
  7342. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7343. {
  7344. await observer.OnCompletedAsync().ConfigureAwait(false);
  7345. }
  7346. }
  7347. }
  7348. ),
  7349. Create<T10>(
  7350. async x =>
  7351. {
  7352. using (await gate.LockAsync().ConfigureAwait(false))
  7353. {
  7354. if (!hasValue10)
  7355. {
  7356. hasValue10 = true;
  7357. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7358. }
  7359. latestValue10 = x;
  7360. if (allHasValue)
  7361. {
  7362. TResult res;
  7363. try
  7364. {
  7365. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7366. }
  7367. catch (Exception ex)
  7368. {
  7369. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7370. return;
  7371. }
  7372. await observer.OnNextAsync(res).ConfigureAwait(false);
  7373. }
  7374. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7375. {
  7376. await observer.OnCompletedAsync().ConfigureAwait(false);
  7377. }
  7378. }
  7379. },
  7380. async ex =>
  7381. {
  7382. using (await gate.LockAsync().ConfigureAwait(false))
  7383. {
  7384. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7385. }
  7386. },
  7387. async () =>
  7388. {
  7389. using (await gate.LockAsync().ConfigureAwait(false))
  7390. {
  7391. isDone10 = true;
  7392. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7393. {
  7394. await observer.OnCompletedAsync().ConfigureAwait(false);
  7395. }
  7396. }
  7397. }
  7398. ),
  7399. Create<T11>(
  7400. async x =>
  7401. {
  7402. using (await gate.LockAsync().ConfigureAwait(false))
  7403. {
  7404. if (!hasValue11)
  7405. {
  7406. hasValue11 = true;
  7407. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7408. }
  7409. latestValue11 = x;
  7410. if (allHasValue)
  7411. {
  7412. TResult res;
  7413. try
  7414. {
  7415. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7416. }
  7417. catch (Exception ex)
  7418. {
  7419. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7420. return;
  7421. }
  7422. await observer.OnNextAsync(res).ConfigureAwait(false);
  7423. }
  7424. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone12 && isDone13 && isDone14 && isDone15)
  7425. {
  7426. await observer.OnCompletedAsync().ConfigureAwait(false);
  7427. }
  7428. }
  7429. },
  7430. async ex =>
  7431. {
  7432. using (await gate.LockAsync().ConfigureAwait(false))
  7433. {
  7434. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7435. }
  7436. },
  7437. async () =>
  7438. {
  7439. using (await gate.LockAsync().ConfigureAwait(false))
  7440. {
  7441. isDone11 = true;
  7442. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7443. {
  7444. await observer.OnCompletedAsync().ConfigureAwait(false);
  7445. }
  7446. }
  7447. }
  7448. ),
  7449. Create<T12>(
  7450. async x =>
  7451. {
  7452. using (await gate.LockAsync().ConfigureAwait(false))
  7453. {
  7454. if (!hasValue12)
  7455. {
  7456. hasValue12 = true;
  7457. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7458. }
  7459. latestValue12 = x;
  7460. if (allHasValue)
  7461. {
  7462. TResult res;
  7463. try
  7464. {
  7465. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7466. }
  7467. catch (Exception ex)
  7468. {
  7469. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7470. return;
  7471. }
  7472. await observer.OnNextAsync(res).ConfigureAwait(false);
  7473. }
  7474. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone13 && isDone14 && isDone15)
  7475. {
  7476. await observer.OnCompletedAsync().ConfigureAwait(false);
  7477. }
  7478. }
  7479. },
  7480. async ex =>
  7481. {
  7482. using (await gate.LockAsync().ConfigureAwait(false))
  7483. {
  7484. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7485. }
  7486. },
  7487. async () =>
  7488. {
  7489. using (await gate.LockAsync().ConfigureAwait(false))
  7490. {
  7491. isDone12 = true;
  7492. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7493. {
  7494. await observer.OnCompletedAsync().ConfigureAwait(false);
  7495. }
  7496. }
  7497. }
  7498. ),
  7499. Create<T13>(
  7500. async x =>
  7501. {
  7502. using (await gate.LockAsync().ConfigureAwait(false))
  7503. {
  7504. if (!hasValue13)
  7505. {
  7506. hasValue13 = true;
  7507. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7508. }
  7509. latestValue13 = x;
  7510. if (allHasValue)
  7511. {
  7512. TResult res;
  7513. try
  7514. {
  7515. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7516. }
  7517. catch (Exception ex)
  7518. {
  7519. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7520. return;
  7521. }
  7522. await observer.OnNextAsync(res).ConfigureAwait(false);
  7523. }
  7524. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone14 && isDone15)
  7525. {
  7526. await observer.OnCompletedAsync().ConfigureAwait(false);
  7527. }
  7528. }
  7529. },
  7530. async ex =>
  7531. {
  7532. using (await gate.LockAsync().ConfigureAwait(false))
  7533. {
  7534. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7535. }
  7536. },
  7537. async () =>
  7538. {
  7539. using (await gate.LockAsync().ConfigureAwait(false))
  7540. {
  7541. isDone13 = true;
  7542. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7543. {
  7544. await observer.OnCompletedAsync().ConfigureAwait(false);
  7545. }
  7546. }
  7547. }
  7548. ),
  7549. Create<T14>(
  7550. async x =>
  7551. {
  7552. using (await gate.LockAsync().ConfigureAwait(false))
  7553. {
  7554. if (!hasValue14)
  7555. {
  7556. hasValue14 = true;
  7557. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7558. }
  7559. latestValue14 = x;
  7560. if (allHasValue)
  7561. {
  7562. TResult res;
  7563. try
  7564. {
  7565. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7566. }
  7567. catch (Exception ex)
  7568. {
  7569. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7570. return;
  7571. }
  7572. await observer.OnNextAsync(res).ConfigureAwait(false);
  7573. }
  7574. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone15)
  7575. {
  7576. await observer.OnCompletedAsync().ConfigureAwait(false);
  7577. }
  7578. }
  7579. },
  7580. async ex =>
  7581. {
  7582. using (await gate.LockAsync().ConfigureAwait(false))
  7583. {
  7584. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7585. }
  7586. },
  7587. async () =>
  7588. {
  7589. using (await gate.LockAsync().ConfigureAwait(false))
  7590. {
  7591. isDone14 = true;
  7592. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7593. {
  7594. await observer.OnCompletedAsync().ConfigureAwait(false);
  7595. }
  7596. }
  7597. }
  7598. ),
  7599. Create<T15>(
  7600. async x =>
  7601. {
  7602. using (await gate.LockAsync().ConfigureAwait(false))
  7603. {
  7604. if (!hasValue15)
  7605. {
  7606. hasValue15 = true;
  7607. allHasValue = hasValue1 && hasValue2 && hasValue3 && hasValue4 && hasValue5 && hasValue6 && hasValue7 && hasValue8 && hasValue9 && hasValue10 && hasValue11 && hasValue12 && hasValue13 && hasValue14 && hasValue15;
  7608. }
  7609. latestValue15 = x;
  7610. if (allHasValue)
  7611. {
  7612. TResult res;
  7613. try
  7614. {
  7615. res = await selector(latestValue1, latestValue2, latestValue3, latestValue4, latestValue5, latestValue6, latestValue7, latestValue8, latestValue9, latestValue10, latestValue11, latestValue12, latestValue13, latestValue14, latestValue15).ConfigureAwait(false);
  7616. }
  7617. catch (Exception ex)
  7618. {
  7619. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7620. return;
  7621. }
  7622. await observer.OnNextAsync(res).ConfigureAwait(false);
  7623. }
  7624. else if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14)
  7625. {
  7626. await observer.OnCompletedAsync().ConfigureAwait(false);
  7627. }
  7628. }
  7629. },
  7630. async ex =>
  7631. {
  7632. using (await gate.LockAsync().ConfigureAwait(false))
  7633. {
  7634. await observer.OnErrorAsync(ex).ConfigureAwait(false);
  7635. }
  7636. },
  7637. async () =>
  7638. {
  7639. using (await gate.LockAsync().ConfigureAwait(false))
  7640. {
  7641. isDone15 = true;
  7642. if (isDone1 && isDone2 && isDone3 && isDone4 && isDone5 && isDone6 && isDone7 && isDone8 && isDone9 && isDone10 && isDone11 && isDone12 && isDone13 && isDone14 && isDone15)
  7643. {
  7644. await observer.OnCompletedAsync().ConfigureAwait(false);
  7645. }
  7646. }
  7647. }
  7648. )
  7649. );
  7650. }
  7651. }
  7652. }