diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-09 21:02:57 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-09 21:02:57 +0100 |
commit | 293916c8f4dc109082ecd709e5e4c19a0847b0cd (patch) | |
tree | d0178f9434e0f01b7c5b12850eceee126bc8f946 /step-04 | |
download | erlang-workshop-293916c8f4dc109082ecd709e5e4c19a0847b0cd.tar.gz erlang-workshop-293916c8f4dc109082ecd709e5e4c19a0847b0cd.tar.bz2 erlang-workshop-293916c8f4dc109082ecd709e5e4c19a0847b0cd.tar.xz erlang-workshop-293916c8f4dc109082ecd709e5e4c19a0847b0cd.zip |
wip
Diffstat (limited to 'step-04')
-rw-r--r-- | step-04/README.md | 0 | ||||
-rw-r--r-- | step-04/tut17.erl | 31 |
2 files changed, 31 insertions, 0 deletions
diff --git a/step-04/README.md b/step-04/README.md new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/step-04/README.md diff --git a/step-04/tut17.erl b/step-04/tut17.erl new file mode 100644 index 0000000..6808340 --- /dev/null +++ b/step-04/tut17.erl @@ -0,0 +1,31 @@ +-module(tut17). + +-export([start_ping/1, start_pong/0, ping/2, pong/0]). + +ping(0, Pong_Node) -> + {pong, Pong_Node} ! finished, + io:format("ping finished~n", []); + +ping(N, Pong_Node) -> + {pong, Pong_Node} ! {ping, self()}, + receive + pong -> + io:format("Ping received pong~n", []) + end, + ping(N - 1, Pong_Node). + +pong() -> + receive + finished -> + io:format("Pong finished~n", []); + {ping, Ping_PID} -> + io:format("Pong received ping~n", []), + Ping_PID ! pong, + pong() + end. + +start_pong() -> + register(pong, spawn(tut17, pong, [])). + +start_ping(Pong_Node) -> + spawn(tut17, ping, [3, Pong_Node]). |