Skip to content

Instantly share code, notes, and snippets.

@djthread
Created August 31, 2012 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djthread/3558936 to your computer and use it in GitHub Desktop.
Save djthread/3558936 to your computer and use it in GitHub Desktop.
chaining file reads?
loadConfigFile = (err, data) ->
log.log "Reading Global Config File..."
if err
log.log 'db/config.json not found. starting new one..'
else
for key, val of JSON.parse data
if config[key] != undefined then config[key] = val
log.log "Loaded."
log.log ""
filesystem.readFile 'db/feeds.json', loadFeedsFile
loadFeedsFile = (err, data) ->
log.log "Reading feeds from file..."
if err
log.log 'db/data.json not found. starting new one..'
return
for feed in JSON.parse data
items = []
for i in feed.items
items.push = new FeedItem(i)
feed.items = items
feed.config = new FeedConfig(feed.config)
feeds.push new Feed(feed)
log.log "Loaded #{feeds.length} feeds"
log.log ""
filesystem.readFile 'db/config.json', loadConfigFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment