mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-25 15:55:18 +00:00
Merge branch 'queue-queue' of https://github.com/pythongosssss/ComfyUI
This commit is contained in:
commit
d4273eadcd
@ -5,6 +5,15 @@ import { defaultGraph } from "./defaultGraph.js";
|
||||
import { getPngMetadata, importA1111 } from "./pnginfo.js";
|
||||
|
||||
class ComfyApp {
|
||||
/**
|
||||
* List of {number, batchCount} entries to queue
|
||||
*/
|
||||
#queueItems = [];
|
||||
/**
|
||||
* If the queue is currently being processed
|
||||
*/
|
||||
#processingQueue = false;
|
||||
|
||||
constructor() {
|
||||
this.ui = new ComfyUI(this);
|
||||
this.extensions = [];
|
||||
@ -915,31 +924,47 @@ class ComfyApp {
|
||||
}
|
||||
|
||||
async queuePrompt(number, batchCount = 1) {
|
||||
for (let i = 0; i < batchCount; i++) {
|
||||
const p = await this.graphToPrompt();
|
||||
this.#queueItems.push({ number, batchCount });
|
||||
|
||||
try {
|
||||
await api.queuePrompt(number, p);
|
||||
} catch (error) {
|
||||
this.ui.dialog.show(error.response || error.toString());
|
||||
return;
|
||||
}
|
||||
// Only have one action process the items so each one gets a unique seed correctly
|
||||
if (this.#processingQueue) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#processingQueue = true;
|
||||
try {
|
||||
while (this.#queueItems.length) {
|
||||
({ number, batchCount } = this.#queueItems.pop());
|
||||
|
||||
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();
|
||||
for (let i = 0; i < batchCount; i++) {
|
||||
const p = await this.graphToPrompt();
|
||||
|
||||
try {
|
||||
await api.queuePrompt(number, p);
|
||||
} catch (error) {
|
||||
this.ui.dialog.show(error.response || error.toString());
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
this.canvas.draw(true, true);
|
||||
await this.ui.queue.update();
|
||||
} finally {
|
||||
this.#processingQueue = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user