Skip to content

Instantly share code, notes, and snippets.

@frelar
Last active October 31, 2017 22:39
Show Gist options
  • Save frelar/e98b94123165a7abe8bf7c2242b771cc to your computer and use it in GitHub Desktop.
Save frelar/e98b94123165a7abe8bf7c2242b771cc to your computer and use it in GitHub Desktop.
Small boilerplate for the next project using async.waterfall
var async = require('async'),
open = require('open');
async.waterfall([
async.constant({
output: './pba.pdf'
}),
loadRequest,
loadResponse,
extractPdf,
savePdf,
showPdf
], function(err, result){
if(err) console.error(err);
});
/* Load request xml from file system */
function loadRequest(options, callback) {
console.log('Loaded request xml from file system');
callback(null, options, '<xml/>');
}
/* Load response xml from SOAP service */
function loadResponse(options, request, callback) {
console.log('Loaded response xml from SOAP service');
callback(null, options, '<xml/>');
}
/* Extract pdf from response xml */
function extractPdf(options, response, callback) {
var pdf = 'ABCDEF0123456789';
console.log('Extracted pdf from response xml');
callback(null, options, pdf);
}
/* Save extracted pdf to file system */
function savePdf(options, pdf, callback) {
console.log('Saved extracted pdf to file system');
callback(null, options);
}
/* Show extracted pdf */
function showPdf(options, callback) {
console.log('Showed pdf using default viewer');
open(options.output);
callback(null, options, 'Done!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment