Skip to content

Commit 502d282

Browse files
committed
Added documentation for new Channel class.
1 parent 345eb8b commit 502d282

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

.ruby-version.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby-2.0.0-p247
1+
ruby-ruby-2.1.0

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ The design goals of this gem are:
3030
* Repeated task execution with Java-inspired [TimerTask](https://github.com/jdantonio/concurrent-ruby/blob/master/md/timer_task.md) service
3131
* Scheduled task execution with Java-inspired [ScheduledTask](https://github.com/jdantonio/concurrent-ruby/blob/master/md/scheduled_task.md) service
3232
* Erlang-inspired [Supervisor](https://github.com/jdantonio/concurrent-ruby/blob/master/md/supervisor.md) for managing long-running threads
33-
* Actor variant called `Channel` loosely based on the [MailboxProcessor](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx)
33+
* Actor variant [Channel](https://github.com/jdantonio/concurrent-ruby/blob/master/md/channel.md)
34+
loosely based on the [MailboxProcessor](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx)
3435
agent in [F#](http://msdn.microsoft.com/en-us/library/ee370357.aspx)
3536

3637
### Semantic Versioning

md/channel.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Change the dang channel!
2+
3+
`Channel` is a functional programming variation of `Actor`, based very loosely on the
4+
[MailboxProcessor](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx)
5+
agent in [F#](http://msdn.microsoft.com/en-us/library/ee370357.aspx).
6+
The `Actor` is used to create objects that receive messages from other
7+
threads then processes those messages based on the behavior of the class. `Channel`
8+
creates objects that receive messages and processe them using the block given
9+
at construction. `Channel` is implemented as a subclass of
10+
[Actor](https://github.com/jdantonio/concurrent-ruby/blob/master/md/actor.md)
11+
and supports all message-passing methods of that class. `Channel` also supports pools
12+
with a shared mailbox.
13+
14+
See the [Actor](https://github.com/jdantonio/concurrent-ruby/blob/master/md/actor.md)
15+
documentation for more detail.
16+
17+
## Usage
18+
19+
```ruby
20+
require 'concurrent'
21+
22+
channel = Concurrent::Channel.new do |msg|
23+
sleep(1)
24+
puts "#{msg}\n"
25+
end
26+
27+
channel.run! => #<Thread:0x007fa123d95fc8 sleep>
28+
29+
channel.post("Hello, World!") => 1
30+
# wait...
31+
=> Hello, World!
32+
33+
future = channel.post? "Don't Panic." => #<Concurrent::Contract:0x007fa123d6d9d8 @state=:pending...
34+
future.pending? => true
35+
# wait...
36+
=> "Don't Panic."
37+
future.fulfilled? => true
38+
39+
channel.stop => true
40+
```

0 commit comments

Comments
 (0)