Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04e407b

Browse files
author
Ryan Levick
committed
Give more of an explanation of processes
1 parent 3d2ece0 commit 04e407b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

getting_started/11.markdown

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ guide: 11
66

77
# {{ page.title }}
88

9-
In Elixir, all of your code run inside processes. Those processes are isolated from each other and they communicate with message passing. In this chapter, we will learn about the basic constructs for spawning new processes, sending and receiving messages.
9+
In Elixir, all code runs inside processes. Processes are isolated from each other, run concurrent to one another and communicate via message passing. Processes are not only the basis for concurrency in Elixir, but they also provide the means for building distributed and highly fault-tolerant programs.
10+
11+
Processes are extremely lightweight in terms of memory and CPU (unlike threads in many other programming languages). Because of this, it is not uncommon to have thousands of processes running simultaneously.
12+
13+
In this chapter, we will learn about the basic constructs for spawning new processes, as well as sending and receiving messages between different processes.
1014

1115
## 11.1 spawn
1216

@@ -17,6 +21,8 @@ iex> spawn fn -> 1 + 2 end
1721
#PID<0.43.0>
1822
```
1923

24+
`spawn/1` takes a function which it will execute in another process.
25+
2026
Notice `spawn/1` returns a PID (process identifier). At this point, the process you spawned is very likely dead. The spawned process will execute the given function and exit after the function is done:
2127

2228
```iex
@@ -41,7 +47,7 @@ Processes get much more interesting when we are able to send and receive message
4147

4248
## 11.2 send and receive
4349

44-
We can send messages with `send/2` and receive them with `receive/1`:
50+
We can send messages to a process with `send/2` and receive them with `receive/1`:
4551

4652
```iex
4753
iex> send self(), {:hello, "world"}

0 commit comments

Comments
 (0)