Permalink
Browse files

Issue #99

- Changed SynchronousInvoker to execute its tasks outside of the SynchronizationContext
  • Loading branch information...
linvi committed Feb 10, 2016
1 parent 9de3321 commit 980fed6135624d04306d2d52aa18967ff5a7515b
@@ -1,24 +1,27 @@
using System.Threading.Tasks;
namespace Tweetinvi.Core.Helpers
{
public interface ISynchronousInvoker
{
T GetResultSyncrhonously<T>(Task<T> task);
void ExecuteSynchronously(Task task);
}
public class SynchronousInvoker : ISynchronousInvoker
{
public T GetResultSyncrhonously<T>(Task<T> task)
{
task.Wait();
return task.Result;
}
public void ExecuteSynchronously(Task task)
{
task.Wait();
}
}
using System;
using System.Threading.Tasks;
namespace Tweetinvi.Core.Helpers
{
public interface ISynchronousInvoker
{
T GetResultSyncrhonously<T>(Func<Task<T>> asyncMethod);
void ExecuteSynchronously(Func<Task> asyncMethod);
}
public class SynchronousInvoker : ISynchronousInvoker
{
public T GetResultSyncrhonously<T>(Func<Task<T>> asyncMethod)
{
Task<T> task = TaskEx.Run(() => asyncMethod());
task.Wait();
return task.Result;
}
public void ExecuteSynchronously(Func<Task> asyncMethod)
{
Task task = TaskEx.Run(() => asyncMethod());
task.Wait();
}
}
}
@@ -84,7 +84,7 @@ public class FilteredStream : TrackedStream, IFilteredStream
public void StartStreamMatchingAnyCondition()
{
Action startStreamAction = () => _synchronousInvoker.ExecuteSynchronously(StartStreamMatchingAnyConditionAsync());
Action startStreamAction = () => _synchronousInvoker.ExecuteSynchronously(() => StartStreamMatchingAnyConditionAsync());
_singleAggregateExceptionThrower.ExecuteActionAndThrowJustOneExceptionIfExist(startStreamAction);
}
@@ -132,7 +132,7 @@ public async Task StartStreamMatchingAnyConditionAsync()
public void StartStreamMatchingAllConditions()
{
Action startStreamAction = () => _synchronousInvoker.ExecuteSynchronously(StartStreamMatchingAllConditionsAsync());
Action startStreamAction = () => _synchronousInvoker.ExecuteSynchronously(() => StartStreamMatchingAllConditionsAsync());
_singleAggregateExceptionThrower.ExecuteActionAndThrowJustOneExceptionIfExist(startStreamAction);
}
@@ -90,7 +90,7 @@ public async Task StartStreamAsync(Func<string, bool> processObject, Func<ITwitt
await TaskEx.Run(() =>
{
streamTask.Start();
});
}).ConfigureAwait(false);
}
private void StreamTaskStarted(object sender, EventArgs eventArgs)
@@ -39,7 +39,7 @@ public class SampleStream : TweetStream, ISampleStream
public void StartStream()
{
Action startStreamAction = () => _synchronousInvoker.ExecuteSynchronously(StartStream(Resources.Stream_Sample));
Action startStreamAction = () => _synchronousInvoker.ExecuteSynchronously(() => StartStream(Resources.Stream_Sample));
_singleAggregateExceptionThrower.ExecuteActionAndThrowJustOneExceptionIfExist(startStreamAction);
}
@@ -216,7 +216,7 @@ private async Task<StreamReader> GetStreamReader(HttpClient client, ITwitterQuer
var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
var body = await response.Content.ReadAsStreamAsync();
var body = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return new StreamReader(body, Encoding.GetEncoding("utf-8"));
}
Oops, something went wrong.

0 comments on commit 980fed6

Please sign in to comment.