Skip to content

Commit f7e3672

Browse files
committed
Removed old channel, replaced with new.
1 parent 359d9bc commit f7e3672

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1332
-2391
lines changed

doc/channel.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The Go programming languages uses "goroutines" as the core concurrency mechanism
2828
```ruby
2929
puts "Main thread: #{Thread.current}"
3030

31-
Concurrent::Edge::Channel.go do
31+
Concurrent::Channel.go do
3232
puts "Goroutine thread: #{Thread.current}"
3333
end
3434

@@ -47,9 +47,9 @@ The core channel operations are {#put} and {#take} (aliased as {#send} and {#rec
4747
The following, simple example creates a channel, launches a goroutine from which a value is placed into the channel, then reads that value from the channel. When run this example will display "ping" in the console.
4848

4949
```ruby
50-
messages = Concurrent::Edge::Channel.new
50+
messages = Concurrent::Channel.new
5151

52-
Concurrent::Edge::Channel.go do
52+
Concurrent::Channel.go do
5353
messages.put 'ping'
5454
end
5555

@@ -69,10 +69,10 @@ end
6969

7070
a = [7, 2, 8, -9, 4, 0]
7171
l = a.length / 2
72-
c = Concurrent::Edge::Channel.new
72+
c = Concurrent::Channel.new
7373

74-
Concurrent::Edge::Channel.go { sum(a[-l, l], c) }
75-
Concurrent::Edge::Channel.go { sum(a[0, l], c) }
74+
Concurrent::Channel.go { sum(a[-l, l], c) }
75+
Concurrent::Channel.go { sum(a[0, l], c) }
7676
x, y = ~c, ~c # `~` is an alias for `take` or `receive`
7777

7878
puts [x, y, x+y].join(' ')
@@ -85,7 +85,7 @@ One common channel variation is a *buffered* channel. A buffered channel has a f
8585
The following example creates a buffered channel with two slots. It then makes two `put` calls, adding values to the channel. These calls do not block because the buffer has room. Were a third `put` call to be made before an `take` calls, the third `put` would block.
8686

8787
```ruby
88-
ch = Concurrent::Edge::Channel.new(size: 2)
88+
ch = Concurrent::Channel.new(size: 2)
8989
ch << 1
9090
ch << 2
9191

@@ -106,8 +106,8 @@ def worker(done_channel)
106106
done_channel << true
107107
end
108108

109-
done = Concurrent::Edge::Channel.new(size: 1)
110-
Concurrent::Edge::Channel.go{ worker(done) }
109+
done = Concurrent::Channel.new(size: 1)
110+
Concurrent::Channel.go{ worker(done) }
111111

112112
~done # block until signaled
113113
```
@@ -119,21 +119,21 @@ Often it is necessary for a single thread to operate on more than one channel. T
119119
The following example spawns two goroutines, each of which goes to sleep before putting a value onto a channel. The main thread loops twice over a `select` and, in each loop, takes a value off of whichever channel returns one first.
120120

121121
```ruby
122-
c1 = Concurrent::Edge::Channel.new
123-
c2 = Concurrent::Edge::Channel.new
122+
c1 = Concurrent::Channel.new
123+
c2 = Concurrent::Channel.new
124124

125-
Concurrent::Edge::Channel.go do
125+
Concurrent::Channel.go do
126126
sleep(1)
127127
c1 << 'one'
128128
end
129129

130-
Concurrent::Edge::Channel.go do
130+
Concurrent::Channel.go do
131131
sleep(2)
132132
c1 << 'two'
133133
end
134134

135135
2.times do
136-
Concurrent::Edge::Channel.select do |s|
136+
Concurrent::Channel.select do |s|
137137
s.take(c1) { |msg| print "received #{msg}\n" }
138138
s.take(c2) { |msg| print "received #{msg}\n" }
139139
end
@@ -153,7 +153,7 @@ The next example calculates the first 10 fibonacci numbers, passing them to the
153153
def fibonacci(c, quit)
154154
x, y = 0, 1
155155
loop do
156-
Concurrent::Edge::Channel.select do |s|
156+
Concurrent::Channel.select do |s|
157157
s.case(c, :<<, x) { x, y = y, x+y; x } # alias for `s.put`
158158
s.case(quit, :~) do # alias for `s.take`
159159
puts 'quit'
@@ -163,10 +163,10 @@ def fibonacci(c, quit)
163163
end
164164
end
165165

166-
c = Concurrent::Edge::Channel.new
167-
quit = Concurrent::Edge::Channel.new
166+
c = Concurrent::Channel.new
167+
quit = Concurrent::Channel.new
168168

169-
Concurrent::Edge::Channel.go do
169+
Concurrent::Channel.go do
170170
10.times { puts ~c }
171171
quit << 0
172172
end
@@ -192,8 +192,8 @@ def fibonacci(n, c)
192192
c.close
193193
end
194194

195-
chan = Concurrent::Edge::Channel.new(size: 10)
196-
Concurrent::Edge::Channel.go { fibonacci(chan.capacity, c) }
195+
chan = Concurrent::Channel.new(size: 10)
196+
Concurrent::Channel.go { fibonacci(chan.capacity, c) }
197197
chan.each { |i| puts i }
198198
```
199199

