zoukankan      html  css  js  c++  java
  • gen_server的模板

    -module(first_gen_server).
    -behaviour(gen_server).
    -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

    %% ====================================================================
    %% API functions
    %% ====================================================================
    -export([]).



    %% ====================================================================
    %% Behavioural functions
    %% ====================================================================
    -record(state, {}).

    %% init/1
    %% ====================================================================
    %% @doc <a href="http://www.erlang.org/doc/man/gen_server.html#Module:init-1">gen_server:init/1</a>
    -spec init(Args :: term()) -> Result when
        Result :: {ok, State}
                | {ok, State, Timeout}
                | {ok, State, hibernate}
                | {stop, Reason :: term()}
                | ignore,
        State :: term(),
        Timeout :: non_neg_integer() | infinity.
    %% ====================================================================
    init([]) ->
        {ok, #state{}}.


    %% handle_call/3
    %% ====================================================================
    %% @doc <a href="http://www.erlang.org/doc/man/gen_server.html#Module:handle_call-3">gen_server:handle_call/3</a>
    -spec handle_call(Request :: term(), From :: {pid(), Tag :: term()}, State :: term()) -> Result when
        Result :: {reply, Reply, NewState}
                | {reply, Reply, NewState, Timeout}
                | {reply, Reply, NewState, hibernate}
                | {noreply, NewState}
                | {noreply, NewState, Timeout}
                | {noreply, NewState, hibernate}
                | {stop, Reason, Reply, NewState}
                | {stop, Reason, NewState},
        Reply :: term(),
        NewState :: term(),
        Timeout :: non_neg_integer() | infinity,
        Reason :: term().
    %% ====================================================================
    handle_call(Request, From, State) ->
        Reply = ok,
        {reply, Reply, State}.


    %% handle_cast/2
    %% ====================================================================
    %% @doc <a href="http://www.erlang.org/doc/man/gen_server.html#Module:handle_cast-2">gen_server:handle_cast/2</a>
    -spec handle_cast(Request :: term(), State :: term()) -> Result when
        Result :: {noreply, NewState}
                | {noreply, NewState, Timeout}
                | {noreply, NewState, hibernate}
                | {stop, Reason :: term(), NewState},
        NewState :: term(),
        Timeout :: non_neg_integer() | infinity.
    %% ====================================================================
    handle_cast(Msg, State) ->
        {noreply, State}.


    %% handle_info/2
    %% ====================================================================
    %% @doc <a href="http://www.erlang.org/doc/man/gen_server.html#Module:handle_info-2">gen_server:handle_info/2</a>
    -spec handle_info(Info :: timeout | term(), State :: term()) -> Result when
        Result :: {noreply, NewState}
                | {noreply, NewState, Timeout}
                | {noreply, NewState, hibernate}
                | {stop, Reason :: term(), NewState},
        NewState :: term(),
        Timeout :: non_neg_integer() | infinity.
    %% ====================================================================
    handle_info(Info, State) ->
        {noreply, State}.


    %% terminate/2
    %% ====================================================================
    %% @doc <a href="http://www.erlang.org/doc/man/gen_server.html#Module:terminate-2">gen_server:terminate/2</a>
    -spec terminate(Reason, State :: term()) -> Any :: term() when
        Reason :: normal
                | shutdown
                | {shutdown, term()}
                | term().
    %% ====================================================================
    terminate(Reason, State) ->
        ok.


    %% code_change/3
    %% ====================================================================
    %% @doc <a href="http://www.erlang.org/doc/man/gen_server.html#Module:code_change-3">gen_server:code_change/3</a>
    -spec code_change(OldVsn, State :: term(), Extra :: term()) -> Result when
        Result :: {ok, NewState :: term()} | {error, Reason :: term()},
        OldVsn :: Vsn | {down, Vsn},
        Vsn :: term().
    %% ====================================================================
    code_change(OldVsn, State, Extra) ->
        {ok, State}.


    %% ====================================================================
    %% Internal functions
    %% ====================================================================


  • 相关阅读:
    Android深度探索--第三章读后感
    Android深度探索--第二章读后感
    Android深度探索--第一章读后感
    android深度探索第十章心得体会
    android深度探索第九章心得体会
    android深度探索第八章心得体会
    深度探索android第七章
    Android 深度探索第六章
    深度探索android第五章
    Android深度探索第四章读后感
  • 原文地址:https://www.cnblogs.com/ribavnu/p/3409330.html
Copyright © 2011-2022 走看看