title: In Node.js design patterns unleashing zalgo why is the asynchronous path consistent?
body: <p>In the great book i'm reading now <code>NodeJs design patterns</code> I see the following example:</p>
  
  <pre><code>var fs = require('fs');
  var cache = {};
  
  function inconsistentRead(filename, callback) {
      if (cache[filename]) {
          //invoked synchronously
          callback(cache[filename]);
      } else {
          //asynchronous function
          fs.readFile(filename, 'utf8', function(err, data) {
              cache[filename] = data;
              callback(data);
          });
      }
  }
  </code></pre>
  
  <p>then:</p>
  
  <pre><code>function createFileReader(filename) {
      var listeners = [];
      inconsistentRead(filename, function(value) {
          listeners.forEach(function(listener) {
              listener(value);
          });
      });
      return {
          onDataReady: function(listener) {
              listeners.push(listener);
          }
      };
  }
  </code></pre>
  
  <p>and usage of it:</p>
  
  <pre><code>var reader1 = createFileReader('data.txt');
  reader1.onDataReady(function(data) {
  console.log('First call data: ' + data);
  </code></pre>
  
  <p>The author says that if the item is in cache the behaviour is synchronous and asynchronous if its not in cache.  I'm ok with that.  he then continues to say that we should be either sync or async.  I'm ok with that.  </p>
  
  <p>What I don't understand is that if I take the asynchronous path then when this line <code>var reader1 = createFileReader('data.txt');</code> is executed can't the asynchronous file read finish already and thus the listener <strong>won't</strong> be registered in the following line which tries to register it?</p>