Skip to content

Commit 98d1c80

Browse files
committed
Updated README
1 parent d4fac12 commit 98d1c80

File tree

1 file changed

+57
-44
lines changed

1 file changed

+57
-44
lines changed

README.md

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,27 @@ There are many concurrency abstractions in this library. These abstractions can
6161
into several general groups:
6262

6363
* Asynchronous concurrency abstractions including
64-
[Async](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Async),
65-
[Agent](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Agent),
66-
[Future](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Future),
67-
[Promise](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Promise),
68-
[ScheduledTask](https://github.com/ruby-concurrency/concurrent-ruby/wiki/ScheduledTask),
69-
and [TimerTask](https://github.com/ruby-concurrency/concurrent-ruby/wiki/TimerTask)
70-
* Thread-safe variables including [M-Structures](https://github.com/ruby-concurrency/concurrent-ruby/wiki/MVar-(M-Structure)),
71-
[I-Structures](https://github.com/ruby-concurrency/concurrent-ruby/wiki/IVar-(I-Structure)),
72-
[thread-local variables](https://github.com/ruby-concurrency/concurrent-ruby/wiki/ThreadLocalVar),
73-
atomic counters, and [software transactional memory](https://github.com/ruby-concurrency/concurrent-ruby/wiki/TVar-(STM))
74-
* Thread synchronization classes and algorithms including [dataflow](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Dataflow),
75-
timeout, condition, countdown latch, dependency counter, and event
76-
* Java-inspired [thread pools](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Thread%20Pools)
77-
* New fast light-weighted [Actor model](http://ruby-concurrency.github.io/concurrent-ruby/frames.html#!Concurrent/Actress.html) implementation.
78-
* And many more...
64+
[Agent](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Agent.html),
65+
[Async](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Async.html),
66+
[Future](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Future.html),
67+
[Promise](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Promise.html),
68+
[ScheduledTask](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ScheduledTask.html),
69+
and [TimerTask](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/TimerTask.html)
70+
* Fast, light-weight [Actor model](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Actor.html) implementation.
71+
* Thread-safe variables including
72+
[I-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html),
73+
[M-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/MVar.html),
74+
[thread-local variables](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadLocalVar.html),
75+
and [software transactional memory](https://github.com/ruby-concurrency/concurrent-ruby/wiki/TVar-(STM))
76+
* Thread synchronization classes and algorithms including
77+
[condition](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Condition.html),
78+
[countdown latch](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CountDownLatch.html),
79+
[dataflow](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Dataflow),
80+
[event](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Event.html),
81+
[exchanger](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Exchanger.html),
82+
and [timeout](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timeout-class_method)
83+
* Java-inspired [executors](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Thread%20Pools) (thread pools and more)
84+
* [And many more](http://ruby-concurrency.github.io/concurrent-ruby/index.html)...
7985

8086
### Semantic Versioning
8187

@@ -90,7 +96,8 @@ It should be fully compatible with any interpreter that is compliant with Ruby 1
9096
### Examples
9197

9298
Many more code examples can be found in the documentation for each class (linked above).
93-
This one simple example shows some of the power of this gem.
99+
100+
Future and ScheduledTask:
94101

95102
```ruby
96103
require 'concurrent'
@@ -112,25 +119,47 @@ sleep(1) # do other stuff
112119
price.value #=> 63.65
113120
price.state #=> :fulfilled
114121

115-
# Promise
116-
prices = Concurrent::Promise.new{ puts Ticker.new.get_year_end_closing('AAPL', 2013) }.
117-
then{ puts Ticker.new.get_year_end_closing('MSFT', 2013) }.
118-
then{ puts Ticker.new.get_year_end_closing('GOOG', 2013) }.
119-
then{ puts Ticker.new.get_year_end_closing('AMZN', 2013) }.execute
120-
prices.state #=> :pending
121-
sleep(1) # do other stuff
122-
#=> 561.02
123-
#=> 37.41
124-
#=> 1120.71
125-
#=> 398.79
126-
127122
# ScheduledTask
128123
task = Concurrent::ScheduledTask.execute(2){ Ticker.new.get_year_end_closing('INTC', 2013) }
129124
task.state #=> :pending
130125
sleep(3) # do other stuff
131126
task.value #=> 25.96
132127
```
133128

129+
Actor:
130+
131+
```ruby
132+
class Counter < Concurrent::Actor::Context
133+
# Include context of an actor which gives this class access to reference
134+
# and other information about the actor
135+
136+
# use initialize as you wish
137+
def initialize(initial_value)
138+
@count = initial_value
139+
end
140+
141+
# override on_message to define actor's behaviour
142+
def on_message(message)
143+
if Integer === message
144+
@count += message
145+
end
146+
end
147+
end #
148+
149+
# Create new actor naming the instance 'first'.
150+
# Return value is a reference to the actor, the actual actor is never returned.
151+
counter = Counter.spawn(:first, 5)
152+
153+
# Tell a message and forget returning self.
154+
counter.tell(1)
155+
counter << 1
156+
# (First counter now contains 7.)
157+
158+
# Send a messages asking for a result.
159+
counter.ask(0).class
160+
counter.ask(0).value
161+
```
162+
134163
## Maintainers
135164

136165
* [Jerry D'Antonio](https://github.com/jdantonio)
@@ -139,22 +168,6 @@ task.value #=> 25.96
139168
* [Lucas Allan](https://github.com/lucasallan)
140169
* [Petr Chalupa](https://github.com/pitr-ch)
141170

142-
### Contributors
143-
144-
* [Bill Dueber](https://github.com/billdueber)
145-
* [Brian Shirai](https://github.com/brixen)
146-
* [Chip Miller](https://github.com/chip-miller)
147-
* [Giuseppe Capizzi](https://github.com/gcapizzi)
148-
* [Jamie Hodge](https://github.com/jamiehodge)
149-
* [Justin Lambert](https://github.com/mastfish)
150-
* [Larry Lv](https://github.com/larrylv)
151-
* [Maxim Chechel](https://github.com/maximchick)
152-
* [Ravil Bayramgalin](https://github.com/brainopia)
153-
* [René Föhring](https://github.com/rrrene)
154-
* [Shane Wilton](https://github.com/ShaneWilton)
155-
* [sheaney](https://github.com/sheaney)
156-
* [Zander Hill](https://github.com/zph)
157-
158171
### Contributing
159172

160173
1. Fork it

0 commit comments

Comments
 (0)