考虑以下Erlang代码:
-module(testit). -export([testit/0]). testit() -> Pid = spawn(fun testit_proc/0),Pid ! final,Pid ! one,Pid ! two,io:format("Root finished~n"). testit_proc() -> receive one -> io:format("One~n"); two -> io:format("Two~n") end,receive one -> io:format("One~n"); two -> io:format("Two~n") end,receive one -> io:format("One~n"); two -> io:format("Two~n"); final -> io:format("Final~n") end,io:format("Spawn finished~n").
输出为:
Root finished One Two Final Spawn finished
最终消息的处理基本上延迟到最后接收块之前,因为先前的接收模式不匹配该消息.
你怎么用Haskell的TChan这样做?