MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / runStep

Method runStep

src/LGraph.ts:450–516  ·  view source on GitHub ↗

* Run N steps (cycles) of the graph * @param num number of steps to run, default is 1 * @param do_not_catch_errors [optional] if you want to try/catch errors * @param limit max number of nodes to execute (used to execute from start to a node)

(num: number, do_not_catch_errors: boolean, limit?: number)

Source from the content-addressed store, hash-verified

448 * @param limit max number of nodes to execute (used to execute from start to a node)
449 */
450 runStep(num: number, do_not_catch_errors: boolean, limit?: number): void {
451 num = num || 1
452
453 const start = LiteGraph.getTime()
454 this.globaltime = 0.001 * (start - this.starttime)
455
456 const nodes = this._nodes_executable || this._nodes
457 if (!nodes) return
458
459 limit = limit || nodes.length
460
461 if (do_not_catch_errors) {
462 // iterations
463 for (let i = 0; i < num; i++) {
464 for (let j = 0; j < limit; ++j) {
465 const node = nodes[j]
466 // FIXME: Looks like copy/paste broken logic - checks for "on", executes "do"
467 if (node.mode == LGraphEventMode.ALWAYS && node.onExecute) {
468 // wrap node.onExecute();
469 node.doExecute?.()
470 }
471 }
472
473 this.fixedtime += this.fixedtime_lapse
474 this.onExecuteStep?.()
475 }
476
477 this.onAfterExecute?.()
478 } else {
479 try {
480 // iterations
481 for (let i = 0; i < num; i++) {
482 for (let j = 0; j < limit; ++j) {
483 const node = nodes[j]
484 if (node.mode == LGraphEventMode.ALWAYS) {
485 node.onExecute?.()
486 }
487 }
488
489 this.fixedtime += this.fixedtime_lapse
490 this.onExecuteStep?.()
491 }
492
493 this.onAfterExecute?.()
494 this.errors_in_execution = false
495 } catch (error) {
496 this.errors_in_execution = true
497 if (LiteGraph.throw_errors) throw error
498
499 if (LiteGraph.debug) console.log("Error during execution:", error)
500 this.stop()
501 }
502 }
503
504 const now = LiteGraph.getTime()
505 let elapsed = now - start
506 if (elapsed == 0) elapsed = 1
507

Callers 2

on_frameMethod · 0.95
startMethod · 0.95

Calls 3

stopMethod · 0.95
doExecuteMethod · 0.80
getTimeMethod · 0.45

Tested by

no test coverage detected