@@ -203,16 +203,16 @@ chan.each { |i| puts i }
203203

204204
A {.timer} is a specialized channel which triggers at a predefined time, specified as a number of seconds in the future. It is similar in concept to a {Concurrent::ScheduledTask} but operates as a channel and can fully participate in all channel operations.
205205

206-
The following code example creates two timers with different delay values. The first timer is allowed to expire (trigger) by having the main thread perform a `take` on it. When the timer expires it puts a {Concurrent::Edge::Channel::Tick} object into its buffer and closes. The second timer is listened to on a goroutine but the it never expires: the main thread stops (closes) the timer before it expires. Note that the goroutine in this example blocks forever and never exits. Since the timer is closed it never puts the `Tick` into its buffer.
206+
The following code example creates two timers with different delay values. The first timer is allowed to expire (trigger) by having the main thread perform a `take` on it. When the timer expires it puts a {Concurrent::Channel::Tick} object into its buffer and closes. The second timer is listened to on a goroutine but the it never expires: the main thread stops (closes) the timer before it expires. Note that the goroutine in this example blocks forever and never exits. Since the timer is closed it never puts the `Tick` into its buffer.
207207

208208
```ruby
209-
timer1 = Concurrent::Edge::Channel.timer(2)
209+
timer1 = Concurrent::Channel.timer(2)
210210

211211
~timer1
212212
puts 'Timer 1 expired'
213213

214-
timer2 = Concurrent::Edge::Channel.timer(1)
215-
Concurrent::Edge::Channel.go do
214+
timer2 = Concurrent::Channel.timer(1)
215+
Concurrent::Channel.go do
216216
~timer2
217217
print "Timer 2 expired\n"
218218
end
@@ -226,8 +226,8 @@ A {.ticker} is a specialized channel which triggers over and over again at a pre
226226
The following example creates a ticker which triggers every half-second. A goroutine iterates over the ticker using the `each` method, printing the tick at every interval. When the main thread stops (closes) the ticker the `each` call ends and the goroutine exits.
227227

228228
```ruby
229-
ticker = Concurrent::Edge::Channel.ticker(0.5)
230-
Concurrent::Edge::Channel.go do
229+
ticker = Concurrent::Channel.ticker(0.5)
230+
Concurrent::Channel.go do
231231
ticker.each do |tick|
232232
print "Tick at #{tick}\n"
233233
end
@@ -243,11 +243,11 @@ print "Ticker stopped\n"
243243
As with a Ruby `case` statement, a `Channel.select` statement will accept a `default` clause which will trigger if none of the other clauses trigger. Not surprisingly, the `default` clause must be the last clause in a `select` block.
244244

