﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on A surprise TaskCancelledException</title><description>Omer,
None of those things are actually needed or required.

BatchAsync is being called from SaveChangesAsync, and there is usually only ever to be one of them.</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment9</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment9</guid><pubDate>Fri, 09 Sep 2011 22:38:51 GMT</pubDate></item><item><title>Omer Mor commented on A surprise TaskCancelledException</title><description>I'll give it a shot later.
I guess the basic idea would be to treat it as a stream of command batches, and project it (select) into a stream of responses. Along the way we could push the handling into a dedicated thread, or use the thread/task pool. we might also easily "batch our batches" based on count or time if that could increase our performance. we might also throttle against overloading / DoS attacks for example. 

I cross-posted your example in the Rx forums, for help getting an expert opinion on this (http://social.msdn.microsoft.com/Forums/en/rx/thread/3cd72a7e-fba8-4c81-9113-36ef78e2ac54).


</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment8</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment8</guid><pubDate>Fri, 09 Sep 2011 21:32:40 GMT</pubDate></item><item><title>Ayende Rahien commented on A surprise TaskCancelledException</title><description>Omer,
Most of what we are doing are actually do computation of a single value.
For example, take a look at the type of things we do here:

public Task&lt;BatchResult[]&gt; BatchAsync(ICommandData[] commandDatas)
{
	var metadata = new RavenJObject();
	AddTransactionInformation(metadata);
	var req = jsonRequestFactory.CreateHttpJsonRequest(this, url + "/bulk_docs", "POST", metadata, credentials, convention);
	var jArray = new RavenJArray(commandDatas.Select(x =&gt; x.ToJson()));
	var data = jArray.ToString(Formatting.None);

	return Task.Factory.FromAsync(req.BeginWrite, req.EndWrite, data, null)
		.ContinueWith(writeTask =&gt; req.ReadResponseStringAsync())
		.Unwrap()
		.ContinueWith(task =&gt;
		{
			string response;
			try
			{
				response = task.Result;
			}
			catch (WebException e)
			{
				var httpWebResponse = e.Response as HttpWebResponse;
				if (httpWebResponse == null ||
					httpWebResponse.StatusCode != HttpStatusCode.Conflict)
					throw;
				throw ThrowConcurrencyException(e);
			}
			return JsonConvert.DeserializeObject&lt;BatchResult[]&gt;(response, new JsonToJsonConverter());
		});

}


can you should me how this would be written, Rx style?</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment7</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment7</guid><pubDate>Fri, 09 Sep 2011 19:42:57 GMT</pubDate></item><item><title>Omer Mor commented on A surprise TaskCancelledException</title><description>This is from SO: http://stackoverflow.com/questions/2542764/tpl-v-s-reactive-framework
In general, tasks abstract single (future) values/computations and observables abstract streams of (future) values/computations. You could treat the single value case as a special case of a single value stream, and only use Rx. However if your use case primarily deals with single values, TPL might be a better feat.
Also, Rx allows for much better composition (using LINQ).

From my experience, Rx works best when replacing events.

For me - Rx was a mind enhancing experience, which changed the way I perceive many problems. I advise you to take a leap of faith here, and invest some time in this ingenious framework.

</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment6</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment6</guid><pubDate>Fri, 09 Sep 2011 19:36:27 GMT</pubDate></item><item><title>Ayende Rahien commented on A surprise TaskCancelledException</title><description>Omer,
I would love to see some real examples of TPL vs. RX code, because I haven't really been able to figure out that.
And I think that with C# 5.0, TPL is a better alternative</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment5</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment5</guid><pubDate>Fri, 09 Sep 2011 19:21:39 GMT</pubDate></item><item><title>Omer Mor commented on A surprise TaskCancelledException</title><description>Oren,
have you gotten in Rx yet (as in fully grokked it)?
You seem to use tasks a lot. I myself use Rx for most of my asynchronous needs. It is usually a better concept. And regarding this case, it has Observable.Empty or Observable.Return(null) helpers which could your case, had you been using Rx.</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment3</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment3</guid><pubDate>Fri, 09 Sep 2011 18:30:34 GMT</pubDate></item><item><title>Frank Quednau commented on A surprise TaskCancelledException</title><description>3 lines of code that can be extracted into some static property hardly counts as a difficult way to create a completed task ;)</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment2</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment2</guid><pubDate>Fri, 09 Sep 2011 10:49:36 GMT</pubDate></item><item><title>Remco Blok commented on A surprise TaskCancelledException</title><description>The Async CTP has a static TaskEx.FromResult method that does exactly what you do:

public static Task&lt;TResult&gt; FromResult&lt;TResult&gt;(TResult result)
{
    TaskCompletionSource&lt;TResult&gt; source = new TaskCompletionSource&lt;TResult&gt;(result);
    source.TrySetResult(result);
    return source.Task;
}

Expect this TaskEx class to be merged with the Task class for .Net 5.</description><link>http://ayende.com/88065/a-surprise-taskcancelledexception#comment1</link><guid>http://ayende.com/88065/a-surprise-taskcancelledexception#comment1</guid><pubDate>Fri, 09 Sep 2011 09:15:14 GMT</pubDate></item></channel></rss>