Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lazy option to outputs to delay execution of output if not needed #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jrichardlai
Copy link
Contributor

@jrichardlai jrichardlai commented Nov 26, 2024

What

Add lazy option to outputs to delay execution of output if not needed in all situation where the op is called.

Example:

class MyOp < ::Subroutine::Op

  outputs :heavy_operation, lazy: true

  protected

  def perform
    output :heavy_operation, -> { some_heavy_operation }
  end

  def some_heavy_operation
    # ...
  end

end

@@ -45,32 +63,49 @@ def output(name, value)
raise ::Subroutine::Outputs::UnknownOutputError, name
end

outputs[name] = value
outputs[name] = output_configurations[name].lazy? ? LazyExecutor.new(value) : value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will mess with op_instance.outputs (which is a hash of all the outputs)

maybe outputs can be a method that calls any lazy outputs for backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks updated

@jrichardlai jrichardlai force-pushed the lazy-output branch 2 times, most recently from 4e26476 to cbabd9e Compare November 27, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants