Class: ZeevexConcurrency::Delayed
- Inherits:
-
Object
- Object
- ZeevexConcurrency::Delayed
show all
- Defined in:
- lib/zeevex_concurrency/delayed.rb
Overview
base class for Promise, Future, etc.
Defined Under Namespace
Modules: Bindable, Cancellable, ConvenienceMethods, LatchBased, QueueBased
Classes: CancelledException
Instance Method Summary
collapse
Instance Method Details
#exception ⇒ Object
39
40
41
|
# File 'lib/zeevex_concurrency/delayed.rb', line 39
def exception
@exception
end
|
#exception? ⇒ Boolean
43
44
45
|
# File 'lib/zeevex_concurrency/delayed.rb', line 43
def exception?
!! @exception
end
|
#executed? ⇒ Boolean
47
48
49
|
# File 'lib/zeevex_concurrency/delayed.rb', line 47
def executed?
@executed
end
|
#set_result(&block) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/zeevex_concurrency/delayed.rb', line 74
def set_result(&block)
@exec_mutex.synchronize do
raise ArgumentError, "Must supply block" unless block_given?
raise ArgumentError, "Already supplied block" if bound?
raise ArgumentError, "Promise already executed" if executed?
_execute(block)
end
end
|
#value(reraise = true) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/zeevex_concurrency/delayed.rb', line 51
def value(reraise = true)
@mutex.synchronize do
unless @done
@result = _wait_for_value
@done = true
end
end
if @exception && reraise
raise @exception
else
@result
end
end
|
#wait(timeout = nil) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/zeevex_concurrency/delayed.rb', line 65
def wait(timeout = nil)
Timeout::timeout(timeout) do
value(false)
true
end
rescue Timeout::Error
false
end
|