Class: Google::Cloud::Firestore::DocumentListener

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/firestore/document_listener.rb

Overview

An ongoing listen operation on a document reference. This is returned by calling Google::Cloud::Firestore::DocumentReference#listen.

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Get a document reference
nyc_ref = firestore.doc "cities/NYC"

listener = nyc_ref.listen do |snapshot|
  puts "The population of #{snapshot[:name]} "
  puts "is #{snapshot[:population]}."
end

# When ready, stop the listen operation and close the stream.
listener.stop

Instance Method Summary collapse

Instance Method Details

#stopObject

Stops the client listening for changes.

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Get a document reference
nyc_ref = firestore.doc "cities/NYC"

listener = nyc_ref.listen do |snapshot|
  puts "The population of #{snapshot[:name]} "
  puts "is #{snapshot[:population]}."
end

# When ready, stop the listen operation and close the stream.
listener.stop


90
91
92
# File 'lib/google/cloud/firestore/document_listener.rb', line 90

def stop
  @listener.stop
end

#stopped?Boolean

Whether the client has stopped listening for changes.

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Get a document reference
nyc_ref = firestore.doc "cities/NYC"

listener = nyc_ref.listen do |snapshot|
  puts "The population of #{snapshot[:name]} "
  puts "is #{snapshot[:population]}."
end

# Checks if the listener is stopped.
listener.stopped? #=> false

# When ready, stop the listen operation and close the stream.
listener.stop

# Checks if the listener is stopped.
listener.stopped? #=> true

Returns:

  • (Boolean)


119
120
121
# File 'lib/google/cloud/firestore/document_listener.rb', line 119

def stopped?
  @listener.stopped?
end