title: Matlab events and listeners: propagate information out of the Event call
body: <p>I have an object that incorporates an event which is created in my program(specifically, a session based ni daq with a 'DataAvailable' event which fires every time a set number of samples is acquired.) This event will be fired at random times during the course of running my program that will do other stuff independent of recording. When fired, it will collect and save the data chunk in a file.</p>
  
  <p>My issue is that everytime the Event is triggered, i need to increase a counter (i name it "chunk") in my original program. This is critical as a number of features in my program depend on my being able to measure the number of chunks accurately. </p>
  
  <p>QUESTION: how can i propagate the fact that an event has been triggered into my main program?</p>
  
  <p>For people who process (pseudo)code better:</p>
  
  <pre><code>setupStuff();
  endLoop = false;
  while ~endLoop
    if ~recording
      session  = createDAQSessionObject(params);
      chunkNum = 0;
      session.addListener('DataAvailable',@(src,event)saveChunk(src,event,chunkNum));
      session.startBackGround()
      recording  = true;
    end
    endLoop = doOtherStuff();
    pause(0.1);
  end
  
  function saveChunk(src,event,numChunk)
    filename = sprintf('chunk%d.mat',numChunk);
    times = event.TimeStamps;
    data = event.Data;
    save(filename,'times','data');
    % but now the next time around we need to get in numChunks+1 (but we never will because we have no way of knowing that the event was called...
  end
  </code></pre>
  
  <p>Thanks</p>
  
  <p>-bas</p>