Permalink
Browse files

Merge pull request #12 from ben-miller/master

create makelistSync function
  • Loading branch information...
daitangio committed Sep 7, 2017
2 parents 9bb4ad1 + 5b85b22 commit e9293d49a68788c3d645dd1bd4ae47117f583450
Showing with 49 additions and 24 deletions.
  1. +49 −24 lib/org-mode-parser.js
View
@@ -626,45 +626,69 @@ var makelistFromStringWithPerformance=function(data,processFunction, passPerform
}
};
var makelist=function(fileName, processFunction, passPerformanceAlso){
// This function translates the callback behavior expected from
// makelistNode into the callback behavior expected from this function
var translateFunc = function (err, list) {
if (err) {
throw err;
}
processFunction(list);
};
var makelist=function(fileName, processFunction, passPerformanceAlso, sync){
if (sync) {
return makelistNodeSync(fileName, passPerformanceAlso);
} else {
// This function translates the callback behavior expected from
// makelistNode into the callback behavior expected from this function
var translateFunc = function (err, list) {
if (err) {
throw err;
}
makelistNode(fileName, translateFunc, passPerformanceAlso);
processFunction(list);
};
makelistNode(fileName, translateFunc, passPerformanceAlso);
}
};
var makelistSync = function(fileName, passPerformanceAlso) {
return makelist(fileName, undefined, passPerformanceAlso, true);
}
var makelistWithPerformance = function (fileName,processFunction){
makelist(fileName,processFunction,true);
};
var makelistNode = function(fileName, processFunction, passPerformanceAlso){
fs.readFile(fileName, 'utf-8',function (err,data){
if (err) {
processFunction(err);
return;
}
var makelistNodeCallback = function(err, data, processFunction, passPerformanceAlso) {
if (err) {
processFunction(err);
return;
}
var successFunction = function (list) {
processFunction(null, list);
};
var successFunction = function (list) {
processFunction(null, list);
};
try {
makelistFromStringWithPerformance(data,successFunction,passPerformanceAlso);
} catch (err) {
processFunction(err);
}
try {
makelistFromStringWithPerformance(data,successFunction,passPerformanceAlso);
} catch (err) {
processFunction(err);
}
}
var makelistNode = function(fileName, processFunction, passPerformanceAlso){
fs.readFile(fileName, 'utf-8',function (err,data){
makelistNodeCallback(err, data, processFunction, passPerformanceAlso);
});
};
var makelistNodeSync = function(fileName, passPerformanceAlso) {
try {
var data = fs.readFileSync(fileName, 'utf-8');
} catch (err) {
return err;
}
var result;
var processFunction = function(err, list) {
result = list;
};
makelistNodeCallback(null, data, processFunction, passPerformanceAlso);
return result;
}
// A new object for overall information, subtree-querying
@@ -1059,6 +1083,7 @@ var OrgQuery=(function ()
exports.makelistWithPerformance=makelistWithPerformance;
exports.makelistFromStringWithPerformance=makelistFromStringWithPerformance;
exports.makelist=makelist;
exports.makelistSync=makelistSync;
exports.makelistNode=makelistNode;
exports.OrgQuery=OrgQuery;

0 comments on commit e9293d4

Please sign in to comment.