commit 8293234a24dc41f765eddc5f2a3a0e435a36182d Author: Timofey Khoruzhii Date: Mon Apr 17 11:43:58 2023 +0300 init diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2afbab9 --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b572c4 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Для запуска + +```bash +mix run -e "ProcessCommunication.run()" +``` + +# Вывод +```text +info 7 +cast 17 +call 31 +Rusult: 55 +``` diff --git a/lib/process_communication.ex b/lib/process_communication.ex new file mode 100644 index 0000000..f20037d --- /dev/null +++ b/lib/process_communication.ex @@ -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 diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..ffb5819 --- /dev/null +++ b/mix.exs @@ -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