Debian Codegraph @

asyncro/docs/index.html

raw
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset='utf-8' />
5 <title> | Documentation</title>
6 <meta name='viewport' content='width=device-width,initial-scale=1'>
7 <link href='assets/bass.css' type='text/css' rel='stylesheet' />
8 <link href='assets/style.css' type='text/css' rel='stylesheet' />
9 <link href='assets/github.css' type='text/css' rel='stylesheet' />
10 </head>
11 <body class='documentation'>
12 <div class='max-width-4 mx-auto'>
13 <div class='clearfix md-mxn2'>
14 <div class='fixed xs-hide fix-3 overflow-auto max-height-100'>
15 <div class='py1 px2'>
16 <h3 class='mb0 no-anchor'></h3>
17 <div class='mb1'><code></code></div>
18 <input
19 placeholder='Filter'
20 id='filter-input'
21 class='col12 block input'
22 type='text' />
23 <div id='toc'>
24 <ul class='list-reset h5 py1-ul'>
25
26
27 <li><a
28 href='#reduce'
29 class="">
30 reduce
31
32 </a>
33
34 </li>
35
36
37 <li><a
38 href='#map'
39 class="">
40 map
41
42 </a>
43
44 </li>
45
46
47 <li><a
48 href='#filter'
49 class="">
50 filter
51
52 </a>
53
54 </li>
55
56
57 <li><a
58 href='#find'
59 class="">
60 find
61
62 </a>
63
64 </li>
65
66
67 <li><a
68 href='#every'
69 class="">
70 every
71
72 </a>
73
74 </li>
75
76
77 <li><a
78 href='#some'
79 class="">
80 some
81
82 </a>
83
84 </li>
85
86
87 <li><a
88 href='#parallel'
89 class="">
90 parallel
91
92 </a>
93
94 </li>
95
96
97 <li><a
98 href='#series'
99 class="">
100 series
101
102 </a>
103
104 </li>
105
106 </ul>
107 </div>
108 <div class='mt1 h6 quiet'>
109 <a href='http://documentation.js.org/reading-documentation.html'>Need help reading this?</a>
110 </div>
111 </div>
112 </div>
113 <div class='fix-margin-3'>
114
115
116 <section class='p2 mb2 clearfix bg-white minishadow'>
117
118
119 <div class='clearfix'>
120 <h3 class='fl m0' id='reduce'>
121 reduce
122 </h3>
123
124 </div>
125
126
127 <p>Invoke an async reducer function on each item in the given Array,
128 where the reducer transforms an accumulator value based on each item iterated over.
129 <strong>Note:</strong> because <code>reduce()</code> is order-sensitive, iteration is sequential.</p>
130 <blockquote>
131 <p>This is an asynchronous version of <code>Array.prototype.reduce()</code></p>
132 </blockquote>
133
134
135 <div class='pre p1 fill-light mt0'>reduce(array: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>, reducer: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>, accumulator: [any]): any</div>
136
137
138
139
140
141
142
143
144
145
146 <div class='py1 quiet mt1 prose-big'>Parameters</div>
147 <div class='prose'>
148
149 <div class='space-bottom0'>
150 <div>
151 <span class='code bold'>array</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>)</code> The Array to reduce
152
153 </div>
154
155 </div>
156
157 <div class='space-bottom0'>
158 <div>
159 <span class='code bold'>reducer</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>)</code> Async function, gets passed
160 <code>(accumulator, value, index, array)</code>
161 and returns a new value for
162 <code>accumulator</code>
163
164 </div>
165
166 </div>
167
168 <div class='space-bottom0'>
169 <div>
170 <span class='code bold'>accumulator</span> <code class='quiet'>([any])</code> Optional initial accumulator value
171
172 </div>
173
174 </div>
175
176 </div>
177
178
179
180
181
182
183 <div class='py1 quiet mt1 prose-big'>Returns</div>
184 <code>any</code>:
185 final
186 <code>accumulator</code>
187 value
188
189
190
191
192
193
194
195
196 <div class='py1 quiet mt1 prose-big'>Example</div>
197
198
199 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> reduce(
200 [<span class="hljs-string">'/foo'</span>, <span class="hljs-string">'/bar'</span>, <span class="hljs-string">'/baz'</span>],
201 <span class="hljs-keyword">async</span> (accumulator, value) =&gt; {
202 accumulator[v] = <span class="hljs-keyword">await</span> fetch(value);
203 <span class="hljs-keyword">return</span> accumulator;
204 },
205 {}
206 );</pre>
207
208
209
210
211
212
213
214
215 </section>
216
217
218
219
220 <section class='p2 mb2 clearfix bg-white minishadow'>
221
222
223 <div class='clearfix'>
224 <h3 class='fl m0' id='map'>
225 map
226 </h3>
227
228 </div>
229
230
231 <p>Invoke an async transform function on each item in the given Array <strong>in parallel</strong>,
232 returning the resulting Array of mapped/transformed items.</p>
233 <blockquote>
234 <p>This is an asynchronous, parallelized version of <code>Array.prototype.map()</code>.</p>
235 </blockquote>
236
237
238 <div class='pre p1 fill-light mt0'>map(array: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>, mapper: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a></div>
239
240
241
242
243
244
245
246
247
248
249 <div class='py1 quiet mt1 prose-big'>Parameters</div>
250 <div class='prose'>
251
252 <div class='space-bottom0'>
253 <div>
254 <span class='code bold'>array</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>)</code> The Array to map over
255
256 </div>
257
258 </div>
259
260 <div class='space-bottom0'>
261 <div>
262 <span class='code bold'>mapper</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>)</code> Async function, gets passed
263 <code>(value, index, array)</code>
264 , returns the new value.
265
266 </div>
267
268 </div>
269
270 </div>
271
272
273
274
275
276
277 <div class='py1 quiet mt1 prose-big'>Returns</div>
278 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a></code>:
279 resulting mapped/transformed values.
280
281
282
283
284
285
286
287
288 <div class='py1 quiet mt1 prose-big'>Example</div>
289
290
291 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> map(
292 [<span class="hljs-string">'foo'</span>, <span class="hljs-string">'baz'</span>],
293 <span class="hljs-keyword">async</span> v =&gt; <span class="hljs-keyword">await</span> fetch(v)
294 )</pre>
295
296
297
298
299
300
301
302
303 </section>
304
305
306
307
308 <section class='p2 mb2 clearfix bg-white minishadow'>
309
310
311 <div class='clearfix'>
312 <h3 class='fl m0' id='filter'>
313 filter
314 </h3>
315
316 </div>
317
318
319 <p>Invoke an async filter function on each item in the given Array <strong>in parallel</strong>,
320 returning an Array of values for which the filter function returned a truthy value.</p>
321 <blockquote>
322 <p>This is an asynchronous, parallelized version of <code>Array.prototype.filter()</code>.</p>
323 </blockquote>
324
325
326 <div class='pre p1 fill-light mt0'>filter</div>
327
328
329
330
331
332
333
334
335
336
337 <div class='py1 quiet mt1 prose-big'>Parameters</div>
338 <div class='prose'>
339
340 <div class='space-bottom0'>
341 <div>
342 <span class='code bold'>array</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>)</code> The Array to filter
343
344 </div>
345
346 </div>
347
348 <div class='space-bottom0'>
349 <div>
350 <span class='code bold'>filterer</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>)</code> Async function. Gets passed
351 <code>(value, index, array)</code>
352 , returns true to keep the value in the resulting filtered Array.
353
354 </div>
355
356 </div>
357
358 </div>
359
360
361
362
363
364
365 <div class='py1 quiet mt1 prose-big'>Returns</div>
366 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a></code>:
367 resulting filtered values
368
369
370
371
372
373
374
375
376 <div class='py1 quiet mt1 prose-big'>Example</div>
377
378
379 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> filter(
380 [<span class="hljs-string">'foo'</span>, <span class="hljs-string">'baz'</span>],
381 <span class="hljs-keyword">async</span> v =&gt; (<span class="hljs-keyword">await</span> fetch(v)).ok
382 )</pre>
383
384
385
386
387
388
389
390
391 </section>
392
393
394
395
396 <section class='p2 mb2 clearfix bg-white minishadow'>
397
398
399 <div class='clearfix'>
400 <h3 class='fl m0' id='find'>
401 find
402 </h3>
403
404 </div>
405
406
407 <p>Invoke an async function on each item in the given Array <strong>in parallel</strong>,
408 returning the first element predicate returns truthy for.</p>
409 <blockquote>
410 <p>This is an asynchronous, parallelized version of <code>Array.prototype.find()</code>.</p>
411 </blockquote>
412
413
414 <div class='pre p1 fill-light mt0'>find</div>
415
416
417
418
419
420
421
422
423
424
425 <div class='py1 quiet mt1 prose-big'>Parameters</div>
426 <div class='prose'>
427
428 <div class='space-bottom0'>
429 <div>
430 <span class='code bold'>array</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>)</code> The Array to find
431
432 </div>
433
434 </div>
435
436 <div class='space-bottom0'>
437 <div>
438 <span class='code bold'>predicate</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>)</code> Async function. Gets passed
439 <code>(value, index, array)</code>
440 , returns true to be the find result.
441
442 </div>
443
444 </div>
445
446 </div>
447
448
449
450
451
452
453 <div class='py1 quiet mt1 prose-big'>Returns</div>
454 <code>any</code>:
455 resulting find value
456
457
458
459
460
461
462
463
464 <div class='py1 quiet mt1 prose-big'>Example</div>
465
466
467 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> find(
468 [<span class="hljs-string">'foo'</span>, <span class="hljs-string">'baz'</span>, <span class="hljs-string">'root'</span>],
469 <span class="hljs-keyword">async</span> v =&gt; (<span class="hljs-keyword">await</span> fetch(v)).name === <span class="hljs-string">'baz'</span>
470 )</pre>
471
472
473
474
475
476
477
478
479 </section>
480
481
482
483
484 <section class='p2 mb2 clearfix bg-white minishadow'>
485
486
487 <div class='clearfix'>
488 <h3 class='fl m0' id='every'>
489 every
490 </h3>
491
492 </div>
493
494
495 <p>Checks if predicate returns truthy for <strong>all</strong> elements of collection <strong>in parallel</strong>.</p>
496 <blockquote>
497 <p>This is an asynchronous, parallelized version of <code>Array.prototype.every()</code>.</p>
498 </blockquote>
499
500
501 <div class='pre p1 fill-light mt0'>every</div>
502
503
504
505
506
507
508
509
510
511
512 <div class='py1 quiet mt1 prose-big'>Parameters</div>
513 <div class='prose'>
514
515 <div class='space-bottom0'>
516 <div>
517 <span class='code bold'>array</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>)</code> The Array to iterate over.
518
519 </div>
520
521 </div>
522
523 <div class='space-bottom0'>
524 <div>
525 <span class='code bold'>predicate</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>)</code> Async function. Gets passed
526 <code>(value, index, array)</code>
527 , The function invoked per iteration.
528
529 </div>
530
531 </div>
532
533 </div>
534
535
536
537
538
539
540 <div class='py1 quiet mt1 prose-big'>Returns</div>
541 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></code>:
542 Returns true if
543 <strong>all</strong>
544 element passes the predicate check, else false.
545
546
547
548
549
550
551
552
553 <div class='py1 quiet mt1 prose-big'>Example</div>
554
555
556 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> every(
557 [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
558 <span class="hljs-keyword">async</span> v =&gt; (<span class="hljs-keyword">await</span> fetch(v)).ok
559 )</pre>
560
561
562
563
564
565
566
567
568 </section>
569
570
571
572
573 <section class='p2 mb2 clearfix bg-white minishadow'>
574
575
576 <div class='clearfix'>
577 <h3 class='fl m0' id='some'>
578 some
579 </h3>
580
581 </div>
582
583
584 <p>Checks if predicate returns truthy for <strong>any</strong> element of collection <strong>in parallel</strong>.</p>
585 <blockquote>
586 <p>This is an asynchronous, parallelized version of <code>Array.prototype.some()</code>.</p>
587 </blockquote>
588
589
590 <div class='pre p1 fill-light mt0'>some</div>
591
592
593
594
595
596
597
598
599
600
601 <div class='py1 quiet mt1 prose-big'>Parameters</div>
602 <div class='prose'>
603
604 <div class='space-bottom0'>
605 <div>
606 <span class='code bold'>array</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>)</code> The Array to iterate over.
607
608 </div>
609
610 </div>
611
612 <div class='space-bottom0'>
613 <div>
614 <span class='code bold'>filterer</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>)</code> Async function. Gets passed
615 <code>(value, index, array)</code>
616 , The function invoked per iteration.
617
618 </div>
619
620 </div>
621
622 </div>
623
624
625
626
627
628
629 <div class='py1 quiet mt1 prose-big'>Returns</div>
630 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></code>:
631 Returns true if
632 <strong>any</strong>
633 element passes the predicate check, else false.
634
635
636
637
638
639
640
641
642 <div class='py1 quiet mt1 prose-big'>Example</div>
643
644
645 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> some(
646 [<span class="hljs-string">'foo'</span>, <span class="hljs-string">'baz'</span>],
647 <span class="hljs-keyword">async</span> v =&gt; (<span class="hljs-keyword">await</span> fetch(v)).ok
648 )</pre>
649
650
651
652
653
654
655
656
657 </section>
658
659
660
661
662 <section class='p2 mb2 clearfix bg-white minishadow'>
663
664
665 <div class='clearfix'>
666 <h3 class='fl m0' id='parallel'>
667 parallel
668 </h3>
669
670 </div>
671
672
673 <p>Invoke all async functions in an Array or Object <strong>in parallel</strong>, returning the result.</p>
674
675
676 <div class='pre p1 fill-light mt0'>parallel(list: (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>>)): (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</div>
677
678
679
680
681
682
683
684
685
686
687 <div class='py1 quiet mt1 prose-big'>Parameters</div>
688 <div class='prose'>
689
690 <div class='space-bottom0'>
691 <div>
692 <span class='code bold'>list</span> <code class='quiet'>((<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>>))</code> Array/Object with values that are async functions to invoke.
693
694 </div>
695
696 </div>
697
698 </div>
699
700
701
702
703
704
705 <div class='py1 quiet mt1 prose-big'>Returns</div>
706 <code>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code>:
707 same structure as
708 <code>list</code>
709 input, but with values now resolved.
710
711
712
713
714
715
716
717
718 <div class='py1 quiet mt1 prose-big'>Example</div>
719
720
721 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> parallel([
722 <span class="hljs-keyword">async</span> () =&gt; <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'foo'</span>),
723 <span class="hljs-keyword">async</span> () =&gt; <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'baz'</span>)
724 ])</pre>
725
726
727
728
729
730
731
732
733 </section>
734
735
736
737
738 <section class='p2 mb2 clearfix bg-white minishadow'>
739
740
741 <div class='clearfix'>
742 <h3 class='fl m0' id='series'>
743 series
744 </h3>
745
746 </div>
747
748
749 <p>Invoke all async functions in an Array or Object <strong>sequentially</strong>, returning the result.</p>
750
751
752 <div class='pre p1 fill-light mt0'>series(list: (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>>)): (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</div>
753
754
755
756
757
758
759
760
761
762
763 <div class='py1 quiet mt1 prose-big'>Parameters</div>
764 <div class='prose'>
765
766 <div class='space-bottom0'>
767 <div>
768 <span class='code bold'>list</span> <code class='quiet'>((<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function</a>>))</code> Array/Object with values that are async functions to invoke.
769
770 </div>
771
772 </div>
773
774 </div>
775
776
777
778
779
780
781 <div class='py1 quiet mt1 prose-big'>Returns</div>
782 <code>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code>:
783 same structure as
784 <code>list</code>
785 input, but with values now resolved.
786
787
788
789
790
791
792
793
794 <div class='py1 quiet mt1 prose-big'>Example</div>
795
796
797 <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">await</span> series([
798 <span class="hljs-keyword">async</span> () =&gt; <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'foo'</span>),
799 <span class="hljs-keyword">async</span> () =&gt; <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'baz'</span>)
800 ])</pre>
801
802
803
804
805
806
807
808
809 </section>
810
811
812
813 </div>
814 </div>
815 </div>
816 <script src='assets/anchor.js'></script>
817 <script src='assets/site.js'></script>
818 </body>
819 </html>