Skip to content

Commit

Permalink
Added documentation for new Channel class.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdantonio committed Jan 7, 2014
1 parent 345eb8b commit 502d282
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .ruby-version.sample
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.0.0-p247
ruby-ruby-2.1.0
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ The design goals of this gem are:
* Repeated task execution with Java-inspired [TimerTask](https://github.com/jdantonio/concurrent-ruby/blob/master/md/timer_task.md) service
* Scheduled task execution with Java-inspired [ScheduledTask](https://github.com/jdantonio/concurrent-ruby/blob/master/md/scheduled_task.md) service
* Erlang-inspired [Supervisor](https://github.com/jdantonio/concurrent-ruby/blob/master/md/supervisor.md) for managing long-running threads
* 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)
* Actor variant [Channel](https://github.com/jdantonio/concurrent-ruby/blob/master/md/channel.md)
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)
agent in [F#](http://msdn.microsoft.com/en-us/library/ee370357.aspx)

### Semantic Versioning
Expand Down
40 changes: 40 additions & 0 deletions md/channel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Change the dang channel!

`Channel` is a functional programming variation of `Actor`, based very loosely on the
[MailboxProcessor](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx)
agent in [F#](http://msdn.microsoft.com/en-us/library/ee370357.aspx).
The `Actor` is used to create objects that receive messages from other
threads then processes those messages based on the behavior of the class. `Channel`
creates objects that receive messages and processe them using the block given
at construction. `Channel` is implemented as a subclass of
[Actor](https://github.com/jdantonio/concurrent-ruby/blob/master/md/actor.md)
and supports all message-passing methods of that class. `Channel` also supports pools
with a shared mailbox.

See the [Actor](https://github.com/jdantonio/concurrent-ruby/blob/master/md/actor.md)
documentation for more detail.

## Usage

```ruby
require 'concurrent'

channel = Concurrent::Channel.new do |msg|
sleep(1)
puts "#{msg}\n"
end

channel.run! => #<Thread:0x007fa123d95fc8 sleep>

channel.post("Hello, World!") => 1
# wait...
=> Hello, World!

future = channel.post? "Don't Panic." => #<Concurrent::Contract:0x007fa123d6d9d8 @state=:pending...
future.pending? => true
# wait...
=> "Don't Panic."
future.fulfilled? => true

channel.stop => true
```

0 comments on commit 502d282

Please sign in to comment.