This commit is contained in:
Timofey Khoruzhii 2023-04-17 11:43:58 +03:00
commit 8293234a24
5 changed files with 107 additions and 0 deletions

4
.formatter.exs Normal file
View file

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

26
.gitignore vendored Normal file
View file

@ -0,0 +1,26 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where third-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
process_communication-*.tar
# Temporary files, for example, from tests.
/tmp/

13
README.md Normal file
View file

@ -0,0 +1,13 @@
# Для запуска
```bash
mix run -e "ProcessCommunication.run()"
```
# Вывод
```text
info 7
cast 17
call 31
Rusult: 55
```

View file

@ -0,0 +1,36 @@
defmodule Child do
def start_link do
GenServer.start_link(__MODULE__, [])
end
def init(_args) do
{:ok, 0}
end
def handle_info({:info, n}, state) do
IO.puts "info #{n}"
{:noreply, state + n}
end
def handle_cast({:cast, n}, state) do
IO.puts "cast #{n}"
{:noreply, state + n}
end
def handle_call({:call, n}, _from, state) do
IO.puts "call #{n}"
{:reply, state + n, state + n}
end
end
defmodule ProcessCommunication do
def run do
{:ok, child} = Child.start_link()
send(child, {:info, 7})
GenServer.cast(child, {:cast, 17})
result = GenServer.call(child, {:call, 31})
IO.puts "Rusult: #{result}"
end
end

28
mix.exs Normal file
View file

@ -0,0 +1,28 @@
defmodule ProcessCommunication.MixProject do
use Mix.Project
def project do
[
app: :process_communication,
version: "0.1.0",
elixir: "~> 1.14",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end