245245
```ruby
246-
tick = Concurrent::Edge::Channel.tick(0.1) # alias for `ticker`
247-
boom = Concurrent::Edge::Channel.after(0.5) # alias for `timer`
246+
tick = Concurrent::Channel.tick(0.1) # alias for `ticker`
247+
boom = Concurrent::Channel.after(0.5) # alias for `timer`
248248

249249
loop do
250-
Concurrent::Edge::Channel.select do |s|
250+
Concurrent::Channel.select do |s|
251251
s.take(tick) { print "tick.\n" }
252252
s.take(boom) do
253253
print "BOOM!\n"

examples/a-tour-of-go-channels/buffered-channels.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$: << File.expand_path('../../../lib', __FILE__)
44
require 'concurrent-edge'
5-
Channel = Concurrent::Edge::Channel
5+
Channel = Concurrent::Channel
66

77
## A Tour of Go: Buffered Channels
88
# https://tour.golang.org/concurrency/3

examples/a-tour-of-go-channels/channels.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$: << File.expand_path('../../../lib', __FILE__)
44
require 'concurrent-edge'
5-
Channel = Concurrent::Edge::Channel
5+
Channel = Concurrent::Channel
66

77
## A Tour of Go: Channels
88
# https://tour.golang.org/concurrency/2

examples/a-tour-of-go-channels/default-selection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$: << File.expand_path('../../../lib', __FILE__)
44
require 'concurrent-edge'
5-
Channel = Concurrent::Edge::Channel
5+
Channel = Concurrent::Channel
66

77
## A Tour of Go: Default Selection
88
# https://tour.golang.org/concurrency/6

examples/a-tour-of-go-channels/equivalent-binary-trees.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$: << File.expand_path('../../../lib', __FILE__)
44
require 'concurrent-edge'
5-
Channel = Concurrent::Edge::Channel
5+
Channel = Concurrent::Channel
66

77
## A Tour of Go: Equivalent Binary Trees
88
# https://tour.golang.org/concurrency/8

examples/a-tour-of-go-channels/range-and-close.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$: << File.expand_path('../../../lib', __FILE__)
44
require 'concurrent-edge'
5-
Channel = Concurrent::Edge::Channel
5+
Channel = Concurrent::Channel
66

77
## A Tour of Go: Range and Close
88
# https://tour.golang.org/concurrency/4

examples/a-tour-of-go-channels/select.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$: << File.expand_path('../../../lib', __FILE__)
44
require 'concurrent-edge'
5-
Channel = Concurrent::Edge::Channel
5+
Channel = Concurrent::Channel
66

77
## A Tour of Go: Select
88
# https://tour.golang.org/concurrency/5

examples/edge_futures.in.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@
145145

146146
### Interoperability with channels
147147

148-
ch1 = Concurrent::Edge::Channel.new
149-
ch2 = Concurrent::Edge::Channel.new
148+
ch1 = Concurrent::Channel.new
149+
ch2 = Concurrent::Channel.new
150150

151151
result = Concurrent.select(ch1, ch2)
152-
ch1.push 1
152+
ch1.put 1
153153
result.value!
154154

155155
Concurrent.

examples/edge_futures.out.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@
173173

174174
### Interoperability with channels
175175

176-
ch1 = Concurrent::Edge::Channel.new # => #<Concurrent::Edge::Channel:0x007fcc73043188>
177-
ch2 = Concurrent::Edge::Channel.new # => #<Concurrent::Edge::Channel:0x007fcc730425f8>
176+
ch1 = Concurrent::Channel.new # => #<Concurrent::Channel:0x007fcc73043188>
177+
ch2 = Concurrent::Channel.new # => #<Concurrent::Channel:0x007fcc730425f8>
178178

179179
result = Concurrent.select(ch1, ch2)
180180
# => <#Concurrent::Edge::CompletableFuture:0x7fcc730411a8 pending blocks:[]>
181181
ch1.push 1 # => nil
182182
result.value!
183-
# => [1, #<Concurrent::Edge::Channel:0x007fcc73043188>]
183+
# => [1, #<Concurrent::Channel:0x007fcc73043188>]
184184

185185
Concurrent.
186186
future { 1+1 }.

examples/go-by-example-channels/channel-buffering.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$: << File.expand_path('../../../lib', __FILE__)
44
require 'concurrent-edge'
5-
Channel = Concurrent::Edge::Channel
5+
Channel = Concurrent::Channel
66

77
## Go by Example: Channel Buffering
88
# https://gobyexample.com/channel-buffering

0 commit comments

Comments
 (0)