iterator next method returning new object

Benjamin (Inglor) Gruenbaum inglor at gmail.com
Sun Mar 1 01:26:28 PST 2015


Well, if the user caches the result (in order to pass it to another
iterator) they'll get unexpected results.

Iterator A yields:

```js

{value: 1, done: false}
{value: 2, done: false}
{value: 3, done: false}
{value: 4, done: false}
```

There are two consumers for the iterator (sending the result to remote
servers that perform a calculation) which do something like:

```js
function consume(){
    var toSend = iterator.next();
    if(toSend.done) return Promise.resolve();
    return fetch("/mydata?id="+toSend).then(function(result){
         return {value: toSend.value, response: result};
    });
}
```

Returning a mutable object will cause a race condition which will cause
incorrect results sometimes. Whether or not people will actually do this is
an interesting question but IMO returning mutable objects is a big lose
here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150301/9c99691f/attachment.html>


More information about the es-discuss mailing list