add a helper function for easy use

This commit is contained in:
bigcat88
2026-02-04 18:16:42 +02:00
parent d987b0d32d
commit 50975a7a0d
2 changed files with 42 additions and 0 deletions

View File

@@ -23,6 +23,19 @@ current_executing_context: contextvars.ContextVar[ExecutionContext | None] = con
def get_executing_context() -> ExecutionContext | None:
return current_executing_context.get(None)
def is_output_needed(output_index: int) -> bool:
"""Check if an output at the given index is connected downstream.
Returns True if the output might be used (should be computed).
Returns False if the output is definitely not connected (safe to skip).
"""
ctx = get_executing_context()
if ctx is None or ctx.expected_outputs is None:
return True
return output_index in ctx.expected_outputs
class CurrentNodeContext:
"""
Context manager for setting the current executing node context.