ToAsync.Generated.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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.Concurrency;
  5. using System.Reactive.Subjects;
  6. namespace System.Reactive.Linq
  7. {
  8. // REVIEW: Consider if these are worth retaining in the async space.
  9. partial class AsyncObservable
  10. {
  11. public static Func<IAsyncObservable<TResult>> ToAsync<TResult>(Func<TResult> function)
  12. {
  13. if (function == null)
  14. throw new ArgumentNullException(nameof(function));
  15. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  16. }
  17. public static Func<IAsyncObservable<TResult>> ToAsync<TResult>(Func<TResult> function, IAsyncScheduler scheduler)
  18. {
  19. if (function == null)
  20. throw new ArgumentNullException(nameof(function));
  21. if (scheduler == null)
  22. throw new ArgumentNullException(nameof(scheduler));
  23. return () =>
  24. {
  25. var subject = new SequentialAsyncAsyncSubject<TResult>();
  26. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  27. scheduler.ScheduleAsync(async ct =>
  28. {
  29. TResult res;
  30. try
  31. {
  32. res = function();
  33. }
  34. catch (Exception ex)
  35. {
  36. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  37. return;
  38. }
  39. await subject.OnNextAsync(res).RendezVous(scheduler);
  40. await subject.OnCompletedAsync().RendezVous(scheduler);
  41. });
  42. return subject.AsAsyncObservable();
  43. };
  44. }
  45. public static Func<T1, IAsyncObservable<TResult>> ToAsync<T1, TResult>(Func<T1, TResult> function)
  46. {
  47. if (function == null)
  48. throw new ArgumentNullException(nameof(function));
  49. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  50. }
  51. public static Func<T1, IAsyncObservable<TResult>> ToAsync<T1, TResult>(Func<T1, TResult> function, IAsyncScheduler scheduler)
  52. {
  53. if (function == null)
  54. throw new ArgumentNullException(nameof(function));
  55. if (scheduler == null)
  56. throw new ArgumentNullException(nameof(scheduler));
  57. return (arg1) =>
  58. {
  59. var subject = new SequentialAsyncAsyncSubject<TResult>();
  60. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  61. scheduler.ScheduleAsync(async ct =>
  62. {
  63. TResult res;
  64. try
  65. {
  66. res = function(arg1);
  67. }
  68. catch (Exception ex)
  69. {
  70. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  71. return;
  72. }
  73. await subject.OnNextAsync(res).RendezVous(scheduler);
  74. await subject.OnCompletedAsync().RendezVous(scheduler);
  75. });
  76. return subject.AsAsyncObservable();
  77. };
  78. }
  79. public static Func<T1, T2, IAsyncObservable<TResult>> ToAsync<T1, T2, TResult>(Func<T1, T2, TResult> function)
  80. {
  81. if (function == null)
  82. throw new ArgumentNullException(nameof(function));
  83. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  84. }
  85. public static Func<T1, T2, IAsyncObservable<TResult>> ToAsync<T1, T2, TResult>(Func<T1, T2, TResult> function, IAsyncScheduler scheduler)
  86. {
  87. if (function == null)
  88. throw new ArgumentNullException(nameof(function));
  89. if (scheduler == null)
  90. throw new ArgumentNullException(nameof(scheduler));
  91. return (arg1, arg2) =>
  92. {
  93. var subject = new SequentialAsyncAsyncSubject<TResult>();
  94. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  95. scheduler.ScheduleAsync(async ct =>
  96. {
  97. TResult res;
  98. try
  99. {
  100. res = function(arg1, arg2);
  101. }
  102. catch (Exception ex)
  103. {
  104. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  105. return;
  106. }
  107. await subject.OnNextAsync(res).RendezVous(scheduler);
  108. await subject.OnCompletedAsync().RendezVous(scheduler);
  109. });
  110. return subject.AsAsyncObservable();
  111. };
  112. }
  113. public static Func<T1, T2, T3, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult> function)
  114. {
  115. if (function == null)
  116. throw new ArgumentNullException(nameof(function));
  117. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  118. }
  119. public static Func<T1, T2, T3, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult> function, IAsyncScheduler scheduler)
  120. {
  121. if (function == null)
  122. throw new ArgumentNullException(nameof(function));
  123. if (scheduler == null)
  124. throw new ArgumentNullException(nameof(scheduler));
  125. return (arg1, arg2, arg3) =>
  126. {
  127. var subject = new SequentialAsyncAsyncSubject<TResult>();
  128. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  129. scheduler.ScheduleAsync(async ct =>
  130. {
  131. TResult res;
  132. try
  133. {
  134. res = function(arg1, arg2, arg3);
  135. }
  136. catch (Exception ex)
  137. {
  138. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  139. return;
  140. }
  141. await subject.OnNextAsync(res).RendezVous(scheduler);
  142. await subject.OnCompletedAsync().RendezVous(scheduler);
  143. });
  144. return subject.AsAsyncObservable();
  145. };
  146. }
  147. public static Func<T1, T2, T3, T4, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult> function)
  148. {
  149. if (function == null)
  150. throw new ArgumentNullException(nameof(function));
  151. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  152. }
  153. public static Func<T1, T2, T3, T4, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult> function, IAsyncScheduler scheduler)
  154. {
  155. if (function == null)
  156. throw new ArgumentNullException(nameof(function));
  157. if (scheduler == null)
  158. throw new ArgumentNullException(nameof(scheduler));
  159. return (arg1, arg2, arg3, arg4) =>
  160. {
  161. var subject = new SequentialAsyncAsyncSubject<TResult>();
  162. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  163. scheduler.ScheduleAsync(async ct =>
  164. {
  165. TResult res;
  166. try
  167. {
  168. res = function(arg1, arg2, arg3, arg4);
  169. }
  170. catch (Exception ex)
  171. {
  172. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  173. return;
  174. }
  175. await subject.OnNextAsync(res).RendezVous(scheduler);
  176. await subject.OnCompletedAsync().RendezVous(scheduler);
  177. });
  178. return subject.AsAsyncObservable();
  179. };
  180. }
  181. public static Func<T1, T2, T3, T4, T5, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult> function)
  182. {
  183. if (function == null)
  184. throw new ArgumentNullException(nameof(function));
  185. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  186. }
  187. public static Func<T1, T2, T3, T4, T5, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult> function, IAsyncScheduler scheduler)
  188. {
  189. if (function == null)
  190. throw new ArgumentNullException(nameof(function));
  191. if (scheduler == null)
  192. throw new ArgumentNullException(nameof(scheduler));
  193. return (arg1, arg2, arg3, arg4, arg5) =>
  194. {
  195. var subject = new SequentialAsyncAsyncSubject<TResult>();
  196. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  197. scheduler.ScheduleAsync(async ct =>
  198. {
  199. TResult res;
  200. try
  201. {
  202. res = function(arg1, arg2, arg3, arg4, arg5);
  203. }
  204. catch (Exception ex)
  205. {
  206. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  207. return;
  208. }
  209. await subject.OnNextAsync(res).RendezVous(scheduler);
  210. await subject.OnCompletedAsync().RendezVous(scheduler);
  211. });
  212. return subject.AsAsyncObservable();
  213. };
  214. }
  215. public static Func<T1, T2, T3, T4, T5, T6, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, TResult>(Func<T1, T2, T3, T4, T5, T6, TResult> function)
  216. {
  217. if (function == null)
  218. throw new ArgumentNullException(nameof(function));
  219. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  220. }
  221. public static Func<T1, T2, T3, T4, T5, T6, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, TResult>(Func<T1, T2, T3, T4, T5, T6, TResult> function, IAsyncScheduler scheduler)
  222. {
  223. if (function == null)
  224. throw new ArgumentNullException(nameof(function));
  225. if (scheduler == null)
  226. throw new ArgumentNullException(nameof(scheduler));
  227. return (arg1, arg2, arg3, arg4, arg5, arg6) =>
  228. {
  229. var subject = new SequentialAsyncAsyncSubject<TResult>();
  230. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  231. scheduler.ScheduleAsync(async ct =>
  232. {
  233. TResult res;
  234. try
  235. {
  236. res = function(arg1, arg2, arg3, arg4, arg5, arg6);
  237. }
  238. catch (Exception ex)
  239. {
  240. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  241. return;
  242. }
  243. await subject.OnNextAsync(res).RendezVous(scheduler);
  244. await subject.OnCompletedAsync().RendezVous(scheduler);
  245. });
  246. return subject.AsAsyncObservable();
  247. };
  248. }
  249. public static Func<T1, T2, T3, T4, T5, T6, T7, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, TResult> function)
  250. {
  251. if (function == null)
  252. throw new ArgumentNullException(nameof(function));
  253. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  254. }
  255. public static Func<T1, T2, T3, T4, T5, T6, T7, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, TResult> function, IAsyncScheduler scheduler)
  256. {
  257. if (function == null)
  258. throw new ArgumentNullException(nameof(function));
  259. if (scheduler == null)
  260. throw new ArgumentNullException(nameof(scheduler));
  261. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
  262. {
  263. var subject = new SequentialAsyncAsyncSubject<TResult>();
  264. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  265. scheduler.ScheduleAsync(async ct =>
  266. {
  267. TResult res;
  268. try
  269. {
  270. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
  271. }
  272. catch (Exception ex)
  273. {
  274. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  275. return;
  276. }
  277. await subject.OnNextAsync(res).RendezVous(scheduler);
  278. await subject.OnCompletedAsync().RendezVous(scheduler);
  279. });
  280. return subject.AsAsyncObservable();
  281. };
  282. }
  283. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> function)
  284. {
  285. if (function == null)
  286. throw new ArgumentNullException(nameof(function));
  287. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  288. }
  289. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> function, IAsyncScheduler scheduler)
  290. {
  291. if (function == null)
  292. throw new ArgumentNullException(nameof(function));
  293. if (scheduler == null)
  294. throw new ArgumentNullException(nameof(scheduler));
  295. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) =>
  296. {
  297. var subject = new SequentialAsyncAsyncSubject<TResult>();
  298. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  299. scheduler.ScheduleAsync(async ct =>
  300. {
  301. TResult res;
  302. try
  303. {
  304. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
  305. }
  306. catch (Exception ex)
  307. {
  308. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  309. return;
  310. }
  311. await subject.OnNextAsync(res).RendezVous(scheduler);
  312. await subject.OnCompletedAsync().RendezVous(scheduler);
  313. });
  314. return subject.AsAsyncObservable();
  315. };
  316. }
  317. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> function)
  318. {
  319. if (function == null)
  320. throw new ArgumentNullException(nameof(function));
  321. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  322. }
  323. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> function, IAsyncScheduler scheduler)
  324. {
  325. if (function == null)
  326. throw new ArgumentNullException(nameof(function));
  327. if (scheduler == null)
  328. throw new ArgumentNullException(nameof(scheduler));
  329. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) =>
  330. {
  331. var subject = new SequentialAsyncAsyncSubject<TResult>();
  332. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  333. scheduler.ScheduleAsync(async ct =>
  334. {
  335. TResult res;
  336. try
  337. {
  338. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
  339. }
  340. catch (Exception ex)
  341. {
  342. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  343. return;
  344. }
  345. await subject.OnNextAsync(res).RendezVous(scheduler);
  346. await subject.OnCompletedAsync().RendezVous(scheduler);
  347. });
  348. return subject.AsAsyncObservable();
  349. };
  350. }
  351. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> function)
  352. {
  353. if (function == null)
  354. throw new ArgumentNullException(nameof(function));
  355. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  356. }
  357. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> function, IAsyncScheduler scheduler)
  358. {
  359. if (function == null)
  360. throw new ArgumentNullException(nameof(function));
  361. if (scheduler == null)
  362. throw new ArgumentNullException(nameof(scheduler));
  363. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) =>
  364. {
  365. var subject = new SequentialAsyncAsyncSubject<TResult>();
  366. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  367. scheduler.ScheduleAsync(async ct =>
  368. {
  369. TResult res;
  370. try
  371. {
  372. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
  373. }
  374. catch (Exception ex)
  375. {
  376. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  377. return;
  378. }
  379. await subject.OnNextAsync(res).RendezVous(scheduler);
  380. await subject.OnCompletedAsync().RendezVous(scheduler);
  381. });
  382. return subject.AsAsyncObservable();
  383. };
  384. }
  385. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> function)
  386. {
  387. if (function == null)
  388. throw new ArgumentNullException(nameof(function));
  389. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  390. }
  391. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> function, IAsyncScheduler scheduler)
  392. {
  393. if (function == null)
  394. throw new ArgumentNullException(nameof(function));
  395. if (scheduler == null)
  396. throw new ArgumentNullException(nameof(scheduler));
  397. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) =>
  398. {
  399. var subject = new SequentialAsyncAsyncSubject<TResult>();
  400. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  401. scheduler.ScheduleAsync(async ct =>
  402. {
  403. TResult res;
  404. try
  405. {
  406. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
  407. }
  408. catch (Exception ex)
  409. {
  410. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  411. return;
  412. }
  413. await subject.OnNextAsync(res).RendezVous(scheduler);
  414. await subject.OnCompletedAsync().RendezVous(scheduler);
  415. });
  416. return subject.AsAsyncObservable();
  417. };
  418. }
  419. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> function)
  420. {
  421. if (function == null)
  422. throw new ArgumentNullException(nameof(function));
  423. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  424. }
  425. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> function, IAsyncScheduler scheduler)
  426. {
  427. if (function == null)
  428. throw new ArgumentNullException(nameof(function));
  429. if (scheduler == null)
  430. throw new ArgumentNullException(nameof(scheduler));
  431. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) =>
  432. {
  433. var subject = new SequentialAsyncAsyncSubject<TResult>();
  434. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  435. scheduler.ScheduleAsync(async ct =>
  436. {
  437. TResult res;
  438. try
  439. {
  440. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
  441. }
  442. catch (Exception ex)
  443. {
  444. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  445. return;
  446. }
  447. await subject.OnNextAsync(res).RendezVous(scheduler);
  448. await subject.OnCompletedAsync().RendezVous(scheduler);
  449. });
  450. return subject.AsAsyncObservable();
  451. };
  452. }
  453. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> function)
  454. {
  455. if (function == null)
  456. throw new ArgumentNullException(nameof(function));
  457. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  458. }
  459. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> function, IAsyncScheduler scheduler)
  460. {
  461. if (function == null)
  462. throw new ArgumentNullException(nameof(function));
  463. if (scheduler == null)
  464. throw new ArgumentNullException(nameof(scheduler));
  465. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) =>
  466. {
  467. var subject = new SequentialAsyncAsyncSubject<TResult>();
  468. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  469. scheduler.ScheduleAsync(async ct =>
  470. {
  471. TResult res;
  472. try
  473. {
  474. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13);
  475. }
  476. catch (Exception ex)
  477. {
  478. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  479. return;
  480. }
  481. await subject.OnNextAsync(res).RendezVous(scheduler);
  482. await subject.OnCompletedAsync().RendezVous(scheduler);
  483. });
  484. return subject.AsAsyncObservable();
  485. };
  486. }
  487. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> function)
  488. {
  489. if (function == null)
  490. throw new ArgumentNullException(nameof(function));
  491. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  492. }
  493. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> function, IAsyncScheduler scheduler)
  494. {
  495. if (function == null)
  496. throw new ArgumentNullException(nameof(function));
  497. if (scheduler == null)
  498. throw new ArgumentNullException(nameof(scheduler));
  499. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) =>
  500. {
  501. var subject = new SequentialAsyncAsyncSubject<TResult>();
  502. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  503. scheduler.ScheduleAsync(async ct =>
  504. {
  505. TResult res;
  506. try
  507. {
  508. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
  509. }
  510. catch (Exception ex)
  511. {
  512. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  513. return;
  514. }
  515. await subject.OnNextAsync(res).RendezVous(scheduler);
  516. await subject.OnCompletedAsync().RendezVous(scheduler);
  517. });
  518. return subject.AsAsyncObservable();
  519. };
  520. }
  521. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> function)
  522. {
  523. if (function == null)
  524. throw new ArgumentNullException(nameof(function));
  525. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  526. }
  527. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> function, IAsyncScheduler scheduler)
  528. {
  529. if (function == null)
  530. throw new ArgumentNullException(nameof(function));
  531. if (scheduler == null)
  532. throw new ArgumentNullException(nameof(scheduler));
  533. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) =>
  534. {
  535. var subject = new SequentialAsyncAsyncSubject<TResult>();
  536. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  537. scheduler.ScheduleAsync(async ct =>
  538. {
  539. TResult res;
  540. try
  541. {
  542. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15);
  543. }
  544. catch (Exception ex)
  545. {
  546. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  547. return;
  548. }
  549. await subject.OnNextAsync(res).RendezVous(scheduler);
  550. await subject.OnCompletedAsync().RendezVous(scheduler);
  551. });
  552. return subject.AsAsyncObservable();
  553. };
  554. }
  555. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> function)
  556. {
  557. if (function == null)
  558. throw new ArgumentNullException(nameof(function));
  559. return ToAsync(function, TaskPoolAsyncScheduler.Default);
  560. }
  561. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, IAsyncObservable<TResult>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> function, IAsyncScheduler scheduler)
  562. {
  563. if (function == null)
  564. throw new ArgumentNullException(nameof(function));
  565. if (scheduler == null)
  566. throw new ArgumentNullException(nameof(scheduler));
  567. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16) =>
  568. {
  569. var subject = new SequentialAsyncAsyncSubject<TResult>();
  570. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  571. scheduler.ScheduleAsync(async ct =>
  572. {
  573. TResult res;
  574. try
  575. {
  576. res = function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);
  577. }
  578. catch (Exception ex)
  579. {
  580. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  581. return;
  582. }
  583. await subject.OnNextAsync(res).RendezVous(scheduler);
  584. await subject.OnCompletedAsync().RendezVous(scheduler);
  585. });
  586. return subject.AsAsyncObservable();
  587. };
  588. }
  589. public static Func<IAsyncObservable<Unit>> ToAsync(Action action)
  590. {
  591. if (action == null)
  592. throw new ArgumentNullException(nameof(action));
  593. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  594. }
  595. public static Func<IAsyncObservable<Unit>> ToAsync(Action action, IAsyncScheduler scheduler)
  596. {
  597. if (action == null)
  598. throw new ArgumentNullException(nameof(action));
  599. if (scheduler == null)
  600. throw new ArgumentNullException(nameof(scheduler));
  601. return () =>
  602. {
  603. var subject = new SequentialAsyncAsyncSubject<Unit>();
  604. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  605. scheduler.ScheduleAsync(async ct =>
  606. {
  607. try
  608. {
  609. action();
  610. }
  611. catch (Exception ex)
  612. {
  613. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  614. return;
  615. }
  616. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  617. await subject.OnCompletedAsync().RendezVous(scheduler);
  618. });
  619. return subject.AsAsyncObservable();
  620. };
  621. }
  622. public static Func<T1, IAsyncObservable<Unit>> ToAsync<T1>(Action<T1> action)
  623. {
  624. if (action == null)
  625. throw new ArgumentNullException(nameof(action));
  626. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  627. }
  628. public static Func<T1, IAsyncObservable<Unit>> ToAsync<T1>(Action<T1> action, IAsyncScheduler scheduler)
  629. {
  630. if (action == null)
  631. throw new ArgumentNullException(nameof(action));
  632. if (scheduler == null)
  633. throw new ArgumentNullException(nameof(scheduler));
  634. return (arg1) =>
  635. {
  636. var subject = new SequentialAsyncAsyncSubject<Unit>();
  637. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  638. scheduler.ScheduleAsync(async ct =>
  639. {
  640. try
  641. {
  642. action(arg1);
  643. }
  644. catch (Exception ex)
  645. {
  646. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  647. return;
  648. }
  649. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  650. await subject.OnCompletedAsync().RendezVous(scheduler);
  651. });
  652. return subject.AsAsyncObservable();
  653. };
  654. }
  655. public static Func<T1, T2, IAsyncObservable<Unit>> ToAsync<T1, T2>(Action<T1, T2> action)
  656. {
  657. if (action == null)
  658. throw new ArgumentNullException(nameof(action));
  659. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  660. }
  661. public static Func<T1, T2, IAsyncObservable<Unit>> ToAsync<T1, T2>(Action<T1, T2> action, IAsyncScheduler scheduler)
  662. {
  663. if (action == null)
  664. throw new ArgumentNullException(nameof(action));
  665. if (scheduler == null)
  666. throw new ArgumentNullException(nameof(scheduler));
  667. return (arg1, arg2) =>
  668. {
  669. var subject = new SequentialAsyncAsyncSubject<Unit>();
  670. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  671. scheduler.ScheduleAsync(async ct =>
  672. {
  673. try
  674. {
  675. action(arg1, arg2);
  676. }
  677. catch (Exception ex)
  678. {
  679. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  680. return;
  681. }
  682. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  683. await subject.OnCompletedAsync().RendezVous(scheduler);
  684. });
  685. return subject.AsAsyncObservable();
  686. };
  687. }
  688. public static Func<T1, T2, T3, IAsyncObservable<Unit>> ToAsync<T1, T2, T3>(Action<T1, T2, T3> action)
  689. {
  690. if (action == null)
  691. throw new ArgumentNullException(nameof(action));
  692. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  693. }
  694. public static Func<T1, T2, T3, IAsyncObservable<Unit>> ToAsync<T1, T2, T3>(Action<T1, T2, T3> action, IAsyncScheduler scheduler)
  695. {
  696. if (action == null)
  697. throw new ArgumentNullException(nameof(action));
  698. if (scheduler == null)
  699. throw new ArgumentNullException(nameof(scheduler));
  700. return (arg1, arg2, arg3) =>
  701. {
  702. var subject = new SequentialAsyncAsyncSubject<Unit>();
  703. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  704. scheduler.ScheduleAsync(async ct =>
  705. {
  706. try
  707. {
  708. action(arg1, arg2, arg3);
  709. }
  710. catch (Exception ex)
  711. {
  712. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  713. return;
  714. }
  715. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  716. await subject.OnCompletedAsync().RendezVous(scheduler);
  717. });
  718. return subject.AsAsyncObservable();
  719. };
  720. }
  721. public static Func<T1, T2, T3, T4, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action)
  722. {
  723. if (action == null)
  724. throw new ArgumentNullException(nameof(action));
  725. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  726. }
  727. public static Func<T1, T2, T3, T4, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, IAsyncScheduler scheduler)
  728. {
  729. if (action == null)
  730. throw new ArgumentNullException(nameof(action));
  731. if (scheduler == null)
  732. throw new ArgumentNullException(nameof(scheduler));
  733. return (arg1, arg2, arg3, arg4) =>
  734. {
  735. var subject = new SequentialAsyncAsyncSubject<Unit>();
  736. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  737. scheduler.ScheduleAsync(async ct =>
  738. {
  739. try
  740. {
  741. action(arg1, arg2, arg3, arg4);
  742. }
  743. catch (Exception ex)
  744. {
  745. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  746. return;
  747. }
  748. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  749. await subject.OnCompletedAsync().RendezVous(scheduler);
  750. });
  751. return subject.AsAsyncObservable();
  752. };
  753. }
  754. public static Func<T1, T2, T3, T4, T5, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> action)
  755. {
  756. if (action == null)
  757. throw new ArgumentNullException(nameof(action));
  758. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  759. }
  760. public static Func<T1, T2, T3, T4, T5, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> action, IAsyncScheduler scheduler)
  761. {
  762. if (action == null)
  763. throw new ArgumentNullException(nameof(action));
  764. if (scheduler == null)
  765. throw new ArgumentNullException(nameof(scheduler));
  766. return (arg1, arg2, arg3, arg4, arg5) =>
  767. {
  768. var subject = new SequentialAsyncAsyncSubject<Unit>();
  769. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  770. scheduler.ScheduleAsync(async ct =>
  771. {
  772. try
  773. {
  774. action(arg1, arg2, arg3, arg4, arg5);
  775. }
  776. catch (Exception ex)
  777. {
  778. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  779. return;
  780. }
  781. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  782. await subject.OnCompletedAsync().RendezVous(scheduler);
  783. });
  784. return subject.AsAsyncObservable();
  785. };
  786. }
  787. public static Func<T1, T2, T3, T4, T5, T6, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6>(Action<T1, T2, T3, T4, T5, T6> action)
  788. {
  789. if (action == null)
  790. throw new ArgumentNullException(nameof(action));
  791. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  792. }
  793. public static Func<T1, T2, T3, T4, T5, T6, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6>(Action<T1, T2, T3, T4, T5, T6> action, IAsyncScheduler scheduler)
  794. {
  795. if (action == null)
  796. throw new ArgumentNullException(nameof(action));
  797. if (scheduler == null)
  798. throw new ArgumentNullException(nameof(scheduler));
  799. return (arg1, arg2, arg3, arg4, arg5, arg6) =>
  800. {
  801. var subject = new SequentialAsyncAsyncSubject<Unit>();
  802. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  803. scheduler.ScheduleAsync(async ct =>
  804. {
  805. try
  806. {
  807. action(arg1, arg2, arg3, arg4, arg5, arg6);
  808. }
  809. catch (Exception ex)
  810. {
  811. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  812. return;
  813. }
  814. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  815. await subject.OnCompletedAsync().RendezVous(scheduler);
  816. });
  817. return subject.AsAsyncObservable();
  818. };
  819. }
  820. public static Func<T1, T2, T3, T4, T5, T6, T7, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7>(Action<T1, T2, T3, T4, T5, T6, T7> action)
  821. {
  822. if (action == null)
  823. throw new ArgumentNullException(nameof(action));
  824. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  825. }
  826. public static Func<T1, T2, T3, T4, T5, T6, T7, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7>(Action<T1, T2, T3, T4, T5, T6, T7> action, IAsyncScheduler scheduler)
  827. {
  828. if (action == null)
  829. throw new ArgumentNullException(nameof(action));
  830. if (scheduler == null)
  831. throw new ArgumentNullException(nameof(scheduler));
  832. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
  833. {
  834. var subject = new SequentialAsyncAsyncSubject<Unit>();
  835. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  836. scheduler.ScheduleAsync(async ct =>
  837. {
  838. try
  839. {
  840. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
  841. }
  842. catch (Exception ex)
  843. {
  844. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  845. return;
  846. }
  847. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  848. await subject.OnCompletedAsync().RendezVous(scheduler);
  849. });
  850. return subject.AsAsyncObservable();
  851. };
  852. }
  853. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8>(Action<T1, T2, T3, T4, T5, T6, T7, T8> action)
  854. {
  855. if (action == null)
  856. throw new ArgumentNullException(nameof(action));
  857. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  858. }
  859. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8>(Action<T1, T2, T3, T4, T5, T6, T7, T8> action, IAsyncScheduler scheduler)
  860. {
  861. if (action == null)
  862. throw new ArgumentNullException(nameof(action));
  863. if (scheduler == null)
  864. throw new ArgumentNullException(nameof(scheduler));
  865. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) =>
  866. {
  867. var subject = new SequentialAsyncAsyncSubject<Unit>();
  868. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  869. scheduler.ScheduleAsync(async ct =>
  870. {
  871. try
  872. {
  873. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
  874. }
  875. catch (Exception ex)
  876. {
  877. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  878. return;
  879. }
  880. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  881. await subject.OnCompletedAsync().RendezVous(scheduler);
  882. });
  883. return subject.AsAsyncObservable();
  884. };
  885. }
  886. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action)
  887. {
  888. if (action == null)
  889. throw new ArgumentNullException(nameof(action));
  890. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  891. }
  892. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action, IAsyncScheduler scheduler)
  893. {
  894. if (action == null)
  895. throw new ArgumentNullException(nameof(action));
  896. if (scheduler == null)
  897. throw new ArgumentNullException(nameof(scheduler));
  898. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) =>
  899. {
  900. var subject = new SequentialAsyncAsyncSubject<Unit>();
  901. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  902. scheduler.ScheduleAsync(async ct =>
  903. {
  904. try
  905. {
  906. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
  907. }
  908. catch (Exception ex)
  909. {
  910. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  911. return;
  912. }
  913. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  914. await subject.OnCompletedAsync().RendezVous(scheduler);
  915. });
  916. return subject.AsAsyncObservable();
  917. };
  918. }
  919. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action)
  920. {
  921. if (action == null)
  922. throw new ArgumentNullException(nameof(action));
  923. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  924. }
  925. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action, IAsyncScheduler scheduler)
  926. {
  927. if (action == null)
  928. throw new ArgumentNullException(nameof(action));
  929. if (scheduler == null)
  930. throw new ArgumentNullException(nameof(scheduler));
  931. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) =>
  932. {
  933. var subject = new SequentialAsyncAsyncSubject<Unit>();
  934. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  935. scheduler.ScheduleAsync(async ct =>
  936. {
  937. try
  938. {
  939. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
  940. }
  941. catch (Exception ex)
  942. {
  943. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  944. return;
  945. }
  946. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  947. await subject.OnCompletedAsync().RendezVous(scheduler);
  948. });
  949. return subject.AsAsyncObservable();
  950. };
  951. }
  952. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> action)
  953. {
  954. if (action == null)
  955. throw new ArgumentNullException(nameof(action));
  956. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  957. }
  958. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> action, IAsyncScheduler scheduler)
  959. {
  960. if (action == null)
  961. throw new ArgumentNullException(nameof(action));
  962. if (scheduler == null)
  963. throw new ArgumentNullException(nameof(scheduler));
  964. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) =>
  965. {
  966. var subject = new SequentialAsyncAsyncSubject<Unit>();
  967. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  968. scheduler.ScheduleAsync(async ct =>
  969. {
  970. try
  971. {
  972. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
  973. }
  974. catch (Exception ex)
  975. {
  976. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  977. return;
  978. }
  979. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  980. await subject.OnCompletedAsync().RendezVous(scheduler);
  981. });
  982. return subject.AsAsyncObservable();
  983. };
  984. }
  985. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> action)
  986. {
  987. if (action == null)
  988. throw new ArgumentNullException(nameof(action));
  989. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  990. }
  991. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> action, IAsyncScheduler scheduler)
  992. {
  993. if (action == null)
  994. throw new ArgumentNullException(nameof(action));
  995. if (scheduler == null)
  996. throw new ArgumentNullException(nameof(scheduler));
  997. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) =>
  998. {
  999. var subject = new SequentialAsyncAsyncSubject<Unit>();
  1000. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  1001. scheduler.ScheduleAsync(async ct =>
  1002. {
  1003. try
  1004. {
  1005. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
  1006. }
  1007. catch (Exception ex)
  1008. {
  1009. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  1010. return;
  1011. }
  1012. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  1013. await subject.OnCompletedAsync().RendezVous(scheduler);
  1014. });
  1015. return subject.AsAsyncObservable();
  1016. };
  1017. }
  1018. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> action)
  1019. {
  1020. if (action == null)
  1021. throw new ArgumentNullException(nameof(action));
  1022. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  1023. }
  1024. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> action, IAsyncScheduler scheduler)
  1025. {
  1026. if (action == null)
  1027. throw new ArgumentNullException(nameof(action));
  1028. if (scheduler == null)
  1029. throw new ArgumentNullException(nameof(scheduler));
  1030. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) =>
  1031. {
  1032. var subject = new SequentialAsyncAsyncSubject<Unit>();
  1033. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  1034. scheduler.ScheduleAsync(async ct =>
  1035. {
  1036. try
  1037. {
  1038. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13);
  1039. }
  1040. catch (Exception ex)
  1041. {
  1042. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  1043. return;
  1044. }
  1045. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  1046. await subject.OnCompletedAsync().RendezVous(scheduler);
  1047. });
  1048. return subject.AsAsyncObservable();
  1049. };
  1050. }
  1051. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> action)
  1052. {
  1053. if (action == null)
  1054. throw new ArgumentNullException(nameof(action));
  1055. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  1056. }
  1057. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> action, IAsyncScheduler scheduler)
  1058. {
  1059. if (action == null)
  1060. throw new ArgumentNullException(nameof(action));
  1061. if (scheduler == null)
  1062. throw new ArgumentNullException(nameof(scheduler));
  1063. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) =>
  1064. {
  1065. var subject = new SequentialAsyncAsyncSubject<Unit>();
  1066. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  1067. scheduler.ScheduleAsync(async ct =>
  1068. {
  1069. try
  1070. {
  1071. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
  1072. }
  1073. catch (Exception ex)
  1074. {
  1075. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  1076. return;
  1077. }
  1078. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  1079. await subject.OnCompletedAsync().RendezVous(scheduler);
  1080. });
  1081. return subject.AsAsyncObservable();
  1082. };
  1083. }
  1084. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> action)
  1085. {
  1086. if (action == null)
  1087. throw new ArgumentNullException(nameof(action));
  1088. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  1089. }
  1090. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> action, IAsyncScheduler scheduler)
  1091. {
  1092. if (action == null)
  1093. throw new ArgumentNullException(nameof(action));
  1094. if (scheduler == null)
  1095. throw new ArgumentNullException(nameof(scheduler));
  1096. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) =>
  1097. {
  1098. var subject = new SequentialAsyncAsyncSubject<Unit>();
  1099. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  1100. scheduler.ScheduleAsync(async ct =>
  1101. {
  1102. try
  1103. {
  1104. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15);
  1105. }
  1106. catch (Exception ex)
  1107. {
  1108. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  1109. return;
  1110. }
  1111. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  1112. await subject.OnCompletedAsync().RendezVous(scheduler);
  1113. });
  1114. return subject.AsAsyncObservable();
  1115. };
  1116. }
  1117. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> action)
  1118. {
  1119. if (action == null)
  1120. throw new ArgumentNullException(nameof(action));
  1121. return ToAsync(action, TaskPoolAsyncScheduler.Default);
  1122. }
  1123. public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, IAsyncObservable<Unit>> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> action, IAsyncScheduler scheduler)
  1124. {
  1125. if (action == null)
  1126. throw new ArgumentNullException(nameof(action));
  1127. if (scheduler == null)
  1128. throw new ArgumentNullException(nameof(scheduler));
  1129. return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16) =>
  1130. {
  1131. var subject = new SequentialAsyncAsyncSubject<Unit>();
  1132. // NB: We don't do anything with the result of scheduling the action; it can't be cancelled.
  1133. scheduler.ScheduleAsync(async ct =>
  1134. {
  1135. try
  1136. {
  1137. action(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);
  1138. }
  1139. catch (Exception ex)
  1140. {
  1141. await subject.OnErrorAsync(ex).RendezVous(scheduler);
  1142. return;
  1143. }
  1144. await subject.OnNextAsync(Unit.Default).RendezVous(scheduler);
  1145. await subject.OnCompletedAsync().RendezVous(scheduler);
  1146. });
  1147. return subject.AsAsyncObservable();
  1148. };
  1149. }
  1150. }
  1151. }