Add helper functions for async task running.

This commit is contained in:
kovacsv 2021-10-23 08:36:01 +02:00
parent 654ffd0acc
commit 19ca7a697b
4 changed files with 18 additions and 12 deletions

View File

@ -61,3 +61,15 @@ OV.RunTaskAsync = function (task)
task ();
}, 0);
};
OV.RunTasks = function (count, callbacks)
{
let taskRunner = new OV.TaskRunner ();
taskRunner.Run (count, callbacks);
};
OV.RunTaskBatch = function (count, batchCount, callbacks)
{
let taskRunner = new OV.TaskRunner ();
taskRunner.RunBatch (count, batchCount, callbacks);
};

View File

@ -62,8 +62,7 @@ OV.FileList = class
GetContent (onReady)
{
let taskRunner = new OV.TaskRunner ();
taskRunner.Run (this.files.length, {
OV.RunTasks (this.files.length, {
runTask : (index, complete) => {
this.GetFileContent (this.files[index], complete);
},

View File

@ -256,8 +256,7 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
}
let threeObject = new THREE.Object3D ();
let taskRunner = new OV.TaskRunner ();
taskRunner.RunBatch (model.MeshCount (), 100, {
OV.RunTaskBatch (model.MeshCount (), 100, {
runTask : (firstIndex, lastIndex, ready) => {
for (let meshIndex = firstIndex; meshIndex <= lastIndex; meshIndex++) {
let mesh = model.GetMesh (meshIndex);

View File

@ -2,9 +2,8 @@ var assert = require ('assert');
describe ('Task Runner', function () {
it ('Run task zero times', function (done) {
var tr = new OV.TaskRunner ();
var numbers = [];
tr.Run (0, {
OV.RunTasks (0, {
runTask : function (index, ready) {
numbers.push (index);
ready ();
@ -17,9 +16,8 @@ describe ('Task Runner', function () {
});
it ('Run task three times', function (done) {
var tr = new OV.TaskRunner ();
var numbers = [];
tr.Run (3, {
OV.RunTasks (3, {
runTask : function (index, ready) {
numbers.push (index);
ready ();
@ -32,9 +30,8 @@ describe ('Task Runner', function () {
});
it ('Run task batched', function (done) {
var tr = new OV.TaskRunner ();
var indices = [];
tr.RunBatch (10, 3, {
OV.RunTaskBatch (10, 3, {
runTask : function (firstIndex, lastIndex, ready) {
indices.push ([firstIndex, lastIndex]);
ready ();
@ -47,9 +44,8 @@ describe ('Task Runner', function () {
});
it ('Run task batched zero times', function (done) {
var tr = new OV.TaskRunner ();
var indices = [];
tr.RunBatch (0, 3, {
OV.RunTaskBatch (0, 3, {
runTask : function (firstIndex, lastIndex, ready) {
indices.push ([firstIndex, lastIndex]);
ready ();