【问题标题】:Ejabberd erlang and async taskEjabberd erlang和异步任务
【发布时间】:2017-09-20 09:25:04
【问题描述】:

在 ejabberd 模块中我使用这种方法:

httpc:request(post, {Url, Header

似乎不是异步的,erlang有没有办法在单独的线程上启动它???

【问题讨论】:

    标签: erlang ejabberd ejabberd-module


    【解决方案1】:

    我用过这个:

        spawn(mod_http_offline, http_request, [Url, Post]).
    
        % Function that make a call
        http_request(Url, Post)->
          TypeData = "application/x-www-form-urlencoded",
          Header = [],
          HTTPOptions = [],
          Options = [],
          httpc:request(post, {Url, Header, TypeData,list_to_binary(Post)}, HTTPOptions, Options).
    

    但是当我编译时,得到这个:

    Warning: function http_request/2 is unused

    并且函数没有被调用

    【讨论】:

    【解决方案2】:
    Sample method-
    // module name - sample
    http_request(Method,Url,Body)->
    httpc:request(Method, {Url, [], "application/x-www-form-urlencoded", Body}, [], []).
    

    你会这样打电话的-

     spawn(sample, http_request, [post,”www.sample.com”,”some sample data”]). 
     %% syntax spawn(Module, Name, Args) -> pid()
    

    http://erlang.org/doc/getting_started/conc_prog.html http://erlang.org/doc/reference_manual/processes.html

    【讨论】:

    • 查看我对警告的回复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多