This is the constant problem with Futures/Promises.

The neat thing with await is that one can use try/catch for the errback


On Wed, Apr 3, 2013 at 2:29 PM, Eduard Burtescu <notifications@github.com>wrote:

> In demo/parallel-fibonacci.js:
>
> > +function fib(n) {
> > +  var a = 0, b = 1;
> > +  for (var i = 0; i < n; i++) {
> > +    [a, b] = [b, a + b];
> > +
> > +    // Every 4 iterations, 'yield'.
> > +    if ((i & 3) === 0)
> > +      await process.nextTick(); // await setTimeout(0);
> > +  }
> > +  return [a, b, i];
> > +};
> > +
> > +var maxIterations = Number(process.argv[2] || 50);
> > +var concurrentAttempts = Number(process.argv[3] || 10);
> > +for (var i = 0; i < concurrentAttempts; i++) {
> > +  fib(Math.random() * maxIterations).then(([a, b, i]) => {
>
> If only we had an await expression. Or errback doing something when
> there's no handler, instead of letting the error just fade away.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/google/traceur-compiler/pull/237/files#r3642349>
> .
>



-- 
erik