Click here to Skip to main content
15,892,298 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: BinaryFormatter a malware nest ? so, it comes to this ? Pin
Gerry Schmitz19-Dec-21 8:06
mveGerry Schmitz19-Dec-21 8:06 
GeneralThe magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
Super Lloyd18-Dec-21 12:18
Super Lloyd18-Dec-21 12:18 
GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
honey the codewitch18-Dec-21 16:56
mvahoney the codewitch18-Dec-21 16:56 
GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
Super Lloyd18-Dec-21 17:02
Super Lloyd18-Dec-21 17:02 
GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
honey the codewitch18-Dec-21 17:05
mvahoney the codewitch18-Dec-21 17:05 
GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
Super Lloyd18-Dec-21 17:09
Super Lloyd18-Dec-21 17:09 
GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
honey the codewitch18-Dec-21 17:34
mvahoney the codewitch18-Dec-21 17:34 
GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
Super Lloyd18-Dec-21 17:58
Super Lloyd18-Dec-21 17:58 
I think you missed something......

To answer the last question first, the only (very good) practical usage I found for IAsyncEnumrable so far is to enumerate events asynchronously. Events, as you know, happens later, much later, if at all!

So, to your first question:

Let's detail the mouse drag operation

When mouse down happen, I want to wait on next mouse move. I could have written code like that await NextMouseMoveasync()

This would have required lots of boilerplate code. Instead I started my work with reactive, an observable library, which let you manipulate, compose, analyze and action event stream (operators documentation). Really help for that kind of stuff.

It's great, but doesnt use async and the callback syntax for action on event can be complicated when you do lots of stuff. Anyway I much prefer async code to callback code. It's the same thing, but feels more.. straightforward? easier to read?
I can live with the funny exception callstack, but I so much more enjoy the improved code layout.

So next step was to turn this IObservable event stream into an IAsyncEnumerable, here just use the extension method ToAsyncEnumerable().

and voila:

when I write
await foreach (var event Observable.Merge(MouseMove, MouseUp).ToAsynEnumerable())

I am asynchronously waiting for either next mouse move of mouse up, and handling it in the foreach body.
It's 100% asynchronous, what is enumerated here are mouse events, the foreach body is run on each mouse move event, which happens like once every 0.05 seconds, at best! And maybe not at all!

Does my explanation help shed some light?
Perhaps I should have trimmed my initial sample a bit.... mm.. Roll eyes | :rolleyes: Laugh | :laugh:
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 19-Dec-21 0:03am.

GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
honey the codewitch18-Dec-21 18:03
mvahoney the codewitch18-Dec-21 18:03 
GeneralRe: The magic of IAsyncEnumerable and IObservable in action (code show off, sorry) Pin
Super Lloyd18-Dec-21 18:16
Super Lloyd18-Dec-21 18:16 
GeneralIt had to happen at some point Pin
honey the codewitch18-Dec-21 11:18
mvahoney the codewitch18-Dec-21 11:18 
GeneralRe: It had to happen at some point Pin
Super Lloyd18-Dec-21 11:57
Super Lloyd18-Dec-21 11:57 
GeneralRe: It had to happen at some point Pin
honey the codewitch18-Dec-21 11:58
mvahoney the codewitch18-Dec-21 11:58 
GeneralRe: It had to happen at some point PinPopular
PIEBALDconsult18-Dec-21 12:12
mvePIEBALDconsult18-Dec-21 12:12 
GeneralRe: It had to happen at some point Pin
Super Lloyd18-Dec-21 12:21
Super Lloyd18-Dec-21 12:21 
GeneralRe: It had to happen at some point Pin
enhzflep19-Dec-21 10:19
enhzflep19-Dec-21 10:19 
GeneralRe: It had to happen at some point Pin
Randor 18-Dec-21 22:44
professional Randor 18-Dec-21 22:44 
GeneralRe: It had to happen at some point Pin
honey the codewitch19-Dec-21 0:16
mvahoney the codewitch19-Dec-21 0:16 
GeneralRe: It had to happen at some point Pin
Randor 19-Dec-21 0:48
professional Randor 19-Dec-21 0:48 
GeneralRe: It had to happen at some point Pin
honey the codewitch19-Dec-21 1:05
mvahoney the codewitch19-Dec-21 1:05 
GeneralRe: It had to happen at some point Pin
Randor 19-Dec-21 1:24
professional Randor 19-Dec-21 1:24 
GeneralRe: It had to happen at some point Pin
honey the codewitch19-Dec-21 1:51
mvahoney the codewitch19-Dec-21 1:51 
GeneralRe: It had to happen at some point Pin
Randor 19-Dec-21 2:00
professional Randor 19-Dec-21 2:00 
GeneralRe: It had to happen at some point Pin
honey the codewitch19-Dec-21 2:38
mvahoney the codewitch19-Dec-21 2:38 
GeneralXamarin anyone? Pin
Gerry Schmitz18-Dec-21 7:42
mveGerry Schmitz18-Dec-21 7:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.