code: def __next__(self):
      from lightning.app.structures import Dict
  
      while self.queue:
          component = self.queue.pop(0)
  
          if isinstance(component, lightning.app.LightningFlow):
              components = [
                  getattr(component, el)
                  for el in sorted(component._flows)
              ]
              for struct_name in sorted(component._structures):
                  structure = getattr(component, struct_name)
                  if isinstance(structure, Dict):
                      values = sorted(
                          structure.items(), key=lambda x: x[0]
                      )
                  else:
                      values = sorted(
                          ((v.name, v) for v in structure),
                          key=lambda x: x[0],
                      )
                  for _, value in values:
                      if isinstance(value, lightning.app.LightningFlow):
                          components.append(value)
              self.queue += components
              self.queue += component.works(recurse=False)
  
          if any(isinstance(component, t) for t in self.types):
              return component
  
      raise StopIteration
  
file_path: pytorch-lightning/src/lightning/app/utilities/tree.py
imports: from typing import TYPE_CHECKING, Type
  import lightning.app
label_desc: Use image node_id 3 for calling the _BreadthFirstVisitor obj's underlying member method code with example usage: obj.__next__() and returns: component