Browse Source

Added a queue for the queue action

pull/357/head
pythongosssss 2 years ago
parent
commit
178fc76363
  1. 63
      web/scripts/app.js

63
web/scripts/app.js

@ -5,6 +5,15 @@ import { defaultGraph } from "./defaultGraph.js";
import { getPngMetadata, importA1111 } from "./pnginfo.js"; import { getPngMetadata, importA1111 } from "./pnginfo.js";
class ComfyApp { class ComfyApp {
/**
* List of {number, batchCount} entries to queue
*/
#queueItems = [];
/**
* If the queue is currently being processed
*/
#processingQueue = false;
constructor() { constructor() {
this.ui = new ComfyUI(this); this.ui = new ComfyUI(this);
this.extensions = []; this.extensions = [];
@ -915,31 +924,47 @@ class ComfyApp {
} }
async queuePrompt(number, batchCount = 1) { async queuePrompt(number, batchCount = 1) {
for (let i = 0; i < batchCount; i++) { this.#queueItems.push({ number, batchCount });
const p = await this.graphToPrompt();
try { // Only have one action process the items so each one gets a unique seed correctly
await api.queuePrompt(number, p); if (this.#processingQueue) {
} catch (error) { return;
this.ui.dialog.show(error.response || error.toString()); }
return;
} this.#processingQueue = true;
try {
while (this.#queueItems.length) {
({ number, batchCount } = this.#queueItems.pop());
for (const n of p.workflow.nodes) { for (let i = 0; i < batchCount; i++) {
const node = graph.getNodeById(n.id); const p = await this.graphToPrompt();
if (node.widgets) {
for (const widget of node.widgets) { try {
// Allow widgets to run callbacks after a prompt has been queued await api.queuePrompt(number, p);
// e.g. random seed after every gen } catch (error) {
if (widget.afterQueued) { this.ui.dialog.show(error.response || error.toString());
widget.afterQueued(); break;
}
for (const n of p.workflow.nodes) {
const node = graph.getNodeById(n.id);
if (node.widgets) {
for (const widget of node.widgets) {
// Allow widgets to run callbacks after a prompt has been queued
// e.g. random seed after every gen
if (widget.afterQueued) {
widget.afterQueued();
}
}
} }
} }
this.canvas.draw(true, true);
await this.ui.queue.update();
} }
} }
} finally {
this.canvas.draw(true, true); this.#processingQueue = false;
await this.ui.queue.update();
} }
} }

Loading…
Cancel
Save