I agree, Promises easily allow you to do this. Even if you wanted to 'wait'
on an event, you can either.

1. Use EventEmitter and simply have an 'on' handler
2. Create a promise and pass the resolve function to whatever js doing the
work, and `await` on the promise itself

You can also wrap an event emitter callback with a promise, oe use
something like RxJS for Observables. So many possibilities.

On Fri, May 11, 2018, 4:56 PM Michał Wadas <[email protected]> wrote:

> What's wrong with async functions and
> await Promise.all([a, b, c])
> ?
>
> On Fri, May 11, 2018 at 11:14 PM, Matthew Tedder <
> [email protected]> wrote:
>
>>
>> wait for ( condition );
>>
>> Stop executing statements until the condition evaluates to true.  To
>> implement this, freeze the instance of the function in, add a hook to each
>> variable in the condition so that when its value is written to, the
>> condition is re-evaluated.
>>
>> This will greatly increase the clarity and reduce coding needed for
>> operations with many asynchronous calls and any with callbacks using arrow
>> functions..  E.g.,
>>
>> let a = false;
>> let b = 5;
>> let c = 'oranges';
>> doSomethenWhenever( () => { a = true; }
>> doAnotherThingWhenever( () => { b = 16; }
>> DoYetAnotherThing( () => { c = 'apples'; }
>> wait for ( a && b > 10 && c !== 'oranges' );
>> console.log('Conditions are met!');
>>
>>
>> --
>> Matthew C. Tedder
>> HyperConversal, Inc.
>> Desk: 352-381-7142 / Cell: 509-432-5520
>>
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to