iterator next method returning new object

Benjamin (Inglor) Gruenbaum inglor at
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:


{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:

function consume(){
    var toSend =;
    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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list