Class: MrDarcy::Promise::Thread

Inherits:
Base
  • Object
show all
Defined in:
lib/mr_darcy/promise/thread.rb

Overview

Implementation of promises using Ruby threads and locks.

See MrDarcy::Promise::Base for method information.

Instance Method Summary collapse

Methods inherited from Base

#fail, #raise, #reject, #resolve, #then

Constructor Details

#initialize(*args) ⇒ Thread

Returns a new instance of Thread


11
12
13
14
15
# File 'lib/mr_darcy/promise/thread.rb', line 11

def initialize *args
  @semaphore = Mutex.new
  semaphore.synchronize { @complete = false }
  super
end

Instance Method Details

#finalObject


22
23
24
25
# File 'lib/mr_darcy/promise/thread.rb', line 22

def final
  wait_if_unresolved
  self
end

#resultObject


17
18
19
20
# File 'lib/mr_darcy/promise/thread.rb', line 17

def result
  wait_if_unresolved
  value
end