clean up work cancellation
This commit is contained in:
parent
5bb6e6e905
commit
18fded64db
3 changed files with 25 additions and 13 deletions
|
|
@ -14,8 +14,8 @@ let KIRI = self.kiri = self.kiri || {},
|
||||||
seqid = 1,
|
seqid = 1,
|
||||||
syncd = {},
|
syncd = {},
|
||||||
running = {},
|
running = {},
|
||||||
slicing = {},
|
worker = null,
|
||||||
worker = null
|
restarting = false
|
||||||
// occ = new Worker("/kiri/ext/occ-worker.js", {type:"module"}),
|
// occ = new Worker("/kiri/ext/occ-worker.js", {type:"module"}),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -57,25 +57,34 @@ KIRI.work = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
isSlicing: function() {
|
isBusy: function() {
|
||||||
let current = 0;
|
let current = 0;
|
||||||
for (let key in slicing) {
|
for (let rec of Object.values(running)) {
|
||||||
current++;
|
if (rec.fn) current++;
|
||||||
}
|
}
|
||||||
return current > 0;
|
return current > 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
restart: function() {
|
restart: function() {
|
||||||
|
// prevent re-entry from cancel callback
|
||||||
|
if (restarting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (worker) {
|
if (worker) {
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (let key in slicing) {
|
restarting = true;
|
||||||
// slicing[key]({error: "cancelled slicing"});
|
|
||||||
// }
|
for (let key in running) {
|
||||||
|
let rec = running[key];
|
||||||
|
if (rec.fn) {
|
||||||
|
rec.fn({error: "cancelled operation"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
syncd = {};
|
syncd = {};
|
||||||
slicing = {};
|
|
||||||
running = {};
|
running = {};
|
||||||
worker = KIRI.work.newWorker();
|
worker = KIRI.work.newWorker();
|
||||||
|
|
||||||
|
|
@ -95,6 +104,8 @@ KIRI.work = {
|
||||||
|
|
||||||
onreply(reply.data, reply);
|
onreply(reply.data, reply);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
restarting = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
decimate: function(vertices, options, callback) {
|
decimate: function(vertices, options, callback) {
|
||||||
|
|
@ -169,14 +180,12 @@ KIRI.work = {
|
||||||
},
|
},
|
||||||
|
|
||||||
slice: function(settings, widget, callback) {
|
slice: function(settings, widget, callback) {
|
||||||
slicing[widget.id] = callback;
|
|
||||||
send("slice", {
|
send("slice", {
|
||||||
id: widget.id,
|
id: widget.id,
|
||||||
settings: settings
|
settings: settings
|
||||||
}, function(reply) {
|
}, function(reply) {
|
||||||
callback(reply);
|
callback(reply);
|
||||||
if (reply.done || reply.error) {
|
if (reply.done || reply.error) {
|
||||||
delete slicing[widget.id];
|
|
||||||
// in belt mode, slicing modifies a widget and requires re-sync
|
// in belt mode, slicing modifies a widget and requires re-sync
|
||||||
if (settings.device.bedBelt) {
|
if (settings.device.bedBelt) {
|
||||||
widget.modified = true;
|
widget.modified = true;
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,8 @@
|
||||||
// hide all dialogs
|
// hide all dialogs
|
||||||
API.dialog.hide();
|
API.dialog.hide();
|
||||||
// cancel slicing
|
// cancel slicing
|
||||||
if (KIRI.work.isSlicing()) KIRI.work.restart();
|
API.function.cancel();
|
||||||
|
// if (KIRI.work.isSlicing()) KIRI.work.restart();
|
||||||
// kill any poppers in compact mode
|
// kill any poppers in compact mode
|
||||||
UC.hidePoppers();
|
UC.hidePoppers();
|
||||||
// and send an event (used by FDM client)
|
// and send an event (used by FDM client)
|
||||||
|
|
|
||||||
|
|
@ -918,7 +918,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelWorker() {
|
function cancelWorker() {
|
||||||
if (KIRI.work.isSlicing()) KIRI.work.restart();
|
if (KIRI.work.isBusy()) {
|
||||||
|
KIRI.work.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSlider() {
|
function showSlider() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue