@@ -14,20 +14,56 @@ therefore they will be able to reuse their knowledge in Ruby.
14
14
15
15
## Erlang actors
16
16
17
- The actor implementation matches the Erlang's implementation.
18
- Mainly it has the same:
19
- * exit behavior (called termination in Ruby to avoid collision with ` Kernel#exit ` ),
20
- * ability to link and monitor actors,
21
- * ability to have much more actors then threads,
22
- * ordering guarantees between messages and signals,
23
- * message receiving features.
17
+ The actor implementation matches the Erlang's implementation.
18
+ Mainly:
19
+
20
+ * The ` exit/1 ` and ` exit/2 `
21
+ functions are reimplemented with the same arguments and effects.
22
+ Even though the methods are named ` terminate ` to avoid collision with ` Kernel#exit ` .r
23
+ This re-implementation adds that the termination event not only sends signals to linked actors
24
+ but it is represented as a Future
25
+ which is fulfilled with the final value of the actor or rejected with the reason of abnormal termination.
26
+
27
+ * The linking and monitoring between actors (called processes in Erlang) is re-implemented.
28
+ Functions ` link ` , ` unlink ` , ` spawn_link ` , ` monitor ` , ` demonitor ` , ` spawn_monitor `
29
+ have equivalent counterparts
30
+ ` link ` , ` unlink ` , ` spawn link:true ` , ` monitor ` , ` demonitor ` , ` spawn monitor: true ` .
31
+ All the options applicable in this implementation are supported,
32
+ they effects are the same
33
+ and the ordering of signal and messages is the same as on Erlang.
34
+
35
+ * This implementation has two functionally equivalent types of actors
36
+ ` spawn type: on_thread, ... ` and ` spawn type: on_pool, ... ` .
37
+ They differ in the execution mode.
38
+ First requires its own thread second runs on shared thread pool
39
+ therefore allowing to have millions of short or long lived actors if required.
40
+
41
+ * Message and signal ordering of messages between two actors has same guarantee as in Erlang.
42
+ Messages and signals from A are always received by B in the order they were send.
43
+ (Signals are internal messages produced by methods like ` link ` .)
44
+ The ordering guarantee does not scale up to more than 2 actors in Erlang nor in this implementation.
45
+
46
+ * Even though Ruby does not have pattern matching, this implementation provides ` receive `
47
+ which is functionally equivalent.
48
+ (It is sometimes more cumbersome to use though.)
49
+
50
+ Exit behaviour, linking, and monitoring is very well described by
51
+ [ the chapter of the book "learn you some Erlang"] ( https://learnyousomeerlang.com/errors-and-processes ) .
52
+ This implementation matches the behaviours described there.
53
+
54
+ Erlang method documentation can be found at
55
+ < http://erlang.org/documentation/doc-10.3/erts-10.3/doc/html/erlang.html > .
56
+
57
+ ### Actor execution modes - types
24
58
25
59
The actors can be written in 2 modes. First will require it's own thread,
26
60
second will run on a thread pool.
27
61
Please see
28
62
[ Actor types section] ( http://blog.pitr.ch/concurrent-ruby/master/Concurrent/ErlangActor.html )
29
63
for more details.
30
64
65
+ ### Ordering
66
+
31
67
Especially ordering guarantees are not easy to get correct.
32
68
As an example lets have a look at the reasoning behind implementation of monitoring.
33
69
Understanding of the monitors in Erlang actors is necessary for the following part.
0 commit comments