Third observer to subscribe gets no events
See original GitHub issueI’ve implemented an observer type to use with the AsObservable function. This works fine for the first two instances, but the third instance of the observer that I create never gets any events.
My observer class:
public class CommandObserver : IObserver<FirebaseEvent<Command>>
{
private IDisposable _unsubscriber;
private IObservable<FirebaseEvent<Command>> _provider;
public delegate void CommandChangedEventHandler(FirebaseEvent<Command> e);
public event CommandChangedEventHandler CommandChanged;
public delegate void CommandErrorEventHandler(Exception x, string userId);
public event CommandErrorEventHandler CommandError;
public delegate void ObjectCompletedEventHandler(string userId);
public event ObjectCompletedEventHandler CommandCompleted;
public string UserID { get; set; }
public bool Stopped
{
get
{
return _unsubscriber == null;
}
}
public CommandObserver(IObservable<FirebaseEvent<Command>> provider, string userId)
{
this.UserID = userId;
_provider = provider;
}
public void Subscribe()
{
_unsubscriber = _provider.Subscribe(this);
}
public void Unsubsribe()
{
if(_unsubscriber != null) _unsubscriber.Dispose();
}
public void OnCompleted()
{
Debug.WriteLine($"CommandObserver completed for user {this.UserID}");
this.Unsubsribe();
this.CommandCompleted?.Invoke(this.UserID);
}
public void OnError(Exception error)
{
Debug.WriteLine($"CommandObserver error for user {this.UserID}: {error}");
this.Unsubsribe();
this.CommandError?.Invoke(error, this.UserID);
}
public void OnNext(FirebaseEvent<Command> value)
{
Debug.WriteLine($"Command {value.Key} changed on user {value.Object.UserID}");
this.CommandChanged?.Invoke(value);
}
}
Where I get it:
public CommandObserver GetCommandObserver(string userId)
{
var client = GetClient("DATABASE_NAME_HERE");
var provider = client.Child("Commands").Child(userId).AsObservable<Command>();
var observer = new CommandObserver(provider, userId);
return observer;
}
I always call Unsubscribe on the previous observer before getting the next one, but it never fails - the third one will get no events.
I’m hoping someone can point towards what I’m guessing is an error on my part…
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Observer subscribe not firing on first load to Component
1 Answer 1 ... Sequence of events is as follows (confirmed during debugging): ... It's because the vanilla Subject doesn't buffer anything. When...
Read more >Understanding, creating and subscribing to observables in ...
It's good to know that when you subscribe to an observer, each call of subscribe() will trigger it's own independent execution for that...
Read more >Using observables to pass values
When a second observer subscribes, the observable then wires up a new event handler and delivers values to that second observer in a...
Read more >Angular Basics: Introduction to Observables (RxJS)—Part 2
We let an observable know that we want to receive data by calling its subscribe() method and passing in an observer object. The...
Read more >Observable
Subscribing to an Observable is like calling a function, providing callbacks where the data will be delivered to. This is drastically different to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Third subscriber doesn’t work here as well.
Update: It seems there is simply a delay of about 10 seconds from subscribing the third observer until the events start coming through. The amount of data is miniscule so I’m thinking this is a limitation of either the REST API or “firebasedatabase.net”