Created
          October 24, 2012 16:33 
        
      - 
      
- 
        Save mlaccetti/3947177 to your computer and use it in GitHub Desktop. 
    Function vs. Events
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // | |
| // functional | |
| // | |
| http.request(url, function(req, res) { | |
| var html = ''; | |
| res.on('data', function(chunk) { | |
| html += chunk; | |
| }); | |
| res.on('end', function() { | |
| var elements = html.match(/findMe/g); | |
| _.each(elements, function(element) { | |
| // keep going | |
| }); | |
| }); | |
| }); | |
| // | |
| // event emitter | |
| // | |
| var emit = new EventEmitter(); | |
| emit.on('scrape', function(url, nextStep) { | |
| http.request(url, function(req, res) { | |
| var html = ''; | |
| res.on('data', function(chunk) { | |
| html += chunk; | |
| }); | |
| res.on('end', function() { | |
| emit.emit(nextStep, html); | |
| }); | |
| }); | |
| }); | |
| emit.on('nextStep', function(html) { | |
| var elements = html.match(/findMe/g); | |
| _.each(elements, fnction(element) { | |
| // keep going | |
| }); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment