Created
June 5, 2014 00:52
-
-
Save irrationalistic/52eb693b36abe31f1d81 to your computer and use it in GitHub Desktop.
Deep async for parsing RxTerm data
This file contains 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
app.get('...', function(req, res){ | |
var lines = [...]; | |
var lineFns = lines.map(function(line){ | |
return function(cbLines){ | |
var words = line.split(' '); | |
var wordFns = words.map(function(word){ | |
return function(cbWords){ | |
Model.find({term: word}, function(err, docs){ | |
if(docs.length === 0) | |
// null for error and null for value because nothing found | |
cbWords(null, null); | |
else{ | |
// do the proper search to find any match data you want | |
cbWords(null, matchData); | |
} | |
}); | |
}; | |
}); | |
// word functions are created so pass them to the async call | |
async.parallel(wordFns, cbLines); | |
}; | |
}); | |
// all line functions have been defined now... whew... | |
async.parallel(lineFns, function(err, results){ | |
// here, err will be any errors encountered during the CB process | |
// and results will be an array of arrays of data containing matches or null | |
res.send(results); | |
// for example, if you want to just see everything in the page as it is. | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment