-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 {continue, Term} and handle_continue/2 to gen_server #1490
Conversation
handle_common_reply(Reply, Parent, Name, undefined, Msg, Mod, | ||
HibernateAfterTimeout, State); | ||
_ -> | ||
Debug1 = sys:handle_debug(Debug, fun print_event/3, Name, Msg), |
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.
@RaimoNiskanen I have chosen the debug event to be {continue, Continue}
. Is that ok? If there is an error, we will also log the last message as {continue, 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.
Looks just fine
We intend to make a decision about this PR before the next planned release but feedback loop might be a bit slower than usual during the summer so please have patience. |
The test case gen_server_incorrect_args in behaviour_SUITE in dialyzer fails with your branch:
|
d3aae62
to
5fbc435
Compare
@IngelaAndin fixed and force pushed, thanks! |
Sorry about the delay, but another test case fails and I did not see that until now. It is a white box test case in |
@RaimoNiskanen no worries! I will gladly look into it later today. |
5fbc435
to
54dae81
Compare
@RaimoNiskanen fixed and force pushed. I re-ran the stdlib_SUITE here too and everything looks good locally. |
On one of our challenged machines this fails: FROZ
FROZ
FROZ
*** CT Error Notification 2017-07-31 23:36:54.881 ***
gen_server_SUITE:continue failed on line 485
=== Ended at 2017-07-31 23:36:54
=== Location: [{gen_server_SUITE,continue,485},
{test_server,ts_tc,1529},
{test_server,run_test_case_eval1,1045},
{test_server,run_test_case_eval,977}]
=== Reason: no match of right hand side value
[{<0.4970.4>,before_continue},{<0.4970.4>,continue}]
in function gen_server_SUITE:continue/1 (gen_server_SUITE.erl, line 485)
in call from test_server:ts_tc/3 (test_server.erl, line 1529)
in call from test_server:run_test_case_eval1/6 (test_server.erl, line 1045)
in call from test_server:run_test_case_eval/9 (test_server.erl, line 977) I'd say it is because the tested server bangs I do not understand what the Note that message ordering is only guaranteed to be preserved between pairs of processes, so a message to |
If the gen_server process needs to perform an action immediately after initialization or to break the execution of a callback into multiple steps, it can return {continue, term()} in place of the time-out or hibernation value, which will immediately invoke the handle_continue/2 callback with the given term. This provides a more accessible approach to after initialization compared to proc_lib+enter_loop that is also guaranteed to be safe. It also allows callbacks that need to do lengthy or stateful work to checkpoint the state throughout multiple iterations. This can be useful, for example, when implementing behaviours on top of gen_server.
54dae81
to
69e009e
Compare
I see the race condition. gen_server:call(started_p) is invoked before the process sends the after_continue message to itself. I have changed the tests to no longer rely on |
Adds GenServer support for handle_continue (https://www.erlang.org/doc/apps/stdlib/gen_server.html#c:handle_continue/2), tests are carbon copy from upstream test suite https://github.com/erlang/otp/blob/141120ab9de7e6069ee45280dc7f6a251f89e081/lib/stdlib/test/gen_server_SUITE.erl#L1012 Added to otp back in 2017: erlang/otp#1490 - often used in elixir land. Signed-off-by: Peter M <petermm@gmail.com>
Adds GenServer support for handle_continue (https://www.erlang.org/doc/apps/stdlib/gen_server.html#c:handle_continue/2), tests are carbon copy from upstream test suite https://github.com/erlang/otp/blob/141120ab9de7e6069ee45280dc7f6a251f89e081/lib/stdlib/test/gen_server_SUITE.erl#L1012 Added to otp back in 2017: erlang/otp#1490 - often used in elixir land. Signed-off-by: Peter M <petermm@gmail.com>
Adds GenServer support for handle_continue (https://www.erlang.org/doc/apps/stdlib/gen_server.html#c:handle_continue/2), tests are carbon copy from upstream test suite https://github.com/erlang/otp/blob/141120ab9de7e6069ee45280dc7f6a251f89e081/lib/stdlib/test/gen_server_SUITE.erl#L1012 Added to otp back in 2017: erlang/otp#1490 - often used in elixir land. Signed-off-by: Peter M <petermm@gmail.com>
Support handle_continue in gen_server.erl Adds gen_server support for handle_continue (https://www.erlang.org/doc/apps/stdlib/gen_server.html#c:handle_continue/2), tests are carbon copy from upstream test suite https://github.com/erlang/otp/blob/141120ab9de7e6069ee45280dc7f6a251f89e081/lib/stdlib/test/gen_server_SUITE.erl#L1012 Added to otp back in 2017: erlang/otp#1490 - often used in elixir land. These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
If the gen_server process needs to perform an action immediately
after initialization or to break the execution of a callback into
multiple steps, it can return {continue, term()} in place of the
time-out or hibernation value, which will immediately invoke the
handle_continue/2 callback with the given term.
This provides a more accessible approach to after initialization
compared to proc_lib+enter_loop that is also guaranteed to be
safe.
It also allows callbacks that need to do lengthy or stateful work
to checkpoint the state throughout multiple iterations. This can
be useful, for example, when implementing behaviours on top of
gen_server.
This is continuation of PR #1429.