Reference documentation and code samples for the google-cloud-firestore class Google::Cloud::Firestore::DocumentListener.
DocumentListener
An ongoing listen operation on a document reference. This is returned by calling Google::Cloud::Firestore::DocumentReference#listen.
Inherits
- Object
Includes
- MonitorMixin
Example
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]} is #{snapshot[:population]}." end # When ready, stop the listen operation and close the stream. listener.stop
Methods
#last_error
def last_error() -> Exception, nil
The most recent unhandled error to occur while listening for changes.
If an unhandled error has occurred the listener will attempt to recover from the error and resume listening.
- (Exception, nil) — error The most recent error raised.
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]} is #{snapshot[:population]}." end # If an error was raised, it can be retrieved here: listener.last_error #=> nil # When ready, stop the listen operation and close the stream. listener.stop
#on_error
def on_error(&block) { |error| ... }
Register to be notified of errors when raised.
If an unhandled error has occurred the listener will attempt to recover from the error and resume listening.
Multiple error handlers can be added.
- (callback) — The block to be called when an error is raised.
- error (Exception) — The error raised.
- (ArgumentError)
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]} is #{snapshot[:population]}." end # Register to be notified when unhandled errors occur. listener.on_error do |error| puts error end # When ready, stop the listen operation and close the stream. listener.stop
#stop
def stop()
Stops the client listening for changes.
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]} is #{snapshot[:population]}." end # When ready, stop the listen operation and close the stream. listener.stop
#stopped?
def stopped?() -> Boolean
Whether the client has stopped listening for changes.
- (Boolean)
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]} 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