Reputation: 1155
How can I chain the parameters that I need for my both async functions.
The first function fs.readFile returns the content of the file in the callback function as second parameter.
The second function marked requires this content as first parameter. The second parameter is optional and can be an options object. The third parameter is the callback that should give me the converted content as second parameter.
Currently I've tried this code:
var readFile = q.nfbind(fs.readFile);
var md = q.nfbind(marked);
readFile(fileName, 'UTF8')
.then(md)
.then(function (html) {
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', html.length);
res.status(200);
res.end(html);
})
.catch(function (error) {
res.setHeader('Content-Type', 'text/plain');
res.send(500, 'server error: ' + error);
res.end();
})
.done();
But it doesn't work, because the marked function needs the second parameter when it was called with an callback function as third parameter. How can I set the second parameter, to call the marked function correctly?
Upvotes: 0
Views: 756
Reputation:
If you simply replace the .then(md)
line with .then(marked)
, then the result of calling fs.readFile
(the value with which the promise was fulfilled) will be passed to marked
.
Upvotes: 1