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 support for handle_continue/2 callback #300

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

maartenvanvliet
Copy link

@maartenvanvliet maartenvanvliet commented May 11, 2023

I took the liberty to address the feedback for this PR #264 as it was open for more than a year. @hazardfn hope you are okay with this?

GenServers also support a timeout in the return value {:ok, state, timeout | :hibernate | {:continue, term}}which is currently not supported by GenStage. I've added this too.

hazardfn and others added 4 commits May 12, 2023 11:44
  * {:continue, _term} instructions can now be returned as one
    would expect from gen_server.

  * :hibernate is now supported on init similar to gen_server.
lib/gen_stage.ex Outdated
init_producer(mod, opts, state)
init_producer(mod, opts, state, nil)

{:producer, state, opts, continue_or_hibernate} when is_list(opts) ->
Copy link
Author

Choose a reason for hiding this comment

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

Not sure about the naming of continue_or_hibernate as it can also contain the timeout. Including that as well seems verbose, is there a shorter term for it?

Copy link
Member

Choose a reason for hiding this comment

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

I'd call it additional_info.

defp handle_gen_server_init_args(:hibernate, stage), do: {:ok, stage, :hibernate}

defp handle_gen_server_init_args(timeout, stage)
when (is_integer(timeout) and timeout >= 0) or timeout == :infinity,
Copy link
Author

Choose a reason for hiding this comment

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

Testing the timeout value here. Should this guard be placed elsewhere as well?

@maartenvanvliet
Copy link
Author

@josevalim could you have a look?

@acco
Copy link

acco commented Mar 15, 2024

@whatyouhide I know you reviewed the last revision - any chance you can take a look at this one? 🙏

Copy link
Member

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

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

I’m totally down for this, @josevalim?

lib/gen_stage.ex Outdated
init_producer(mod, opts, state)
init_producer(mod, opts, state, nil)

{:producer, state, opts, continue_or_hibernate} when is_list(opts) ->
Copy link
Member

Choose a reason for hiding this comment

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

I'd call it additional_info.

lib/gen_stage.ex Outdated Show resolved Hide resolved
@whatyouhide whatyouhide changed the title handle continue support Add support for handle_continue/2 callback Mar 18, 2024
@VasiliyS
Copy link

VasiliyS commented Sep 19, 2024

@josevalim @whatyouhide - Hi there! I was just looking for this feature to enable timer base scheduling in my GenStage producer. Is there a chance this could be approved soon?

@josevalim
Copy link
Member

I need to sit down and review it. The issue is that we need to consider all possible execution scenarios for producers, consumers, and producer_consumer, and those are not trivial. So I need to be in the proper headspace and other tasks take priority at the moment. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants