class MrDarcy::Promise::Thread
Implementation of promises using Ruby threads and locks.
See MrDarcy::Promise::Base
for method information.
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
MrDarcy::Promise::Base::new
# File lib/mr_darcy/promise/thread.rb, line 11 def initialize *args @semaphore = Mutex.new semaphore.synchronize { @complete = false } super end
Public Instance Methods
final()
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 22 def final wait_if_unresolved self end
result()
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 17 def result wait_if_unresolved value end
Private Instance Methods
child_promise()
click to toggle source
Calls superclass method
MrDarcy::Promise::Base#child_promise
# File lib/mr_darcy/promise/thread.rb, line 89 def child_promise semaphore.synchronize { super } end
complete!()
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 70 def complete! semaphore.synchronize do @complete = true @wait.broadcast if @wait end end
complete?()
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 65 def complete? # semaphore.synchronize { @complete } @complete end
did_reject(value)
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 45 def did_reject value complete! end
did_resolve(value)
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 41 def did_resolve value complete! end
ensure_child_promise()
click to toggle source
Calls superclass method
MrDarcy::Promise::Base#ensure_child_promise
# File lib/mr_darcy/promise/thread.rb, line 57 def ensure_child_promise semaphore.synchronize { super } end
generate_child_promise()
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 61 def generate_child_promise ChildPromise.new driver: :thread end
reject_child_promise()
click to toggle source
Calls superclass method
MrDarcy::Promise::Base#reject_child_promise
# File lib/mr_darcy/promise/thread.rb, line 37 def reject_child_promise ::Thread.new { super } end
resolve_child_promise()
click to toggle source
Calls superclass method
MrDarcy::Promise::Base#resolve_child_promise
# File lib/mr_darcy/promise/thread.rb, line 33 def resolve_child_promise ::Thread.new { super } end
schedule_promise(&block)
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 29 def schedule_promise &block ::Thread.new &block end
semaphore()
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 77 def semaphore @semaphore end
set_value_to(value)
click to toggle source
Calls superclass method
MrDarcy::Promise::Base#set_value_to
# File lib/mr_darcy/promise/thread.rb, line 81 def set_value_to value semaphore.synchronize { super } end
state_machine()
click to toggle source
Calls superclass method
MrDarcy::Promise::Base#state_machine
# File lib/mr_darcy/promise/thread.rb, line 85 def state_machine semaphore.synchronize { super } end
value()
click to toggle source
Calls superclass method
# File lib/mr_darcy/promise/thread.rb, line 93 def value semaphore.synchronize { super } end
wait_if_unresolved()
click to toggle source
# File lib/mr_darcy/promise/thread.rb, line 49 def wait_if_unresolved return if complete? semaphore.synchronize do @wait = ConditionVariable.new @wait.wait(semaphore) end end