title: Pattern for caching resources
body: <p>I have a game with images -- I would like to cache them silently before the games begins. Thus I can have two scenarios:</p>
  
  <ol>
  <li>the code was loaded</li>
  <li>caching started</li>
  <li>caching finished</li>
  <li>user started the game</li>
  <li>run the game</li>
  </ol>
  
  <p>OR</p>
  
  <ol>
  <li>the code was loaded</li>
  <li>caching started</li>
  <li>user started the game --> progress is displayed</li>
  <li>caching finished</li>
  <li>run the game</li>
  </ol>
  
  <p>For the second case, I could pass to caching function a callback to run the game. But since first case can happen I cannot do this, because I have to wait for the user as well.</p>
  
  <p>So now I am thinking about having global (ouch) variable which would be a callback <code>onGameStart</code>. By default it would be displaying progress, but caching callback would do two things -- reset <code>onGameStart</code> to actually starting the game, and checking if the game was started, if it was, it would continue immediately.</p>
  
  <p>Did I miss something? Is it the right pattern?</p>