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


Groups > comp.lang.javascript > #34397

Re: Running promises in order

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Running promises in order
Date 2017-12-01 02:37 +0100
Organization PointedEars Software (PES)
Message-ID <4793140.hK7J4vrPBd@PointedEars.de> (permalink)
References <QKqdnRBapfSmMoHHnZ2dnUU7-KHNnZ2d@westnet.com.au> <984bc0e7-1a08-444d-baac-caa0b7283380@googlegroups.com>

Show all headers | View raw


Michael Haufe (TNO) wrote:

> On Monday, November 27, 2017 at 6:35:22 PM UTC-6, 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.
> 
> At first blush, something like the following:
> 
> promiseArray.reduce((prev, curr) => (
>     prev.then(resultList => (
>         asyncFunc(curr).then(result => resultList.concat(result))
>     ))
> ), Promise.resolve([]));

That is a very clever (mis)use of Array.prototype.reduce() :)

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next 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