-
Notifications
You must be signed in to change notification settings - Fork 193
Support for handle_continue #234
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
Conversation
@@ -882,11 +882,17 @@ defmodule GenStage do | |||
|
|||
@callback init(args :: term) :: | |||
{:producer, state} | |||
| {:producer, state, :hibernate | {:continue, term}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current PR doesn't handle hiberrnate, does it? In any case, there are other discussions we need to have regarding hibernate, so probably better to focus on continue for now. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but the existing documentation for the init function mentions hibernate, which confused me. I'll remove the hibernate reference from the docs (around lines 833-835) and from this callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the hibernate reference from the docs (around lines 833-835) and from this callback.
Fantastic, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, actually, the handle_info
callback (and the others) also contains :hibernate
. I guess that was a copy paste from the GenServer docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Actually we do support hibernate there but not on init
. So I guess we crossed this line anyway. So I would go ahead and support it on init
too!
lib/gen_stage.ex
Outdated
@@ -1726,7 +1770,7 @@ defmodule GenStage do | |||
end | |||
end | |||
|
|||
defp init_producer(mod, opts, state) do | |||
defp init_producer(mod, opts, state, continue \\ :no_continue) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like to use default arguments to private functions. We can directly pass :no_continue
when calling this function. :)
Looks great, can you please add some tests too? Thanks! |
I'd love to, but would welcome some pointers regarding why the current tests fail:
If I only update producers to handle continue in the init, all is well, but also updating the consumers and producer-consumers to handle continue in the init, the tests fail. I suspect it has something to do with subscriptions. |
So this failure is likely that a timeout value different from an integer or
infinity is being given to “after” in a receive or or Process.send_after or
similar.
--
*José Valimwww.plataformatec.com.br
<http://www.plataformatec.com.br/>Founder and Director of R&D*
|
lib/gen_stage.ex
Outdated
@@ -2407,7 +2407,7 @@ defmodule GenStage do | |||
|
|||
## Consumer helpers | |||
|
|||
defp consumer_init_subscribe(producers, stage, continue) do | |||
defp consumer_init_subscribe(producers, stage, continue_or_hibernate) do | |||
fold_fun = fn | |||
to, {:ok, stage, :no_continue} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this clause if we have a case at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I'll remove it.
lib/gen_stage.ex
Outdated
:lists.foldl(fold_fun, {:ok, stage, continue_or_hibernate}, producers) | ||
|> case do | ||
{:ok, stage, :no_continue} -> {:ok, stage} | ||
{:ok, stage, continue_or_hibernate} -> {:ok, stage, continue_or_hibernate} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this clause either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the otherwise
is enough. Will chang.e
Looks good, I have added some comments. Next step is to add some tests too. :) |
Thanks. I think there is still some functionality missing though. Currently, I only handle continue as returned from the init. I should probably handle continue as returned from the other callback implementations as well. |
I have just realized something. Today, if you return |
I think I understand what you mean. I'll see if I can figure out what needs
to change.
…On Mon, 27 May 2019 at 12:40, José Valim ***@***.***> wrote:
I have just realized something. Today, if you return subscribe_to in your
init callback, handle_subscribe would be called BEFORE the handle_continue,
and it probably should be called after. I think that, instead of return {:continue,
...} and let the underlying GenServer take care of it, we should probably
handle and call continue ourselves, as we need to do before
handle_subscribe.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#234?email_source=notifications&email_token=AAXFLZOKTHDBSPBSP6JM3WTPXO3C3A5CNFSM4HNPHOWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWJO45I#issuecomment-496168565>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAXFLZNT2D3CQRZQ4XIMM63PXO3C3ANCNFSM4HNPHOWA>
.
|
Ping! |
Pong! I'm still intending to get this done.
…On Mon, 15 Jul 2019, 1:31 PM José Valim, ***@***.***> wrote:
Ping!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#234?email_source=notifications&email_token=AAXFLZLC2SZBYJKVCUW4SELP7RNZDA5CNFSM4HNPHOWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ5NHMI#issuecomment-511366065>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAXFLZNU7KM34DFWZWPCVDTP7RNZDANCNFSM4HNPHOWA>
.
|
Hi @palm86, it seems we both got busy with other things, so I will go ahead and close this for now. If you still have an interest on this feature, we will gladly reopen it. Thanks! |
This tries so address issue #227. But I need some help to figure it out. I've done what seems necesary to me, but many tests fail with a timeout now and I haven't given any though to additional tests yet.