aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test/gen_server_SUITE_data
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2017-06-22 19:54:26 +0200
committerJosé Valim <[email protected]>2017-08-05 18:58:52 +0200
commit69e009e3e1ad899a4609ff327a08512c86dba374 (patch)
treec4a431d3c7c7f8b8e02de0fe1ceb8028c61b56df /lib/stdlib/test/gen_server_SUITE_data
parentf52748254f17ba42e344798e8c787a1e3361fa33 (diff)
downloadotp-69e009e3e1ad899a4609ff327a08512c86dba374.tar.gz
otp-69e009e3e1ad899a4609ff327a08512c86dba374.tar.bz2
otp-69e009e3e1ad899a4609ff327a08512c86dba374.zip
Add {continue, Term} and handle_continue/2 to gen_server
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.
Diffstat (limited to 'lib/stdlib/test/gen_server_SUITE_data')
-rw-r--r--lib/stdlib/test/gen_server_SUITE_data/oc_server.erl12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/stdlib/test/gen_server_SUITE_data/oc_server.erl b/lib/stdlib/test/gen_server_SUITE_data/oc_server.erl
index 4ba37987f3..7b92a49bf6 100644
--- a/lib/stdlib/test/gen_server_SUITE_data/oc_server.erl
+++ b/lib/stdlib/test/gen_server_SUITE_data/oc_server.erl
@@ -22,7 +22,7 @@
-behaviour(gen_server).
%% API
--export([start/0]).
+-export([start/0, start/1]).
%% gen_server callbacks
-export([init/1]).
@@ -30,8 +30,12 @@
-record(state, {}).
start() ->
- gen_server:start({local, ?MODULE}, ?MODULE, [], []).
+ gen_server:start(?MODULE, ok, []).
-init([]) ->
- {ok, #state{}}.
+start(continue) ->
+ gen_server:start(?MODULE, continue, []).
+init(ok) ->
+ {ok, #state{}};
+init(continue) ->
+ {ok, #state{}, {continue, continue}}.