Fix batch task running in case of zero count.

This commit is contained in:
kovacsv 2021-06-14 14:25:23 +02:00
parent 1cdf592c4f
commit 67a249f528
2 changed files with 19 additions and 1 deletions

View File

@ -21,7 +21,10 @@ OV.TaskRunner = class
RunBatch (count, batchCount, callbacks)
{
const stepCount = parseInt ((count - 1) / batchCount, 10) + 1;
let stepCount = 0;
if (count > 0) {
stepCount = parseInt ((count - 1) / batchCount, 10) + 1;
}
this.Run (stepCount, {
runTask : function (index, ready) {
const firstIndex = index * batchCount;

View File

@ -44,5 +44,20 @@ describe ('Task Runner', function () {
done ();
}
});
});
it ('Run task batched zero times', function (done) {
var tr = new OV.TaskRunner ();
var indices = [];
tr.RunBatch (0, 3, {
runTask : function (firstIndex, lastIndex, ready) {
indices.push ([firstIndex, lastIndex]);
ready ();
},
onReady : function () {
assert.deepStrictEqual (indices, []);
done ();
}
});
});
});