Moving function to utilities

This commit is contained in:
Luis Fernando Molina committed 2021-02-04 13:52:31 +01:00
1 parent 089281344e
commit bc9ece59d3
2 files changed
+26 -22

No files matched your search

@@ -337,7 +337,7 @@
let filePath = datasetModule.node.parentNode.config.codeName + '/' + datasetModule.node.config.codeName
/* We cut the async calls via callBacks at this point, so as to have a clearer code upstream */
let response = await asyncGetDatasetFile(datasetModule, filePath, fileName)
let response = await TS.projects.superalgos.utilities.miscellaneousFunctions.asyncGetDatasetFile(datasetModule, filePath, fileName)
if (response.err.message === 'File does not exist.') {
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
@@ -429,7 +429,7 @@
let filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel
/* We cut the async calls via callBacks at this point, so as to have a clearer code upstream */
let response = await asyncGetDatasetFile(datasetModule, filePath, fileName)
let response = await TS.projects.superalgos.utilities.miscellaneousFunctions.asyncGetDatasetFile(datasetModule, filePath, fileName)
if (response.err.message === 'File does not exist.') {
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
@@ -582,7 +582,7 @@
let fileName = "Data.json"
/* We cut the async calls via callBacks at this point, so as to have a clearer code upstream */
let response = await asyncGetDatasetFile(datasetModule, filePath, fileName)
let response = await TS.projects.superalgos.utilities.miscellaneousFunctions.asyncGetDatasetFile(datasetModule, filePath, fileName)
if (response.err.message === 'File does not exist.') {
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
@@ -933,22 +933,4 @@
}
}
}
async function asyncGetDatasetFile(datasetModule, filePath, fileName) {
let promise = new Promise((resolve, reject) => {
datasetModule.getTextFile(filePath, fileName, onFileReceived)
function onFileReceived(err, text) {
let response = {
err: err,
text: text
}
resolve(response)
}
})
return promise
}
}
@@ -3,7 +3,8 @@ exports.newSuperalgosUtilitiesMiscellaneousFunctions = function () {
let thisObject = {
genereteUniqueId: genereteUniqueId,
truncateToThisPrecision: truncateToThisPrecision,
pad: pad
pad: pad,
asyncGetDatasetFile: asyncGetDatasetFile
}
return thisObject
@@ -23,4 +24,25 @@ exports.newSuperalgosUtilitiesMiscellaneousFunctions = function () {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
async function asyncGetDatasetFile(datasetModule, filePath, fileName) {
/*
This function helps a caller to use await syntax while the called
function uses callbacks, specifically for retrieving files.
*/
let promise = new Promise((resolve, reject) => {
datasetModule.getTextFile(filePath, fileName, onFileReceived)
function onFileReceived(err, text) {
let response = {
err: err,
text: text
}
resolve(response)
}
})
return promise
}
}