Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #34399

Re: Running promises in order

Newsgroups comp.lang.javascript
Date 2017-12-02 04:04 -0800
References <QKqdnRBapfSmMoHHnZ2dnUU7-KHNnZ2d@westnet.com.au>
Message-ID <e7b971cd-da81-4da2-8cd1-539ae51aee07@googlegroups.com> (permalink)
Subject Re: Running promises in order
From ali.abdulhannan@gmail.com

Show all headers | View raw


On Monday, November 27, 2017 at 5:35:22 PM UTC-7, Andrew Poulos wrote:
> How do I run an arbitrary number of promises where the subsequent 
> promise is not to run before the previous promise is fulfilled?
> 
> The values a previous promise generates is used by subsequent promises.
> 
> The various examples I've googled have the user triggering the next 
> promise eg. by clicking a button.
> 
> Andrew Poulos

Happened to check this usenet group, so would like to weigh in. The reduce function is something I would use

<code lang="js">
  const pArray = [ p1, p2, p3 ];
  const fulfilledResults = [];
  pArray.reduce((prev, current) => prev.then((...args) = {
    fulfilledResults.push(args);
  })));
</code>

However if you have many of those usecases I would suggest you to check out Bluebird library which handles scenarios such as these already. Specifically check the <a href="http://bluebirdjs.com/docs/api/promise.mapseries.html">Promise.mapSeries</a> method

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Running promises in order Andrew Poulos <ap_prog@hotmail.com> - 2017-11-28 11:35 +1100
  Re: Running promises in order "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-11-28 13:02 +0100
  Re: Running promises in order "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-28 13:31 -0800
    Re: Running promises in order Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-12-01 02:37 +0100
      Re: Running promises in order "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-12-01 06:53 -0800
  Re: Running promises in order ali.abdulhannan@gmail.com - 2017-12-02 04:04 -0800

csiph-web