SubscriptionPromise
The SubscriptionPromise
class is what is returned from all reading operations. It allows to both read documents once or subscribe to updates depending what you do with the instance.
Alghough the class doesn’t extend the builtin Promise
class, it implements the same interface so that you can use it as a promise.
Promise mode
If you call then
, catch
or await
on the instance, it will perform the read operation and return the result.
You can’t subscribe to updates in this mode, so if you call on
it will throw an error:
Subscription mode
If you call on
on the instance, it will subscribe to updates and return a function to unsubscribe:
You can handle errors using catch
:
Just like with the promise, you can’t read the document in this mode, so if you call then
, catch
or await
it will throw an error:
Constructor
Typically you don’t need to construct SubscriptionPromise
manually, but you’re working on a new method, or custom wrapper, you can use the constructor like that:
request
The property holds the request object that describes the request. It’s useful for integrations, debugging, and logging.
on
The method that triggers the subscription. See the Subscription mode section for more details.