Skip to content

Commit 2b3a80d

Browse files
committed
Make AsyncActor#wait_until_async_stopped method public
1 parent b313467 commit 2b3a80d

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

stackdriver-core/lib/stackdriver/core/async_actor.rb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,30 @@ def async_stop!
198198
:forced
199199
end
200200

201+
##
202+
# Block current thread until the async job is fully stopped.
203+
#
204+
# @param [Integer] timeout If given, lift the blocking when the time has
205+
# exceeded the timeout. If nil, block indefinitely.
206+
#
207+
# @return [Boolean] True if async job is fully stopped. False if timeout.
208+
#
209+
def wait_until_async_stopped timeout = nil
210+
ensure_thread
211+
deadline = timeout ? ::Time.new.to_f + timeout : nil
212+
synchronize do
213+
until async_state == :stopped
214+
cur_time = ::Time.new.to_f
215+
return false if deadline && cur_time >= deadline
216+
max_interval = @cleanup_options[:wait_interval]
217+
interval = deadline ? deadline - cur_time : max_interval
218+
interval = max_interval if interval > max_interval
219+
@lock_cond.wait interval
220+
end
221+
end
222+
true
223+
end
224+
201225
##
202226
# Abstract method that the inheriting classes should implement.
203227
#
@@ -244,28 +268,6 @@ def self.run_cleanup
244268

245269
private
246270

247-
##
248-
# @private Helper method to async_stop! to wait for async job to
249-
# terminate.
250-
#
251-
# @return [Boolean] True if async job terminated. False if timeout.
252-
#
253-
def wait_until_async_stopped timeout = nil
254-
ensure_thread
255-
deadline = timeout ? ::Time.new.to_f + timeout : nil
256-
synchronize do
257-
until async_state == :stopped
258-
cur_time = ::Time.new.to_f
259-
return false if deadline && cur_time >= deadline
260-
max_interval = @cleanup_options[:wait_interval]
261-
interval = deadline ? deadline - cur_time : max_interval
262-
interval = max_interval if interval > max_interval
263-
@lock_cond.wait interval
264-
end
265-
end
266-
true
267-
end
268-
269271
##
270272
# @private Constructor to initialize MonitorMixin
271273
#

0 commit comments

Comments
 (0)