How to send a message to receive in YAWS / Erlang

Typically, Erlang programmers use a character !to send a message for reception in parallel programming, but how do we do it in yaw? Let's say I'm trying to do this>

<erl>
out(Arg) -> loop("bad").


loop(X)->
    receive
        good -> {html, "Good"};
        bad  -> {html, "bad"}
    end.
</erl>

This program continues to wait for a message, how do I send a message?

+3
source share
1 answer

, , , . Yaws HTTP-, Erlang. .yaws, , out/1. , .

. spawn_link , loop/1:

<erl>
    out(_Arg) ->
        process_flag(trap_exit, true),
        Self = self(),
        Pid = spawn_link(fun() -> my_business_logic(Self) end),
        loop(Pid).

    loop(Pid) ->
        receive
            {Pid, good} -> {html, "Good"};
            {Pid, bad} -> {html, "Bad"};
            {'EXIT', Pid, Reason} ->
                [{status, 500},
                 {html, "internal server error"}]
        end.

    my_business_logic(Parent) ->
        %% run your logic here, then send a message
        Parent ! {self(), good}.
</erl>

, Pid , , . , , , , EXIT .

. HTTP-, , Erlang , out/1 , . , , , .

.yaws , . Erlang, Yaws , appmod Yaws, Yaws , Erlang. , Yaws Yaws.

+2

All Articles