system.reactive

How do I get an IObservable to push the newest value upon subscription

不打扰是莪最后的温柔 提交于 2019-12-10 14:44:15
问题 Usually when you subscribe to the changes of a value you are also interested in knowing the initial value. I want my IObservable to cache the latest (or initial) value and push that value on subscription. When using plain events I often end up with code that looks like x.SomeEvent += SomeEventHandler; SomeEventHandler(x, EventArgs.Empty); Using IObservable I was hoping to wrap the event with something that pushes the initial value. If I have multiple subscribers they should receive the newest

Reactive Extensions (Rx) - sample with last known value when no value is present in interval

守給你的承諾、 提交于 2019-12-10 14:34:24
问题 I have an observable stream that produces values at inconsistent intervals like this: ------1---2------3----------------4--------------5--- And I would like to sample this but without any empty samples once the a value has been produced: ------1---2------3----------------4--------------5----- ----_----1----2----3----3----3----4----4----4----5----5 I obviously thought Replay().RefCount() could be used here to provide the last known value to Sample() but as it doesn't re-subscribe to the source

ToAsyncEnumerable().Single() vs SingleAsync()

大城市里の小女人 提交于 2019-12-10 13:46:59
问题 I'm constructing and executing my queries in a way that's independent of EF-Core, so I'm relying on IQueryable<T> to obtain the required level of abstraction. I'm replacing awaited SingleAsync() calls with awaited ToAsyncEnumerable().Single() calls. I'm also replacing ToListAsync() calls with ToAsyncEnumerable().ToList() calls. But I just happened upon the ToAsyncEnumerable() method so I'm unsure I'm using it correctly or not. To clarify which extension methods I'm referring to, they're

ReactiveUI: Testing progress indicator visibility while ReactiveAsyncCommand executes

谁说我不能喝 提交于 2019-12-10 11:56:03
问题 I have a ReactiveAsyncCommand that for the moment are just sleeping for a while: public ReactiveAsyncCommand SignIn { get; private set; } //from constructor: SignIn = new ReactiveAsyncCommand(this.WhenAny(x => x.Username, x => x.Password, (u, p) => !string.IsNullOrWhiteSpace(u.Value) && !string.IsNullOrWhiteSpace(p.Value))); SignIn.RegisterAsyncAction(_ => Thread.Sleep(4000)); I want to show a progress indicator while the command executes, so I have made a property to bind its visibility

Continue using subscription after exception

孤街醉人 提交于 2019-12-10 11:41:07
问题 I was trying out a "type-to-search" Reactive-Extensions sample which takes a string from a textbox (WPF app if it matters) and does a potentially-lengthy server-side search (simulated in my case with a Thread.Sleep) and displays the result(s) in a listbox. The key features of this particular "module" would be : async search; UI is not frozen while searching throttled; typing fast would not generate a server-side search for each keystroke distinct searching; after searching for "asd" and

Why is this double-click detection code unreliable?

心不动则不痛 提交于 2019-12-10 11:28:32
问题 I'm trying to learn Rx through some simple challenges, first by detecting double-clicks by watching only MouseUp events. I came up with the following solution (this code is compilable by creating a WPF project and adding the Reactive Extensions NuGet package): using System; using System.Reactive.Linq; using System.Windows.Input; namespace WpfApplication1 { public partial class MainWindow { public MainWindow() { InitializeComponent(); var clickEvents = Observable .FromEventPattern

Combining latest from an observable of observables

蓝咒 提交于 2019-12-10 11:26:55
问题 Suppose I have a set of URIs that I am monitoring for availability. Each URI is either "up" or "down", and new URIs to monitor may be added to the system at any time: public enum ConnectionStatus { Up, Down } public class WebsiteStatus { public string Uri { get; set; } public ConnectionStatus Status { get; set; } } public class Program { static void Main(string[] args) { var statusStream = new Subject<WebsiteStatus>(); Test(statusStream); Console.WriteLine("Done"); Console.ReadKey(); }

How to use Observable.FromEvent with static events?

巧了我就是萌 提交于 2019-12-10 11:08:54
问题 I am trying to use Reactive Extensions to write code to handle an asynchronous call where both the initiating method and the completed event are static. I can't use var languageSetsLoaded = Observable .FromEvent<LoadLanguageSetsCompletedEventArgs>( LanguageManager, "LanguageSetsLoaded") as LanguageManager is a static class rather than an instance, so I tried var languageSetsLoaded = Observable .FromEvent<LoadLanguageSetsCompletedEventArgs>( h => LanguageManager.LanguageSetsLoaded += h, h =>

Rx: Ignoring updates caused by Subscribers

会有一股神秘感。 提交于 2019-12-10 11:08:23
问题 I'm having problems figuring out how to do this. I have two instances (source & target) that implement INotifyPropertyChanged and I'm tracking the PropertyChanged event for both. What I want to do is run an action any time source.PropertyChanged is raised until target.PropertyChanged is raised. I can do that just fine like this: INotifyPropertyChanged source; INotifyPropertyChanged target; var sourcePropertyChanged = Observable .FromEvent<PropertyChangedEventArgs>(source, "PropertyChanged")

Momentarily ignore values from Observable when another Observable provides a value

萝らか妹 提交于 2019-12-10 11:04:03
问题 I need to ignore Observable values for a period of time when another Observable provides a value. Currently, my implementation uses a variable to control blocking (or ignoring). bool block = false; var blocker = observable1.Do(_ => block = true ) .Throttle( _ => Observable.Timer(_timeToBlock) .Subscribe( _ => block = false )); var receiver = observable2.Where( i => !block && SomeCondition(i) ) .Subscribe( i=> EvenMoreStuff(i) ); Is there a more Rx way to do this, by combining these two