Class: Elevate::Promise
- Inherits:
-
Object
- Object
- Elevate::Promise
- Defined in:
- lib/elevate/promise.rb
Constant Summary collapse
- OUTSTANDING =
0- FULFILLED =
1
Instance Method Summary collapse
- #fulfill(result) ⇒ Object
-
#initialize ⇒ Promise
constructor
A new instance of Promise.
- #value ⇒ Object
Constructor Details
#initialize ⇒ Promise
Returns a new instance of Promise.
6 7 8 9 |
# File 'lib/elevate/promise.rb', line 6 def initialize @lock = NSConditionLock.alloc.initWithCondition(OUTSTANDING) @result = nil end |
Instance Method Details
#fulfill(result) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/elevate/promise.rb', line 11 def fulfill(result) if @lock.tryLockWhenCondition(OUTSTANDING) @result = result @lock.unlockWithCondition(FULFILLED) end end |
#value ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/elevate/promise.rb', line 18 def value result = nil @lock.lockWhenCondition(FULFILLED) result = @result @lock.unlockWithCondition(FULFILLED) result end |