public IDisposable Start( IObservable <BuildProject> buildArgs, IScheduler scheduler = null) { scheduler = scheduler ?? Scheduler.Default; var refresh = _refresh.Merge(Messages.TryParse(ReifyRequired.MessageType, ReifyRequired.ReadDataFrom)); var disposable = _simulatorHost.SubscribeUsing(host => { var endedMessages = host.Messages.TryParse(Ended.MessageType, Ended.ReadDataFrom); return(Disposable.Combine( Disposable.Create(() => _proxy.RemoveProject(Port)), _project.Mutations .Merge(_project.Mutations .OfType <ReifyRequired>().StartWith(new ReifyRequired()) .WithLatestFromBuffered(_project.LatestSource, (signal, data) => data.ToArray()) .Do( docs => { foreach (var doc in docs) { doc.LiveDocument.UpdateSimulatorIds(); } }) .Throttle(TimeSpan.FromSeconds(1.0 / 20.0), scheduler) .ObserveOn(Application.MainThread) .Select(docs => (IBinaryMessage) new GenerateBytecode(Guid.NewGuid(), List.ToImmutableList(docs.Select(doc => doc.FileContents))))) .Merge(_rebuild.StartWith(new object()) .CombineLatest(buildArgs, (_, t) => t) .WithLatestFromBuffered(_project.BuildOutputDirectory, (args, buildDir) => { var output = _buildOutputDirGenerator.Acquire(buildDir / new DirectoryName("Local") / new DirectoryName("Designer")); args.OutputDir = output.NativePath; args.Id = Guid.NewGuid(); return args; }) .Do(args => _proxy.AddProject( Port, AccessCode.ToString(), args.ProjectPath, args.Defines.ToArray()))) .Merge(refresh .WithLatestFromBuffered(_project.LatestSource, (signal, data) => data.ToArray()) .Select(docs => new GenerateBytecode(Guid.NewGuid(), List.ToImmutableList(docs.Select(doc => doc.FileContents)))) .SkipUntil(endedMessages)) .Subscribe(host.Send), endedMessages.Subscribe(ended => { if (ended.Command.Type == BuildProject.MessageType) { _buildOutputDirGenerator.Release(ended.BuildDirectory); Refresh(); } }))); }); _simulatorHost.Connect(); return(disposable); }