@@ -27,7 +27,8 @@ def initialize(rid, completion_routine = nil, completion_param = nil)
27
27
self . completion_routine = completion_routine
28
28
self . completion_param = completion_param
29
29
else
30
- self . done = false
30
+ self . mutex = Mutex . new
31
+ self . cond = ConditionVariable . new
31
32
end
32
33
end
33
34
@@ -48,7 +49,9 @@ def notify(response)
48
49
if ( self . completion_routine )
49
50
self . completion_routine . call ( response , self . completion_param )
50
51
else
51
- self . done = true
52
+ self . mutex . synchronize {
53
+ self . cond . signal
54
+ }
52
55
end
53
56
end
54
57
@@ -57,25 +60,14 @@ def notify(response)
57
60
# If the interval is -1 we can wait forever.
58
61
#
59
62
def wait ( interval )
60
- if ( interval and interval == -1 )
61
- while ( not self . done )
62
- ::IO . select ( nil , nil , nil , 0.1 )
63
- end
64
- else
65
- begin
66
- Timeout . timeout ( interval ) {
67
- while ( not self . done )
68
- ::IO . select ( nil , nil , nil , 0.1 )
69
- end
70
- }
71
- rescue Timeout ::Error
72
- self . response = nil
73
- end
74
- end
63
+ interval = nil if interval and interval == -1
64
+ self . mutex . synchronize {
65
+ self . cond . wait ( self . mutex , interval )
66
+ }
75
67
return self . response
76
68
end
77
69
78
- attr_accessor :rid , :done , :response # :nodoc:
70
+ attr_accessor :rid , :mutex , :cond , :response # :nodoc:
79
71
attr_accessor :completion_routine , :completion_param # :nodoc:
80
72
end
81
73
0 commit comments