Reactive Extensions API in depth: Primitives
- Posted: Nov 24, 2009 at 9:57 AM
- 56,883 Views
- 8 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Does Return call OnNext after someone subscribes, or calls it OnNext during the call to Subscribe? If I call Subscribe, I get back an IDisposable, but do I get the change to call Dispose before the Observable starts pushing values?
In other words, what if I want this method:
IObservable<T> ToObservable<T>(this IEnumerable<T> xs) { return new IObservable<T>() { IDisposable Subscribe(IObserver<T> obs) { foreach (var x in xs) obs.OnNext(x); obs.OnDone(); return someDisposable(); // Don't know how to implement } } }Can I unsubscribe from the IObservable before or during the series of OnNext calls?
Looks like these definitions
That is,
T Never<T>() { while (true); return default(T); } void Empty() { } Func<T> Return<T>(T x) { return () => x; } Action Throw<T>(T x) where T: Exception { return () => { throw x; }; }Primitives
Primitives - Asynchronous
var a1 = Observable.Start(() => { while (true); }); var a2 = Observable.Start(() => { }); var a3 = Observable.Start(() => 42); var a4 = Observable.Start(() => { throw new Exception(); });Need to try out but that looks about right to me...
Bottom isn't really a type. I'd say something like:
Where of course:
If it doesn't terminate, does the type matter, except that it's "bottom" - which should be every type as well?
The reason I write it like functions is because if we look at an IObservable then it looks like a statement sequence to me, especially after the Beckman interview where I believe Erik showed this connection in that you could model an imperative program of sequences of statements as these things.
The primitives are then ways to model basic ways that a statement can behave. Some statements never return. Some statements are constant assignments (or we could say assignment expressions). Some statements throw exceptions. Some statements never terminate. To Erik the last two would be somewhat similar according to previous answers.
And so the first functions defined would mimic this behavior in that you could write
var s1 = Never(); // s1 is bottom, doesn't ever return Empty<int>(); // void - we can't assign that var s3 = Return(42)(); // s3 = 42 Throw(new ForFunException("hah hah"))(); // bottom againI guess one of the reasons for providing Never out of the box (that is, in the box), is that if you can be more clever about the implementation instead of saying while(true); simply never call OnNext or OnComplete; no reason to make the CPU hot.
Good question.
We have gone back and forth on this issue over time, but I expect in the long run that the user can choose either one since they both have meaningful semantics.
In Haskell ⊥ has type forall a :: a.
bottom :: a
bottom = bottom
All Rx combinators have non-blocking subscribe, so OnNext is called on the SynchronizationContext. For Return's case this means that if you subscribe on the thread owning the SynchronizationContext you're guaranteed to be called after Subscribe returns, or if you're calling from a different thread, you're called either during or after your call to subscribe. In the first case, calling Dispose should guarantee not to make the OnNext call, where the latter you might or might not succeed to cancel subscription.
Hi,
I am working on silverlight application.
I have an error on following code snips
Please ans ..
Observable.Start(() =>
{
Thread.Sleep(3000);
return "Hello There";
}).Subscribe(Value => button.Content = Value);
};
this code is not working VS2008 with silverlight application.
It raised error "Specified method is not supported"
Remove this comment
Remove this thread
close