EzDevInfo.com

task.js

Beautiful concurrency for JavaScript Task.js: Beautiful Concurrency for JavaScript

Strange yield syntax in JavaScript

I just took a look at Dave Herman's very interesting task.js. In his example he has this line:

var [foo, bar] = yield join(read("foo.json"),
                                read("bar.json")).timeout(1000);

I'm familiar with generators but I don't understand how the yield expression evaluates to something that can be assigned to [foo, bar]. I actually wouldn't have expected the expression to be assignable to anything since it is basically the same thing as return.

The yield syntax for JS still seems a bit underdocumented and I couldn't find info about this.

So to clarify my question: what ends up being assigned to foo and bar?


Source: (StackOverflow)