Class: Quark::MdkUtil::WaitForPromise

Inherits:
DatawireQuarkCore::QuarkObject show all
Extended by:
DatawireQuarkCore::Static
Defined in:
lib/mdk_util.rb

Overview

Utility to blockingly wait for a Promise to get a value.

Constant Summary

Constants included from DatawireQuarkCore::Static

DatawireQuarkCore::Static::Unassigned

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DatawireQuarkCore::Static

_lazy_statics, static, unlazy_statics

Methods inherited from DatawireQuarkCore::QuarkObject

#to_s

Constructor Details

#initializeWaitForPromise

Returns a new instance of WaitForPromise.



23
24
25
26
27
# File 'lib/mdk_util.rb', line 23

def initialize()
    self.__init_fields__

    nil
end

Class Method Details

.wait(p, timeout, description) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mdk_util.rb', line 42

def self.wait(p, timeout, description)
    
    snapshot = p.value()
    if (snapshot.hasValue())
        return snapshot.getValue()
    end
    done = ::DatawireQuarkCore::Condition.new()
    waiter = ::Quark.mdk_util.WaitForPromise.new()
    p.andThen(::Quark.quark._BoundMethod.new(waiter, "_finished", ::DatawireQuarkCore::List.new([done])))
    msTimeout = ((timeout) * (1000.0)).round()
    done.acquire()
    done.waitWakeup(msTimeout)
    done.release()
    snapshot = p.value()
    if (!(snapshot.hasValue()))
        raise (("Timeout waiting for ") + (description))
    end
    return snapshot.getValue()

    nil
end

Instance Method Details

#__init_fields__Object



85
86
87
88
89
# File 'lib/mdk_util.rb', line 85

def __init_fields__()
    

    nil
end

#_finished(value, done) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/mdk_util.rb', line 32

def _finished(value, done)
    
    done.acquire()
    done.wakeup()
    done.release()
    return true

    nil
end

#_getClassObject



64
65
66
67
68
69
# File 'lib/mdk_util.rb', line 64

def _getClass()
    
    return "mdk_util.WaitForPromise"

    nil
end

#_getField(name) ⇒ Object



71
72
73
74
75
76
# File 'lib/mdk_util.rb', line 71

def _getField(name)
    
    return nil

    nil
end

#_setField(name, value) ⇒ Object



78
79
80
81
82
83
# File 'lib/mdk_util.rb', line 78

def _setField(name, value)
    
    nil

    nil
end