I had written a plugin to read all save files in a folder on startup using Node's asynchronous readFile method. Yet my plugin still halts startup for a whole 6 seconds before showing the splash screen, just as it did back when I had used the synchronous version of that method. I was expecting the process to not make anything else wait for it to finish. Here's the code snippet that handles the file-reading:
And here's the top-level Promise then-chain involved:
What am I doing wrong here? If it helps, I'm using MV 1.5.1.
JavaScript:
static AssignDecompressedJson(args)
{
return new Promise(function(onJsonReady, onReject)
{
fs.readFile(args.filePath, 'utf8', SendDecompressedJson);
function SendDecompressedJson(err, text)
{
args.decompressedJson = LZString.decompressFromBase64(text);
onJsonReady(args);
}
});
}
And here's the top-level Promise then-chain involved:
JavaScript:
function FindClearDataAsync()
{
return new Promise(function(onResolve, onReject)
{
FindAllSaveDataAsync()
.then(PickOutClearDataAsync)
.then(SortClearDataAscendingAsync)
.then(AssignClearDataToNamespaceAsync);
});
}
What am I doing wrong here? If it helps, I'm using MV 1.5.1.