Skip to content

Commit 390ac66

Browse files
committed
Renamed Lazy to LazyReference.
1 parent 664234b commit 390ac66

File tree

11 files changed

+62
-66
lines changed

11 files changed

+62
-66
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* All high-level abstractions default to the "io executor"
3333
* Added shutdown/kill/wait_for_termination variants for global executors
3434
* Fixed bug in `Actor` causing it to prematurely warm global thread pools on gem load
35-
* Added `Lazy`, a simpler and faster varition of `Delay`
36-
- Updated most internal uses of `Delay` with `Lazy`
35+
* Added `LazyReference`, a simpler and faster varition of `Delay`
36+
- Updated most internal uses of `Delay` with `LazyReference`
3737

3838
## Current Release v0.8.0 (25 January 2015)
3939

README.md

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,29 @@ This library contains a variety of concurrency abstractions at high and low leve
6666

6767
* See [ThreadPool](http://ruby-concurrency.github.io/concurrent-ruby/file.thread_pools.html) overview, which also contains a list of other Executors available.
6868

69-
### Thread-safe Observers
70-
71-
* [Concurrent::Observable](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Observable.html) mixin module
72-
* [CopyOnNotifyObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnNotifyObserverSet.html)
73-
* [CopyOnWriteObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnWriteObserverSet.html)
74-
7569
### Thread synchronization classes and algorithms
7670

77-
Lower-level abstractions mainly used as building blocks.
78-
79-
* [condition](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Condition.html)
80-
* [countdown latch](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CountDownLatch.html)
81-
* [cyclic barrier](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CyclicBarrier.html)
82-
* [event](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Event.html)
83-
* [exchanger](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Exchanger.html)
84-
* [semaphore](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Semaphore.html)
85-
* [timeout](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timeout-class_method)
86-
* [timer](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timer-class_method)
71+
* [Condition](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Condition.html)
72+
* [CountdownLatch](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CountDownLatch.html)
73+
* [CyclicBarrier](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CyclicBarrier.html)
74+
* [Event](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Event.html)
75+
* [Exchanger](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Exchanger.html)
76+
* [Semaphore](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Semaphore.html)
77+
* [Timeout](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timeout-class_method)
78+
* [Timer](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timer-class_method)
8779

8880
### Thread-safe variables
8981

90-
Lower-level abstractions mainly used as building blocks.
91-
9282
* [AtomicBoolean](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicBoolean.html)
9383
* [AtomicFixnum](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicFixnum.html)
94-
* AtomicReference (no docs currently available, check source)
84+
* [AtomicReference](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/MutexAtomic.html)
85+
* [Delay](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Delay.html)
86+
* [LazyReference](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/LazyReference.html)
87+
* [LazyRegister](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/LazyRegister.html)
9588
* [I-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html) (IVar)
9689
* [M-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/MVar.html) (MVar)
97-
* [thread-local variables](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadLocalVar.html)
98-
* [software transactional memory](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/TVar.html) (TVar)
90+
* [Thread-local variables](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadLocalVar.html)
91+
* [Software transactional memory](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/TVar.html) (TVar)
9992

10093
## Usage
10194

@@ -128,6 +121,8 @@ require 'concurrent/delay' # Concurrent::Delay
128121
require 'concurrent/exchanger' # Concurrent::Exchanger
129122
require 'concurrent/future' # Concurrent::Future
130123
require 'concurrent/ivar' # Concurrent::IVar
124+
require 'concurrent/lazy_register' # Concurrent::LazyRegister
125+
require 'concurrent/lazy_reference' # Concurrent::LazyReference
131126
require 'concurrent/mvar' # Concurrent::MVar
132127
require 'concurrent/promise' # Concurrent::Promise
133128
require 'concurrent/scheduled_task' # Concurrent::ScheduledTask

examples/lazy_and_delay.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
require 'benchmark'
66

77
require 'concurrent/delay'
8+
require 'concurrent/lazy_reference'
89

910
n = 500_000
1011

1112
delay = Concurrent::Delay.new{ nil }
12-
lazy = Concurrent::Lazy.new{ nil }
13+
lazy = Concurrent::LazyReference.new{ nil }
1314

1415
delay.value
1516
lazy.value

lib/concurrent.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
require 'concurrent/configuration'
44

5+
require 'concurrent/actor'
56
require 'concurrent/atomics'
67
require 'concurrent/channels'
78
require 'concurrent/collections'
89
require 'concurrent/errors'
910
require 'concurrent/executors'
1011
require 'concurrent/utilities'
1112

12-
require 'concurrent/actor'
1313
require 'concurrent/atomic'
1414
require 'concurrent/agent'
1515
require 'concurrent/async'
@@ -19,7 +19,7 @@
1919
require 'concurrent/exchanger'
2020
require 'concurrent/future'
2121
require 'concurrent/ivar'
22-
require 'concurrent/lazy'
22+
require 'concurrent/lazy_reference'
2323
require 'concurrent/lazy_register'
2424
require 'concurrent/mvar'
2525
require 'concurrent/promise'

lib/concurrent/agent.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ class Agent
2424
#
2525
# @param [Object] initial the initial value
2626
#
27-
# @!macro executor_and_deref_options
27+
# @!macro [attach] executor_and_deref_options
28+
#
29+
# @param [Hash] opts the options used to define the behavior at update and deref
30+
# and to specify the executor on which to perform actions
31+
# @option opts [Executor] :executor when set use the given `Executor` instance.
32+
# Three special values are also supported: `:task` returns the global task pool,
33+
# `:operation` returns the global operation pool, and `:immediate` returns a new
34+
# `ImmediateExecutor` object.
35+
# @option opts [Boolean] :dup_on_deref (false) call `#dup` before returning the data
36+
# @option opts [Boolean] :freeze_on_deref (false) call `#freeze` before returning the data
37+
# @option opts [Proc] :copy_on_deref (nil) call the given `Proc` passing
38+
# the internal value and returning the value returned from the proc
2839
def initialize(initial, opts = {})
2940
@value = initial
3041
@rescuers = []

lib/concurrent/async.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'thread'
22
require 'concurrent/configuration'
33
require 'concurrent/delay'
4-
require 'concurrent/lazy'
4+
require 'concurrent/lazy_reference'
55
require 'concurrent/errors'
66
require 'concurrent/ivar'
77
require 'concurrent/executor/immediate_executor'
@@ -202,7 +202,7 @@ def init_mutex
202202
}
203203

