Promise-returning delay function

Andrea Giammarchi andrea.giammarchi at
Tue Oct 28 15:10:02 PDT 2014

Again, you might have an error that comes from "ringTheAlarmBell()" API ...
you are making the problem simple but simple is not the moment all you do
is returning a Promise with binary result (success/error) without
considering that when you reopen, much more could happen ... you **want**
to branch out, not keeping doing the same action and that error could come
for many reasons.

Your control flow here, if you have to take care of all cases, will become
a mess full of nested callbacks ... oh, irony

On Tue, Oct 28, 2014 at 7:39 PM, C. Scott Ananian <ecmascript at>

> On Tue, Oct 28, 2014 at 2:24 PM, Andrea Giammarchi
> <andrea.giammarchi at> wrote:
> > I really need to **drop that action** ... not to wait for it to fulfill
> and
> > then do something else.
> This is orthogonal to the use of Promises, which just discuss control flow.
> > Imagine it's not about network, imagine it's "a lift" ... door are
> closing,
> > someone passes in the middle, what do you do now: sound the alert after
> > chopping the person that tried to enter in the meanwhile or change floor
> ...
> > after chopping the person anyway ?
> You call the `Door.interrupt()` API method to indicate that a person
> is present/cancel the opening.
> Again, this is orthogonal to the Promise that the `Door.close()`
> method returned.  If `Door.close()` returned a Promise, then that
> promise could then resolve to "cancelled" value (instead of
> "success"), or else you could decide that rejecting the promise with a
> `DoorCloseInterrupted` exception makes more sense.
> The asynchronous cancellation mechanism is not related to Promises,
> and shouldn't be conflated with the Promise API.  The Promise
> mechanism just directs control flow after the door has either been
> successfully closed or cancelled.
> Concretely:
> ```
> function tryToAscend() {
> return Door.close().then(function() { return raiseLift(); },
> function(e) { return*1000).then(tryToAscend); });
> };
> ```
>  --scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list