Permalink
Browse files

Pusher Subscribe is racey, give it some more time

  • Loading branch information...
1 parent dfc9059 commit c5c063eeb372924a8898cec51003614a7325f043 @paulcbetts paulcbetts committed Apr 19, 2012
Showing with 15 additions and 7 deletions.
  1. +15 −7 Play/Models/PusherHelper.cs
@@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using PusherClientDotNet;
+using ReactiveUI;
namespace Play.Models
{
@@ -22,15 +23,22 @@ public static IObservable<T> Connect<T>(Func<Pusher> pusherFactory, string chann
pusher.Connect();
disp.Add(Disposable.Create(pusher.Disconnect));
- var ch = pusher.Subscribe(channel);
- disp.Add(Disposable.Create(() => pusher.Unsubscribe(channel)));
+ // NB: Pusher is racey, give it some time to connect
+ var postConnect = Observable.Start(() => {
+ var ch = pusher.Subscribe(channel);
+ disp.Add(Disposable.Create(() => pusher.Unsubscribe(channel)));
- ch.Bind(eventName, x => {
- if (hasCompleted) return;
- subj.OnNext((T)x);
- });
+ ch.Bind(eventName, x => {
+ if (hasCompleted) return;
+ subj.OnNext((T) x);
+ });
+
+ disp.Add(Disposable.Create(ch.Disconnect));
+ }, RxApp.TaskpoolScheduler);
+
+ postConnect.Subscribe(_ => { },
+ ex => LogHost.Default.WarnException("Couldn't connect to Pusher", ex));
- disp.Add(Disposable.Create(ch.Disconnect));
} catch (Exception ex) {
subj.OnError(ex);
hasCompleted = true;

0 comments on commit c5c063e

Please sign in to comment.