« first day (1009 days earlier)      last day (3140 days later) » 

12:17 AM
@ReedCopsey you around?
I'm trying to abuse await/async
 
yes
what's up?
 
Trying to set up a set of parallel tasks... with return values
and take all the return values and put them in another collection
and return that to the caller
WaitAll is very unhappy about that
WhenAll is happy though
thats weird
looks like I needed to go that direction anyways to await it
Will the return values be in Result?
(of each task I mean)
In other words...
            List<int> idLst = idsEnumerable.ToList();

            var pendingTasks = new Dictionary<int, Task<IEnumerable<MyData>>>();
            foreach (int id in IDlist)
            {
                pendingTasks.Add(id, proxy.GetMyData(Id));
            }

            await Task.WhenAll(pendingTasks.Values);

            var returnData = new Dictionary<int, IEnumerable<MyData>>();
            foreach (KeyValuePair<int, Task<IEnumerable<MyData>>> data in pendingTasks)
            {
                returnData.Add(versionInfo.Key, versionInfo.Value.Result);
 
if you await Task.WhenAll(...) you get the results
 
Does that look right?
 
var results = await Task.WhenAll();
 
12:26 AM
Way too many <> in this code
@JohanLarsson Right, but I need to take all that data and construct a dictionary to return
 
feels like pendingTasks.ToDictionary(x=>x.Key, x => x.Value.Result)
but same thing
also ConfigreAwait(true|false)
be explicit about it
convention is GetMyDataAsync
 
supposed to ConfigureAwait(false) fight?
And I just wrapped that in a Task.Run
the next call has to be synchronous
and I like the ToDictionary trick :)
 
everything that does not need to be scheduled back to context is configureawait(false)
should be the default, really stange design & poor name
 
got it
 
if you are in a clickhandler and assign the result to a textbox you want true
 
12:32 AM
sure, this is all backend code
 
I would expect a decent perf gain from configureawait(false) but have no data
we have reed though
 
@ReedCopsey Any other pitfalls in my code?
 
feels like it must simplify the statemachine a lot and no wait for scheduling
 
it all builds at least :)
no await warnings either, so I must have done something right
 
@BradleyDotNET I'm confused by your code, actually
 
12:36 AM
uh oh
 
in foreach (KeyValuePair<int, Task<IEnumerable<MyData>>> data in pendingTasks), you never use data ?
 
thats never good
 
what is versionInfo?
 
whoops
obfuscation screw up
 
12:36 AM
versionInfo was the real name
 
you should be able to simplify dramatically
 
1 line
 
that would be one heck of a one liner
 
Chat.ReedLine()
 
var pendingTasks = idsEnumerable.ToDictionary(i => i, i => proxy.GetMyData(i));
await Task.WhenAll(pendingTasks.Values);
return pendingTasks.ToDictionary(p => p.Key, p => p.Value.Result);
that's the same, right?
 
12:39 AM
yeah, looks same
 
Makes sense
I can collapse the other dictionary creation
 
what does GetMyData do with i btw? Not an id that is returned in the result?
iirc dictionary is a pretty expensive allocation
 
No, the function gets the real proxy in a cached list
 
probably better to make pendingTasks a List, TBH
 
and invokes the same function on it
not the greatest design
but I have to keep the Id around for the return value
 
12:41 AM
array and index?
 
@ReedCopsey How would you keep the ID associated?
@JohanLarsson If only
 
well, that's the rub - make a List<KeyValuePair<>>
but I've got to run
 
gotcha
Ok, thanks!
I have to go as well, but I appreciate the advice
 
yeah - creating a dictionary for the first is expensive - so avoiding it would help
but the code would be uglier ;)
do you want/need all fo the tasks to be runing at the same time?
 
yeah
could be hundreds
 
12:43 AM
then that's probably the best option
 
rather not wait for each network call to finish before running the next
ok, great
 
simpler to avoid the dict, but if you're doing hundreds, that'll be in the noise ;)
 
yeah
thanks again!
 
the first can be an array imo
er, the ints are probably not zero based
 
 
5 hours later…
5:45 AM
hi
 

« first day (1009 days earlier)      last day (3140 days later) »