204204
@__await_delegator__ = Delay.new(executor: :immediate) {
205-
AsyncDelegator.new(self, Lazy.new{ Concurrent::ImmediateExecutor.new }, serializer, true)
205+
AsyncDelegator.new(self, LazyReference.new{ Concurrent::ImmediateExecutor.new }, serializer, true)
206206
}
207207

208208
@__async_delegator__ = Delay.new(executor: :immediate) {

lib/concurrent/configuration.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'thread'
2-
require 'concurrent/lazy'
2+
require 'concurrent/lazy_reference'
33
require 'concurrent/atomics'
44
require 'concurrent/errors'
55
require 'concurrent/executors'
@@ -12,17 +12,17 @@ module Concurrent
1212
class << self
1313
@@auto_terminate_global_executors = Concurrent::AtomicBoolean.new(true)
1414

15-
@@global_fast_executor = Lazy.new do
15+
@@global_fast_executor = LazyReference.new do
1616
Concurrent.new_fast_executor(
1717
stop_on_exit: @@auto_terminate_global_executors.value)
1818
end
1919

20-
@@global_io_executor = Lazy.new do
20+
@@global_io_executor = LazyReference.new do
2121
Concurrent.new_io_executor(
2222
stop_on_exit: @@auto_terminate_global_executors.value)
2323
end
2424

25-
@@global_timer_set = Lazy.new do
25+
@@global_timer_set = LazyReference.new do
2626
Concurrent::TimerSet.new(
2727
stop_on_exit: @@auto_terminate_global_executors.value)
2828
end

lib/concurrent/delay.rb

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Concurrent
77

88
# Lazy evaluation of a block yielding an immutable result. Useful for
99
# expensive operations that may never be needed. `Delay` is a more
10-
# complex and feature-rich version of `Lazy`. It is non-blocking,
10+
# complex and feature-rich version of `LazyReference`. It is non-blocking,
1111
# supports the `Obligation` interface, and accepts the injection of
1212
# custom executor upon which to execute the block. Processing of
1313
# block will be deferred until the first time `#value` is called.
@@ -28,16 +28,16 @@ module Concurrent
2828
# `Delay` includes the `Concurrent::Dereferenceable` mixin to support thread
2929
# safety of the reference returned by `#value`.
3030
#
31-
# Because of its simplicity `Lazy` is much faster than `Delay`:
31+
# Because of its simplicity `LazyReference` is much faster than `Delay`:
3232
#
3333
# user system total real
3434
# Benchmarking Delay...
3535
# 0.730000 0.000000 0.730000 ( 0.738434)
36-
# Benchmarking Lazy...
36+
# Benchmarking LazyReference...
3737
# 0.040000 0.000000 0.040000 ( 0.042322)
3838
#
3939
# @see Concurrent::Dereferenceable
40-
# @see Concurrent::Lazy
40+
# @see Concurrent::LazyReference
4141
class Delay
4242
include Obligation
4343
include ExecutorOptions
@@ -46,18 +46,7 @@ class Delay
4646
#
4747
# @yield the delayed operation to perform
4848
#
49-
# @!macro [attach] executor_and_deref_options
50-
#
51-
# @param [Hash] opts the options used to define the behavior at update and deref
52-
# and to specify the executor on which to perform actions
53-
# @option opts [Executor] :executor when set use the given `Executor` instance.
54-
# Three special values are also supported: `:task` returns the global task pool,
55-
# `:operation` returns the global operation pool, and `:immediate` returns a new
56-
# `ImmediateExecutor` object.
57-
# @option opts [Boolean] :dup_on_deref (false) call `#dup` before returning the data
58-
# @option opts [Boolean] :freeze_on_deref (false) call `#freeze` before returning the data
59-
# @option opts [Proc] :copy_on_deref (nil) call the given `Proc` passing
60-
# the internal value and returning the value returned from the proc
49+
# @!macro executor_and_deref_options
6150
#
6251
# @raise [ArgumentError] if no block is given
6352
def initialize(opts = {}, &block)

lib/concurrent/lazy.rb renamed to lib/concurrent/lazy_reference.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module Concurrent
22

33
# Lazy evaluation of a block yielding an immutable result. Useful for
4-
# expensive operations that may never be needed. `Lazy` is a simpler,
4+
# expensive operations that may never be needed. `LazyReference` is a simpler,
55
# blocking version of `Delay` and has an API similar to `AtomicReference`.
66
# The first time `#value` is called the caller will block until the
77
# block given at construction is executed. Once the result has been
88
# computed the value will be immutably set. Any exceptions thrown during
99
# computation will be suppressed.
1010
#
11-
# Because of its simplicity `Lazy` is much faster than `Delay`:
11+
# Because of its simplicity `LazyReference` is much faster than `Delay`:
1212
#
1313
# user system total real
1414
# Benchmarking Delay...
1515
# 0.730000 0.000000 0.730000 ( 0.738434)
16-
# Benchmarking Lazy...
16+
# Benchmarking LazyReference...
1717
# 0.040000 0.000000 0.040000 ( 0.042322)
1818
#
1919
# @see Concurrent::Delay
20-
class Lazy
20+
class LazyReference
2121

2222
# Creates anew unfulfilled object.
2323
#

lib/concurrent/utility/processor_count.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'rbconfig'
2-
require 'concurrent/lazy'
2+
require 'concurrent/lazy_reference'
33

44
module Concurrent
55

66
class ProcessorCounter
77
def initialize
8-
@processor_count = Lazy.new { compute_processor_count }
9-
@physical_processor_count = Lazy.new { compute_physical_processor_count }
8+
@processor_count = LazyReference.new { compute_processor_count }
9+
@physical_processor_count = LazyReference.new { compute_physical_processor_count }
1010
end
1111

1212
# Number of processors seen by the OS and used for process scheduling. For

0 commit comments

Comments
 (0)