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
    %% ====================================================================


  • 相关阅读:
    Extension Method[下篇]
    Extension Method[上篇]
    科大讯飞和Tizen-TTS语音合成引擎
    c语言中格式化输出函数的研究
    五脏积毒的表现 脸上长痘位置看你健康情况
    Android API Level与sdk版本对照表
    ffmpeg ffprobe ffplay
    sqlite 修改表名,合并数据库(文件)
    Spring配置文件的加载,及装载多个beans.xml文件
    ffmpeg 的tutorial
  • 原文地址:https://www.cnblogs.com/ribavnu/p/3409330.html
Copyright © 2011-2022 走看看