title: async.js map/each with non-reentrant method
body: <p>I am using async.js to work on an array that holds roughly 12'000 values. The problem I'm currently facing is that I am not 100% certain what I can take for granted from async.js. First let me show you an abstract of the iterator function im using (coffeescript):</p>
  
  <pre><code>baseFace = 0
  dataBuffer = new DataBuffer() # my own class that wraps DataView on an Uint8Array
  async.each(@blocks, 
       (block, callback) =&gt;
            numFaces = writeToBuffer(dataBuffer, block, baseFace)
            baseFace += numFaces
            callback(null)
        ,
        () =&gt;
            console.log 'done'
  )
  </code></pre>
  
  <p>So essentially the order in which the blocks are written to the buffers is unimportant, but there are two things I need to be assured of:</p>
  
  <ul>
  <li><p>The entire <code>writeToBuffer</code> has to be done atomic, its not reentrant since it writes to the end of the given buffer and the block has to be written as one (multiple calls to DataView.setXXXX) </p></li>
  <li><p>The <code>baseFace</code> variable too must be accessed atomically inside the function. it cant be that <code>writeToBuffer</code> is called for another element before the face count of the previous call to <code>writeToBuffer</code> has been added to <code>baseFace</code></p></li>
  </ul>
  
  <p>Basically you can say my iterator cannot be evaluated multiple times at the same time, not even with interleaving (like, writeToBuffer, writeToBuffer, baseFace += numFaces, baseFace += numFaces). Coming from C++/C# etc I always fear that something goes wrong when methods access data like in the above example.</p>
  
  <p>Thank you for any insight or tips about that topic, Cromon</p>