Add function to run a single task asynchronously.

This commit is contained in:
Viktor Kovacs 2021-03-31 17:52:26 +02:00
parent 515caed254
commit d1000c0c93
3 changed files with 32 additions and 35 deletions

View File

@ -39,3 +39,10 @@ OV.TaskRunner = class
}
}
};
OV.RunTaskAsync = function (task)
{
setTimeout (function () {
task ();
}, 0);
};

View File

@ -44,22 +44,16 @@ OV.ThreeModelLoader = class
{
let obj = this;
this.callbacks.onFilesLoaded ();
let taskRunner = new OV.TaskRunner ();
taskRunner.Run (1, {
runTask : function (index, ready) {
obj.importer.Import ({
success : function (importResult) {
obj.OnModelImported (importResult);
ready ();
},
error : function (importError) {
obj.callbacks.onLoadError (importError);
obj.inProgress = false;
ready ();
}
});
}
OV.RunTaskAsync (function () {
obj.importer.Import ({
success : function (importResult) {
obj.OnModelImported (importResult);
},
error : function (importError) {
obj.callbacks.onLoadError (importError);
obj.inProgress = false;
}
});
});
}

View File

@ -256,26 +256,22 @@ OV.ShowExportDialog = function (model)
let selectedFormat = formats[selectedIndex - 1];
fileList.html ('Please wait...');
let taskRunner = new OV.TaskRunner ();
taskRunner.Run (1, {
runTask : function (index, ready) {
let exporter = new OV.Exporter ();
let files = exporter.Export (model, selectedFormat.format, selectedFormat.extension);
fileList.empty ();
for (let i = 0; i < files.length; i++) {
let file = files[i];
let url = file.GetUrl ();
if (url === null) {
url = OV.CreateObjectUrl (file.GetContent ());
createdUrls.push (url);
}
let fileLink = $('<a>').addClass ('ov_dialog_file_link').appendTo (fileList);
fileLink.attr ('href', url);
fileLink.attr ('download', file.GetName ());
$('<img>').addClass ('ov_dialog_file_link_icon').attr ('src', 'assets/images/dialog/file_download.svg').appendTo (fileLink);
$('<div>').addClass ('ov_dialog_file_link_text').html (file.GetName ()).appendTo (fileLink);
OV.RunTaskAsync (function () {
let exporter = new OV.Exporter ();
let files = exporter.Export (model, selectedFormat.format, selectedFormat.extension);
fileList.empty ();
for (let i = 0; i < files.length; i++) {
let file = files[i];
let url = file.GetUrl ();
if (url === null) {
url = OV.CreateObjectUrl (file.GetContent ());
createdUrls.push (url);
}
ready ();
let fileLink = $('<a>').addClass ('ov_dialog_file_link').appendTo (fileList);
fileLink.attr ('href', url);
fileLink.attr ('download', file.GetName ());
$('<img>').addClass ('ov_dialog_file_link_icon').attr ('src', 'assets/images/dialog/file_download.svg').appendTo (fileLink);
$('<div>').addClass ('ov_dialog_file_link_text').html (file.GetName ()).appendTo (fileLink);
}
});
});