lib/google/cloud/logging/async_writer.rb in google-cloud-logging-1.10.4 vs lib/google/cloud/logging/async_writer.rb in google-cloud-logging-1.10.5
- old
+ new
@@ -153,11 +153,11 @@
@thread_pool ||= Concurrent::ThreadPoolExecutor.new \
max_threads: @threads, max_queue: @max_queue
@thread ||= Thread.new { run_background }
- publish_batch! if @batch.ready?
+ publish_batch! if @batch&.ready?
@cond.broadcast
end
self
end
@@ -220,10 +220,14 @@
# Blocks until the writer is fully stopped, all pending entries have
# been published, and all callbacks have completed. Does not stop the
# writer. To stop the writer, first call {#stop} and then call {#wait!}
# to block until the writer is stopped.
#
+ # @param [Number, nil] timeout The maximum number of seconds to wait for
+ # shutdown to complete. Will wait forever when the value is `nil`. The
+ # default value is `nil`.
+ #
# @return [AsyncWriter] returns self so calls can be chained.
def wait! timeout = nil
synchronize do
if @thread_pool
@thread_pool.shutdown
@@ -235,21 +239,25 @@
end
##
# Stop this asynchronous writer and block until it has been stopped.
#
- # @param [Number] timeout Timeout in seconds.
+ # @param [Number, nil] timeout The maximum number of seconds to wait for
+ # shutdown to complete. Will wait forever when the value is `nil`. The
+ # default value is `nil`.
# @param [Boolean] force If set to true, and the writer hasn't stopped
- # within the given timeout, kill it forcibly by terminating the
- # thread. This should be used with extreme caution, as it can
- # leave RPCs unfinished. Default is false.
+ # within the given timeout, kill it forcibly by terminating the
+ # thread. This should be used with extreme caution, as it can
+ # leave RPCs unfinished. Default is false.
#
- # @return [Symbol] Returns `:stopped` if the AsyncWriter was already
- # stopped at the time of invocation, `:waited` if it stopped
- # during the timeout period, `:timeout` if it is still running
- # after the timeout, or `:forced` if it was forcibly killed.
+ # @return [Symbol] Returns `:new` if {#write_entries} has never been
+ # called on the AsyncWriter, `:stopped` if it was already stopped
+ # at the time of invocation, `:waited` if it stopped during the
+ # timeout period, `:timeout` if it is still running after the
+ # timeout, or `:forced` if it was forcibly killed.
#
def stop! timeout = nil, force: nil
+ return :new unless @thread_pool
return :stopped if stopped?
stop
wait! timeout