eventmachine 0.12.10-x86-mswin32-60 → 1.0.0.beta.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/README +80 -81
- data/Rakefile +7 -370
- data/docs/COPYING +60 -60
- data/docs/ChangeLog +211 -211
- data/docs/DEFERRABLES +246 -133
- data/docs/EPOLL +141 -141
- data/docs/GNU +281 -281
- data/docs/INSTALL +13 -13
- data/docs/KEYBOARD +42 -38
- data/docs/LEGAL +25 -25
- data/docs/LIGHTWEIGHT_CONCURRENCY +130 -70
- data/docs/PURE_RUBY +75 -75
- data/docs/RELEASE_NOTES +94 -94
- data/docs/SMTP +4 -2
- data/docs/SPAWNED_PROCESSES +148 -89
- data/docs/TODO +8 -8
- data/eventmachine.gemspec +19 -26
- data/examples/ex_channel.rb +42 -42
- data/examples/ex_queue.rb +2 -2
- data/examples/ex_tick_loop_array.rb +15 -0
- data/examples/ex_tick_loop_counter.rb +32 -0
- data/examples/helper.rb +1 -1
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +36 -25
- data/ext/ed.cpp +104 -113
- data/ext/ed.h +24 -30
- data/ext/em.cpp +349 -283
- data/ext/em.h +25 -29
- data/ext/eventmachine.h +5 -4
- data/ext/extconf.rb +58 -49
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +214 -214
- data/ext/fastfilereader/mapper.h +59 -59
- data/ext/fastfilereader/rubymain.cpp +127 -127
- data/ext/kb.cpp +1 -3
- data/ext/page.cpp +107 -107
- data/ext/page.h +51 -51
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +138 -104
- data/java/.classpath +8 -8
- data/java/.project +17 -17
- data/java/src/com/rubyeventmachine/EmReactor.java +1 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -40
- data/lib/em/buftok.rb +138 -138
- data/lib/em/callback.rb +25 -25
- data/lib/em/channel.rb +1 -1
- data/lib/em/connection.rb +6 -1
- data/lib/em/deferrable.rb +16 -2
- data/lib/em/file_watch.rb +53 -53
- data/lib/em/future.rb +61 -61
- data/lib/em/iterator.rb +270 -0
- data/lib/em/messages.rb +66 -66
- data/lib/em/process_watch.rb +43 -43
- data/lib/em/protocols.rb +1 -1
- data/lib/em/protocols/header_and_content.rb +138 -138
- data/lib/em/protocols/httpclient.rb +267 -262
- data/lib/em/protocols/line_protocol.rb +28 -0
- data/lib/em/protocols/memcache.rb +322 -322
- data/lib/em/protocols/postgres3.rb +247 -247
- data/lib/em/protocols/saslauth.rb +175 -175
- data/lib/em/protocols/smtpserver.rb +640 -547
- data/lib/em/protocols/stomp.rb +200 -200
- data/lib/em/protocols/tcptest.rb +52 -52
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +1013 -1022
- data/lib/em/queue.rb +1 -0
- data/lib/em/spawnable.rb +85 -85
- data/lib/em/streamer.rb +130 -130
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +2 -1
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +40 -84
- data/lib/jeventmachine.rb +2 -1
- data/lib/rubyeventmachine.rb +2 -0
- data/setup.rb +1585 -1585
- data/tasks/doc.rake +30 -0
- data/tasks/package.rake +85 -0
- data/tasks/test.rake +6 -0
- data/tests/client.crt +31 -31
- data/tests/client.key +51 -51
- data/tests/test_attach.rb +13 -3
- data/tests/test_basic.rb +60 -95
- data/tests/test_channel.rb +3 -2
- data/tests/test_defer.rb +49 -47
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_error_handler.rb +35 -35
- data/tests/test_errors.rb +82 -82
- data/tests/test_exc.rb +55 -55
- data/tests/test_file_watch.rb +49 -49
- data/tests/test_futures.rb +198 -198
- data/tests/test_handler_check.rb +36 -36
- data/tests/test_hc.rb +190 -218
- data/tests/test_httpclient.rb +227 -218
- data/tests/test_httpclient2.rb +3 -2
- data/tests/test_inactivity_timeout.rb +3 -3
- data/tests/test_kb.rb +60 -60
- data/tests/test_ltp.rb +13 -5
- data/tests/test_ltp2.rb +317 -317
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_object_protocol.rb +36 -36
- data/tests/test_pending_connect_timeout.rb +2 -2
- data/tests/test_process_watch.rb +50 -48
- data/tests/test_proxy_connection.rb +52 -0
- data/tests/test_pure.rb +134 -125
- data/tests/test_queue.rb +44 -44
- data/tests/test_running.rb +42 -42
- data/tests/test_sasl.rb +72 -72
- data/tests/test_send_file.rb +251 -242
- data/tests/test_servers.rb +76 -76
- data/tests/test_smtpclient.rb +83 -83
- data/tests/test_smtpserver.rb +85 -85
- data/tests/test_spawn.rb +322 -322
- data/tests/test_ssl_methods.rb +49 -49
- data/tests/test_ssl_verify.rb +82 -82
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +13 -15
- data/tests/test_ud.rb +36 -36
- data/tests/testem.rb +31 -31
- metadata +66 -51
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma.rb +0 -32
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/web/whatis +0 -7
data/docs/RELEASE_NOTES
CHANGED
@@ -1,94 +1,94 @@
|
|
1
|
-
RUBY/EventMachine RELEASE NOTES
|
2
|
-
|
3
|
-
--------------------------------------------------
|
4
|
-
Version: 0.9.0, released xxXXX07
|
5
|
-
Added Erlang-like distributed-computing features
|
6
|
-
|
7
|
-
--------------------------------------------------
|
8
|
-
Version: 0.8.0, released 23Jun07
|
9
|
-
Added an epoll implementation for Linux 2.6 kernels.
|
10
|
-
Added evented #popen.
|
11
|
-
|
12
|
-
--------------------------------------------------
|
13
|
-
Version: 0.7.3, released 22May07
|
14
|
-
Added a large variety of small features. See the ChangeLog.
|
15
|
-
|
16
|
-
--------------------------------------------------
|
17
|
-
Version: 0.7.1, released xxNov06
|
18
|
-
Added protocol handlers for line-oriented protocols.
|
19
|
-
Various bug fixes.
|
20
|
-
|
21
|
-
--------------------------------------------------
|
22
|
-
Version: 0.7.0, released 20Nov06
|
23
|
-
Added a fix in em.cpp/ConnectToServer to fix a fatal exception that
|
24
|
-
occurred in FreeBSD when connecting successfully to a remote server.
|
25
|
-
|
26
|
-
--------------------------------------------------
|
27
|
-
Version: 0.6.0, released xxJul06
|
28
|
-
Added deferred operations, suggested by Don Stocks, amillionhitpoints@yahoo.com.
|
29
|
-
|
30
|
-
--------------------------------------------------
|
31
|
-
Version: 0.5.4, released xxJun06
|
32
|
-
Added get_peername support for streams and datagrams.
|
33
|
-
|
34
|
-
--------------------------------------------------
|
35
|
-
Version: 0.5.3, released 17May06
|
36
|
-
Fixed bugs in extconf.rb, thanks to Daniel Harple, dharple@generalconsumption.org.
|
37
|
-
Added proper setup.rb and rake tasks, thanks to Austin Ziegler.
|
38
|
-
Fixed a handful of reported problems with builds on various platforms.
|
39
|
-
|
40
|
-
--------------------------------------------------
|
41
|
-
Version: 0.5.2, released 05May06
|
42
|
-
Made several nonvisible improvements to the Windows
|
43
|
-
implementation.
|
44
|
-
Added an exception-handling patch contributed by Jeff Rose, jeff@rosejn.net.
|
45
|
-
Added a dir-config patch contributed anonymously.
|
46
|
-
Supported builds on Solaris.
|
47
|
-
|
48
|
-
--------------------------------------------------
|
49
|
-
Version: 0.5.1, released 05May06
|
50
|
-
Made it possible to pass a Class rather than a Module
|
51
|
-
to a protocol handler.
|
52
|
-
Added Windows port.
|
53
|
-
|
54
|
-
--------------------------------------------------
|
55
|
-
Version: 0.5.0, released 30Apr06
|
56
|
-
Added a preliminary SSL/TLS extension. This will probably
|
57
|
-
change over the next few releases.
|
58
|
-
|
59
|
-
--------------------------------------------------
|
60
|
-
Version: 0.4.5, released 29Apr06
|
61
|
-
Changed ext files so the ruby.h is installed after unistd.h
|
62
|
-
otherwise it doesn't compile on gcc 4.1
|
63
|
-
|
64
|
-
--------------------------------------------------
|
65
|
-
Version: 0.4.2, released 19Apr06
|
66
|
-
Changed the Ruby-glue so the extension will play nicer
|
67
|
-
in the sandbox with Ruby threads.
|
68
|
-
Added an EventMachine::run_without_threads API to
|
69
|
-
switch off the thread-awareness for better performance
|
70
|
-
in programs that do not spin any Ruby threads.
|
71
|
-
|
72
|
-
--------------------------------------------------
|
73
|
-
Version: 0.4.1, released 15Apr06
|
74
|
-
Reworked the shared-object interface to make it easier to
|
75
|
-
use EventMachine from languages other than Ruby.
|
76
|
-
|
77
|
-
--------------------------------------------------
|
78
|
-
Version: 0.3.2, released 12Apr06
|
79
|
-
Added support for a user-supplied block in EventMachine#connect.
|
80
|
-
|
81
|
-
--------------------------------------------------
|
82
|
-
Version: 0.3.1, released 11Apr06
|
83
|
-
Fixed bug that prevented EventMachine from being run multiple
|
84
|
-
times in a single process.
|
85
|
-
|
86
|
-
--------------------------------------------------
|
87
|
-
Version: 0.3.0, released 10Apr06
|
88
|
-
Added method EventHandler::Connection::post_init
|
89
|
-
|
90
|
-
--------------------------------------------------
|
91
|
-
Version: 0.2.0, released 10Apr06
|
92
|
-
Added method EventHandler::stop
|
93
|
-
|
94
|
-
|
1
|
+
RUBY/EventMachine RELEASE NOTES
|
2
|
+
|
3
|
+
--------------------------------------------------
|
4
|
+
Version: 0.9.0, released xxXXX07
|
5
|
+
Added Erlang-like distributed-computing features
|
6
|
+
|
7
|
+
--------------------------------------------------
|
8
|
+
Version: 0.8.0, released 23Jun07
|
9
|
+
Added an epoll implementation for Linux 2.6 kernels.
|
10
|
+
Added evented #popen.
|
11
|
+
|
12
|
+
--------------------------------------------------
|
13
|
+
Version: 0.7.3, released 22May07
|
14
|
+
Added a large variety of small features. See the ChangeLog.
|
15
|
+
|
16
|
+
--------------------------------------------------
|
17
|
+
Version: 0.7.1, released xxNov06
|
18
|
+
Added protocol handlers for line-oriented protocols.
|
19
|
+
Various bug fixes.
|
20
|
+
|
21
|
+
--------------------------------------------------
|
22
|
+
Version: 0.7.0, released 20Nov06
|
23
|
+
Added a fix in em.cpp/ConnectToServer to fix a fatal exception that
|
24
|
+
occurred in FreeBSD when connecting successfully to a remote server.
|
25
|
+
|
26
|
+
--------------------------------------------------
|
27
|
+
Version: 0.6.0, released xxJul06
|
28
|
+
Added deferred operations, suggested by Don Stocks, amillionhitpoints@yahoo.com.
|
29
|
+
|
30
|
+
--------------------------------------------------
|
31
|
+
Version: 0.5.4, released xxJun06
|
32
|
+
Added get_peername support for streams and datagrams.
|
33
|
+
|
34
|
+
--------------------------------------------------
|
35
|
+
Version: 0.5.3, released 17May06
|
36
|
+
Fixed bugs in extconf.rb, thanks to Daniel Harple, dharple@generalconsumption.org.
|
37
|
+
Added proper setup.rb and rake tasks, thanks to Austin Ziegler.
|
38
|
+
Fixed a handful of reported problems with builds on various platforms.
|
39
|
+
|
40
|
+
--------------------------------------------------
|
41
|
+
Version: 0.5.2, released 05May06
|
42
|
+
Made several nonvisible improvements to the Windows
|
43
|
+
implementation.
|
44
|
+
Added an exception-handling patch contributed by Jeff Rose, jeff@rosejn.net.
|
45
|
+
Added a dir-config patch contributed anonymously.
|
46
|
+
Supported builds on Solaris.
|
47
|
+
|
48
|
+
--------------------------------------------------
|
49
|
+
Version: 0.5.1, released 05May06
|
50
|
+
Made it possible to pass a Class rather than a Module
|
51
|
+
to a protocol handler.
|
52
|
+
Added Windows port.
|
53
|
+
|
54
|
+
--------------------------------------------------
|
55
|
+
Version: 0.5.0, released 30Apr06
|
56
|
+
Added a preliminary SSL/TLS extension. This will probably
|
57
|
+
change over the next few releases.
|
58
|
+
|
59
|
+
--------------------------------------------------
|
60
|
+
Version: 0.4.5, released 29Apr06
|
61
|
+
Changed ext files so the ruby.h is installed after unistd.h
|
62
|
+
otherwise it doesn't compile on gcc 4.1
|
63
|
+
|
64
|
+
--------------------------------------------------
|
65
|
+
Version: 0.4.2, released 19Apr06
|
66
|
+
Changed the Ruby-glue so the extension will play nicer
|
67
|
+
in the sandbox with Ruby threads.
|
68
|
+
Added an EventMachine::run_without_threads API to
|
69
|
+
switch off the thread-awareness for better performance
|
70
|
+
in programs that do not spin any Ruby threads.
|
71
|
+
|
72
|
+
--------------------------------------------------
|
73
|
+
Version: 0.4.1, released 15Apr06
|
74
|
+
Reworked the shared-object interface to make it easier to
|
75
|
+
use EventMachine from languages other than Ruby.
|
76
|
+
|
77
|
+
--------------------------------------------------
|
78
|
+
Version: 0.3.2, released 12Apr06
|
79
|
+
Added support for a user-supplied block in EventMachine#connect.
|
80
|
+
|
81
|
+
--------------------------------------------------
|
82
|
+
Version: 0.3.1, released 11Apr06
|
83
|
+
Fixed bug that prevented EventMachine from being run multiple
|
84
|
+
times in a single process.
|
85
|
+
|
86
|
+
--------------------------------------------------
|
87
|
+
Version: 0.3.0, released 10Apr06
|
88
|
+
Added method EventHandler::Connection::post_init
|
89
|
+
|
90
|
+
--------------------------------------------------
|
91
|
+
Version: 0.2.0, released 10Apr06
|
92
|
+
Added method EventHandler::stop
|
93
|
+
|
94
|
+
|
data/docs/SMTP
CHANGED
@@ -1,2 +1,4 @@
|
|
1
|
-
This note details the usage of EventMachine's built-in support for SMTP. EM
|
2
|
-
|
1
|
+
This note details the usage of EventMachine's built-in support for SMTP. EM
|
2
|
+
supports both client and server connections, which will be described in
|
3
|
+
separate sections.
|
4
|
+
|
data/docs/SPAWNED_PROCESSES
CHANGED
@@ -1,89 +1,148 @@
|
|
1
|
-
EventMachine (EM) adds two different formalisms for lightweight concurrency
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
|
28
|
-
ping.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
1
|
+
EventMachine (EM) adds two different formalisms for lightweight concurrency
|
2
|
+
to the Ruby programmer's toolbox: spawned processes and deferrables. This
|
3
|
+
note will show you how to use spawned processes. For more information, see
|
4
|
+
the separate document LIGHTWEIGHT_CONCURRENCY.
|
5
|
+
|
6
|
+
|
7
|
+
=== What are Spawned Processes?
|
8
|
+
|
9
|
+
Spawned Processes in EventMachine are inspired directly by the "processes"
|
10
|
+
found in the Erlang programming language. EM deliberately borrows much (but
|
11
|
+
not all) of Erlang's terminology. However, EM's spawned processes differ from
|
12
|
+
Erlang's in ways that reflect not only Ruby style, but also the fact that
|
13
|
+
Ruby is not a functional language like Erlang.
|
14
|
+
|
15
|
+
Let's proceed with a complete, working code sample that we will analyze line
|
16
|
+
by line. Here's an EM implementation of the "ping-pong" program that also
|
17
|
+
appears in the Erlang tutorial:
|
18
|
+
|
19
|
+
|
20
|
+
require 'eventmachine'
|
21
|
+
|
22
|
+
EM.run {
|
23
|
+
pong = EM.spawn {|x, ping|
|
24
|
+
puts "Pong received #{x}"
|
25
|
+
ping.notify( x-1 )
|
26
|
+
}
|
27
|
+
|
28
|
+
ping = EM.spawn {|x|
|
29
|
+
if x > 0
|
30
|
+
puts "Pinging #{x}"
|
31
|
+
pong.notify x, self
|
32
|
+
else
|
33
|
+
EM.stop
|
34
|
+
end
|
35
|
+
}
|
36
|
+
|
37
|
+
ping.notify 3
|
38
|
+
}
|
39
|
+
|
40
|
+
If you run this program, you'll see the following output:
|
41
|
+
|
42
|
+
Pinging 3
|
43
|
+
Pong received 3
|
44
|
+
Pinging 2
|
45
|
+
Pong received 2
|
46
|
+
Pinging 1
|
47
|
+
Pong received 1
|
48
|
+
|
49
|
+
Let's take it step by step.
|
50
|
+
|
51
|
+
EventMachine#spawn works very much like the built-in function spawn in
|
52
|
+
Erlang. It returns a reference to a Ruby object of class
|
53
|
+
EventMachine::SpawnedProcess, which is actually a schedulable entity. In
|
54
|
+
Erlang, the value returned from spawn is called a "process identifier" or
|
55
|
+
"pid." But we'll refer to the Ruby object returned from EM#spawn simply as a
|
56
|
+
"spawned process."
|
57
|
+
|
58
|
+
You pass a Ruby block with zero or more parameters to EventMachine#spawn.
|
59
|
+
Like all Ruby blocks, this one is a closure, so it can refer to variables
|
60
|
+
defined in the local context when you call EM#spawn.
|
61
|
+
|
62
|
+
However, the code block passed to EM#spawn does NOT execute immediately by
|
63
|
+
default. Rather, it will execute only when the Spawned Object is "notified."
|
64
|
+
In Erlang, this process is called "message passing," and is done with the
|
65
|
+
operator !, but in Ruby it's done simply by calling the #notify method of a
|
66
|
+
spawned-process object. The parameters you pass to #notify must match those
|
67
|
+
defined in the block that was originally passed to EM#spawn.
|
68
|
+
|
69
|
+
When you call the #notify method of a spawned-process object, EM's reactor
|
70
|
+
core will execute the code block originally passed to EM#spawn, at some point
|
71
|
+
in the future. (#notify itself merely adds a notification to the object's
|
72
|
+
message queue and ALWAYS returns immediately.)
|
73
|
+
|
74
|
+
When a SpawnedProcess object executes a notification, it does so in the
|
75
|
+
context of the SpawnedProcess object itself. The notified code block can see
|
76
|
+
local context from the point at which EM#spawn was called. However, the value
|
77
|
+
of "self" inside the notified code block is a reference to the SpawnedProcesss
|
78
|
+
object itself.
|
79
|
+
|
80
|
+
An EM spawned process is nothing more than a Ruby object with a message
|
81
|
+
queue attached to it. You can have any number of spawned processes in your
|
82
|
+
program without compromising scalability. You can notify a spawned process
|
83
|
+
any number of times, and each notification will cause a "message" to be
|
84
|
+
placed in the queue of the spawned process. Spawned processes with non-empty
|
85
|
+
message queues are scheduled for execution automatically by the EM reactor.
|
86
|
+
Spawned processes with no visible references are garbage-collected like any
|
87
|
+
other Ruby object.
|
88
|
+
|
89
|
+
Back to our code sample:
|
90
|
+
|
91
|
+
pong = EM.spawn {|x, ping|
|
92
|
+
puts "Pong received #{x}"
|
93
|
+
ping.notify( x-1 )
|
94
|
+
}
|
95
|
+
|
96
|
+
This simply creates a spawned process and assigns it to the local variable
|
97
|
+
pong. You can see that the spawned code block takes a numeric parameter and a
|
98
|
+
reference to another spawned process. When pong is notified, it expects to
|
99
|
+
receive arguments corresponding to these two parameters. It simply prints out
|
100
|
+
the number it receives as the first argument. Then it notifies the spawned
|
101
|
+
process referenced by the second argument, passing it the first argument
|
102
|
+
minus 1.
|
103
|
+
|
104
|
+
And then the block ends, which is crucial because otherwise nothing else
|
105
|
+
can run. (Remember that in LC, scheduled entities run to completion and are
|
106
|
+
never preempted.)
|
107
|
+
|
108
|
+
On to the next bit of the code sample:
|
109
|
+
|
110
|
+
ping = EM.spawn {|x|
|
111
|
+
if x > 0
|
112
|
+
puts "Pinging #{x}"
|
113
|
+
pong.notify x, self
|
114
|
+
else
|
115
|
+
EM.stop
|
116
|
+
end
|
117
|
+
}
|
118
|
+
|
119
|
+
Here, we're spawning a process that takes a single (numeric) parameter. If
|
120
|
+
the parameter is greater than zero, the block writes it to the console. It
|
121
|
+
then notifies the spawned process referenced by the pong local variable,
|
122
|
+
passing as arguments its number argument, and a reference to itself. The
|
123
|
+
latter reference, as you saw above, is used by pong to send a return
|
124
|
+
notification.
|
125
|
+
|
126
|
+
If the ping process receives a zero value, it will stop the reactor loop and
|
127
|
+
end the program.
|
128
|
+
|
129
|
+
Now we've created a pair of spawned processes, but nothing else has happened.
|
130
|
+
If we stop now, the program will spin in the EM reactor loop, doing nothing
|
131
|
+
at all. Our spawned processes will never be scheduled for execution.
|
132
|
+
|
133
|
+
But look at the next line in the code sample:
|
134
|
+
|
135
|
+
ping.notify 3
|
136
|
+
|
137
|
+
This line gets the ping-pong ball rolling. We call ping's #notify method,
|
138
|
+
passing the argument 3. This causes a message to be sent to the ping spawned
|
139
|
+
process. The message contains the single argument, and it causes the EM
|
140
|
+
reactor to schedule the ping process. And this in turn results in the
|
141
|
+
execution of the Ruby code block passed to EM#spawn when ping was created.
|
142
|
+
Everything else proceeds as a result of the messages that are subsequently
|
143
|
+
passed to each other by the spawned processes.
|
144
|
+
|
145
|
+
[TODO, present the outbound network i/o use case, and clarify that spawned
|
146
|
+
processes are interleaved with normal i/o operations and don't interfere
|
147
|
+
with them at all. Also, blame Erlang for the confusing term "process"]
|
148
|
+
|
data/docs/TODO
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
TODO List:
|
2
|
-
|
3
|
-
12Aug06: Noticed by Don Stocks. A TCP connect-request that results
|
4
|
-
in a failed DNS resolution fires a fatal error back to user code.
|
5
|
-
Uuuuuugly. We should probably cause an unbind event to get fired
|
6
|
-
instead, and add some parameterization so the caller can detect
|
7
|
-
the nature of the failure.
|
8
|
-
|
1
|
+
TODO List:
|
2
|
+
|
3
|
+
12Aug06: Noticed by Don Stocks. A TCP connect-request that results
|
4
|
+
in a failed DNS resolution fires a fatal error back to user code.
|
5
|
+
Uuuuuugly. We should probably cause an unbind event to get fired
|
6
|
+
instead, and add some parameterization so the caller can detect
|
7
|
+
the nature of the failure.
|
8
|
+
|