Skip to content

Instantly share code, notes, and snippets.

@ermst4r
Last active September 2, 2016 07:26
Show Gist options
  • Save ermst4r/49e172d31ec6c632dbb102331eaed6f7 to your computer and use it in GitHub Desktop.
Save ermst4r/49e172d31ec6c632dbb102331eaed6f7 to your computer and use it in GitHub Desktop.
parse: function(feed) {
return new Promise(function(resolve, reject) { // wrap into function to return a promise
sails.log.info('downloading feed ' + feed.id );
importcsv_service.parsecsvfeed.downloadfile(feed,csv_dir).then(function(file){
sails.log.info('file '+ feed.id +' downloaded succesfully');
return file;
}).then(function(file) {
console.log("reading" + file);
importcsv_service.parsecsvfeed.convert_line_to_json(file).then(function(data) {
sails.log.info('feed '+ feed.id +' can be read succesfully :-)');
resolve(data); //<== Over here i return a promise, see it as true, you can also do resolve(true)
}, function(csvparserror){
sails.log.error(csvparserror);
return reject(new Error(csvparserror)); //<== Over here i return a promise, see it as true, you can also do reject(false)
});
//
},function(connection_error) {
sails.log.error(connection_error);
return reject(new Error(connection_error));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment