Here are the examples of the csharp api System.Threading.Tasks.TaskFactory.StartNew(System.Action) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
738 Examples
19
Source : FunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryRun<TArg1>(TArg1 arg1, Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TArg1>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action( arg1);
if (asyncAction != null)
asyncAction();
});
}
else if (asyncAction != null)
{
asyncAction();
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncExecute<TArg1, TArg2, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TArg2, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1, arg2);
asyncAction(result);
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TArg1, TArg2, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TArg2, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1, arg2);
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TArg1, TArg2, TArg3, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, TArg3 arg3, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TArg2, TArg3, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1, arg2, arg3);
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : TreeModel.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void CreateTree()
{
TreeRoot.SelecreplacedemChanged -= OnTreeSelecreplacedemChanged;
TreeRoot.Items.Clear();
Task.Factory.StartNew(CreateTreeTask);
}
19
Source : ZeroStation.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
private bool Start()
{
using (OnceScope.CreateScope(this))
{
State = StationState.Start;
//取配置
Config = ZeroApplication.Config[StationName];
if (Config == null && !OnNofindConfig())
{
ZeroApplication.OnObjectFailed(this);
ZeroTrace.WriteError(StationName, "No config");
State = StationState.ConfigError;
return false;
}
if (Config.State == ZeroCenterState.Stop)
{
ZeroApplication.OnObjectFailed(this);
ZeroTrace.WriteError(StationName, "Uninstall");
State = StationState.ConfigError;
return false;
}
//名称初始化
RealName = ZeroIdenreplacedyHelper.CreateRealName(IsService, Name == Config.StationName ? null : Name);
Idenreplacedy = RealName.ToAsciiBytes();
ZeroTrace.SystemLog(StationName, Config.WorkerCallAddress, Name, RealName);
//扩展动作
if (!OnStart())
{
ZeroApplication.OnObjectFailed(this);
State = StationState.Failed;
return false;
}
//可执行
SystemManager.Instance.HeartJoin(Config.StationName, RealName);
//执行主任务
RunTaskCancel = new CancellationTokenSource();
Task.Factory.StartNew(Run);
}
_waitToken.Wait();
return true;
}
19
Source : WebSocketNotify.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static void Publish(string clreplacedify, string replacedle, string value)
{
if (string.IsNullOrEmpty(value))
return;
if (!Handlers.TryGetValue(clreplacedify, out var list))
return;
var array = list.ToArray();
Task.Factory.StartNew(() => PublishAsync(array, replacedle, value));
}
19
Source : DependencyFunctions.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncExecute<TArg1, TArg2, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2)
{
var func = GetDelegate<Func<TArg1, TArg2, TResult>>();
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(arg1, arg2);
asyncAction(result);
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : DependencyFunctions.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TArg1, TArg2, TArg3, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, TArg3 arg3)
{
var func = GetDelegate<Func<TArg1, TArg2, TArg3, TResult>>();
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(arg1, arg2, arg3);
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : DependencyFunctions.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TArg1, TArg2, TArg3, TArg4, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
{
var func = GetDelegate<Func<TArg1, TArg2, TArg3, TArg4, TResult>>();
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(arg1, arg2, arg3, arg4);
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : DependencyFunctions.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryRun(Action asyncAction = null)
{
var action = GetDelegate<Action>();
if (action != null)
{
Task.Factory.StartNew(() =>
{
action();
if (asyncAction != null)
asyncAction();
});
}
else if (asyncAction != null)
{
asyncAction();
}
}
19
Source : FunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TResult>(Action<TResult> asyncAction, string name = null)
{
var func = GetDelegate<Func<TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func();
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncExecute<TArg1, TResult>(Action<TResult> asyncAction, TArg1 arg1, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1);
asyncAction(result);
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncExecute<TArg1, TArg2, TArg3, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, TArg3 arg3, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TArg2, TArg3, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1, arg2, arg3);
asyncAction(result);
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncExecute<TArg1, TArg2, TArg3, TArg4, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TArg2, TArg3, TArg4, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1, arg2, arg3, arg4);
asyncAction(result);
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncRun(Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model);
if (asyncAction != null)
asyncAction();
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncRun<TArg1>(TArg1 arg1, Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel, TArg1>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model, arg1);
if (asyncAction != null)
asyncAction();
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncRun<TArg1, TArg2, TArg3>(TArg1 arg1, TArg2 arg2, TArg3 arg3, Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel, TArg1, TArg2, TArg3>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model, arg1, arg2, arg3);
if (asyncAction != null)
asyncAction();
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncRun<TArg1, TArg2, TArg3, TArg4>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel, TArg1, TArg2, TArg3, TArg4>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model, arg1, arg2, arg3, arg4);
if (asyncAction != null)
asyncAction();
});
}
throw new ArgumentException("�����ڶ�Ӧ���Ƶķ���");
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TResult>(Action<TResult> asyncAction, string name = null)
{
var func = GetDelegate<Func<TModel, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model);
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TArg1, TResult>(Action<TResult> asyncAction, TArg1 arg1, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1);
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryExecute<TArg1, TArg2, TArg3, TArg4, TResult>(Action<TResult> asyncAction, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, string name = null)
{
var func = GetDelegate<Func<TModel, TArg1, TArg2, TArg3, TArg4, TResult>>(name);
if (func != null)
{
Task.Factory.StartNew(() =>
{
var result = func(Model, arg1, arg2, arg3, arg4);
asyncAction(result);
});
}
else
{
asyncAction(default(TResult));
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryRun(Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model);
if (asyncAction != null)
asyncAction();
});
}
else if (asyncAction != null)
{
asyncAction();
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryRun<TArg1>(TArg1 arg1, Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel, TArg1>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model, arg1);
if (asyncAction != null)
asyncAction();
});
}
else if (asyncAction != null)
{
asyncAction();
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryRun<TArg1, TArg2, TArg3>(TArg1 arg1, TArg2 arg2, TArg3 arg3, Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel, TArg1, TArg2, TArg3>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model, arg1, arg2, arg3);
if (asyncAction != null)
asyncAction();
});
}
else if (asyncAction != null)
{
asyncAction();
}
}
19
Source : ModelFunctionDictionary.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public void AsyncTryRun<TArg1, TArg2, TArg3, TArg4>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, Action asyncAction = null, string name = null)
{
var action = GetDelegate<Action<TModel, TArg1, TArg2, TArg3, TArg4>>(name);
if (action != null)
{
Task.Factory.StartNew(() =>
{
action(Model, arg1, arg2, arg3, arg4);
if (asyncAction != null)
asyncAction();
});
}
else if (asyncAction != null)
{
asyncAction();
}
}
19
Source : TaskQueue.cs
with MIT License
from AiursoftWeb
with MIT License
from AiursoftWeb
public void QueueNew(Func<Task> taskFactory)
{
_pendingTaskFactories.Enqueue(taskFactory);
Task.Factory.StartNew(() =>
{
lock (this)
{
if (_engine.IsCompleted)
{
_engine = RunTasksInQueue();
}
}
});
}
19
Source : CompletableBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(5000)]
#endif
public void Observer_Dispose()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new CompletableSubject();
var to = new TestObserver<object>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
to.Dispose();
cdl.Signal();
});
cs.BlockingSubscribe(to);
cdl.Wait();
replacedert.False(cs.HasObserver());
}
}
19
Source : CompletableBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(5000)]
#endif
public void Observer_Complete_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new CompletableSubject();
var to = new TestObserver<object>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnCompleted();
});
cs.BlockingSubscribe(to);
to.replacedertResult();
}
}
19
Source : CompletableBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(5000)]
#endif
public void Observer_Error_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new CompletableSubject();
var to = new TestObserver<object>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnError(new InvalidOperationException());
});
cs.BlockingSubscribe(to);
to.replacedertFailure(typeof(InvalidOperationException));
}
}
19
Source : CompletableBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(5000)]
#endif
public void Action_Dispose()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new CompletableSubject();
var to = new TestObserver<object>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
to.Dispose();
cdl.Signal();
});
cs.BlockingSubscribe(to.OnCompleted, to.OnError, to.OnSubscribe);
cdl.Wait();
replacedert.False(cs.HasObserver());
}
}
19
Source : CompletableBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(5000)]
#endif
public void Action_Complete_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new CompletableSubject();
var to = new TestObserver<object>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnCompleted();
});
cs.BlockingSubscribe(to.OnCompleted, to.OnError);
to.replacedertResult();
}
}
19
Source : CompletableBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(5000)]
#endif
public void Action_Error_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new CompletableSubject();
var to = new TestObserver<object>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnError(new InvalidOperationException());
});
cs.BlockingSubscribe(to.OnCompleted, to.OnError);
to.replacedertFailure(typeof(InvalidOperationException));
}
}
19
Source : CompletableFromTaskTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
public void Task_Basic()
{
var count = 0;
var task = Task.Factory.StartNew(() => { count++; });
var co = task.ToCompletable();
co.Test()
.AwaitDone(TimeSpan.FromSeconds(5))
.replacedertResult();
replacedert.AreEqual(1, count);
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Observer_Dispose()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
to.Dispose();
cdl.Signal();
});
cs.BlockingSubscribe(to);
cdl.Wait();
replacedert.False(cs.HasObserver());
}
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Observer_Complete_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnCompleted();
});
cs.BlockingSubscribe(to);
to.replacedertResult();
}
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Observer_Success_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnSuccess(1);
});
cs.BlockingSubscribe(to);
to.replacedertResult(1);
}
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Observer_Error_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnError(new InvalidOperationException());
});
cs.BlockingSubscribe(to);
to.replacedertFailure(typeof(InvalidOperationException));
}
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Action_Dispose()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
to.Dispose();
cdl.Signal();
});
cs.BlockingSubscribe(to.OnSuccess, to.OnError, to.OnCompleted, to.OnSubscribe);
cdl.Wait();
replacedert.False(cs.HasObserver());
}
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Action_Complete_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnCompleted();
});
cs.BlockingSubscribe(to.OnSuccess, to.OnError, to.OnCompleted);
to.replacedertResult();
}
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Action_Success_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnSuccess(1);
});
cs.BlockingSubscribe(to.OnSuccess, to.OnError, to.OnCompleted);
to.replacedertResult(1);
}
}
19
Source : MaybeBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Action_Error_Async()
{
for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
{
var cs = new MaybeSubject<int>();
var to = new TestObserver<int>();
var cdl = new CountdownEvent(1);
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
cs.OnError(new InvalidOperationException());
});
cs.BlockingSubscribe(to.OnSuccess, to.OnError, to.OnCompleted);
to.replacedertFailure(typeof(InvalidOperationException));
}
}
19
Source : MaybeWaitTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
public void NoValue_Cancel_Wait()
{
var cs = new MaybeSubject<int>();
var cts = new CancellationTokenSource();
try
{
Task.Factory.StartNew(() =>
{
while (!cs.HasObserver()) ;
Thread.Sleep(100);
cts.Cancel();
});
cs
.Wait(cts: cts);
replacedert.Fail();
}
catch (OperationCanceledException)
{
// expected
}
replacedert.False(cs.HasObserver());
}
19
Source : BlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Basic_Observer_Dispose()
{
var to = new TestObserver<int>();
var sad = new SinglereplacedignmentDisposable();
var cdl = new CountdownEvent(1);
var us = new UnicastSubject<int>();
Task.Factory.StartNew(() =>
{
while (to.ItemCount != 5) ;
sad.Dispose();
cdl.Signal();
});
Task.Factory.StartNew(() =>
{
us.Emit(1, 2, 3, 4, 5);
cdl.Signal();
});
us.BlockingSubscribe(to, d => sad.Disposable = d);
to.replacedertValuesOnly(1, 2, 3, 4, 5);
replacedert.True(cdl.Wait(3000));
replacedert.False(us.HasObserver());
}
19
Source : BlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Basic_Action_Dispose()
{
var to = new TestObserver<int>();
var sad = new SinglereplacedignmentDisposable();
var cdl = new CountdownEvent(2);
var us = new UnicastSubject<int>();
Task.Factory.StartNew(() =>
{
while (to.ItemCount != 5) ;
sad.Dispose();
cdl.Signal();
});
Task.Factory.StartNew(() =>
{
us.Emit(1, 2, 3, 4, 5);
cdl.Signal();
});
us.BlockingSubscribe(to.OnNext, to.OnError, to.OnCompleted, d => sad.Disposable = d);
to.replacedertValuesOnly(1, 2, 3, 4, 5);
replacedert.True(cdl.Wait(3000));
replacedert.False(us.HasObserver());
}
19
Source : BlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Basic_While_Dispose()
{
var to = new TestObserver<int>();
var sad = new SinglereplacedignmentDisposable();
var cdl = new CountdownEvent(2);
var us = new UnicastSubject<int>();
Task.Factory.StartNew(() =>
{
while (to.ItemCount != 5) ;
sad.Dispose();
cdl.Signal();
});
Task.Factory.StartNew(() =>
{
us.Emit(1, 2, 3, 4, 5);
cdl.Signal();
});
us.BlockingSubscribeWhile(v => {
to.OnNext(v);
return true;
}, to.OnError, to.OnCompleted, d => sad.Disposable = d);
to.replacedertValuesOnly(1, 2, 3, 4, 5);
replacedert.True(cdl.Wait(3000));
replacedert.False(us.HasObserver());
}
19
Source : ObservableSourceBlockingSubscribeTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
#if NETFRAMEWORK
[Timeout(10000)]
#endif
public void Basic_Action_Dispose()
{
var to = new TestObserver<int>();
var sad = new SinglereplacedignmentDisposable();
var cdl = new CountdownEvent(2);
var us = new MonocastSubject<int>();
Task.Factory.StartNew(() =>
{
while (to.ItemCount != 5) ;
sad.Dispose();
cdl.Signal();
});
Task.Factory.StartNew(() =>
{
us.Emit(1, 2, 3, 4, 5);
cdl.Signal();
});
us.BlockingSubscribe(to.OnNext, to.OnError, to.OnCompleted, d => sad.Disposable = d);
to.replacedertValuesOnly(1, 2, 3, 4, 5);
replacedert.True(cdl.Wait(3000));
replacedert.False(us.HasObserver());
}
19
Source : ObservableSourceFromTaskTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
public void Plain_Basic_To()
{
Task.Factory.StartNew(() => { }).ToObservableSource<int>()
.Test()
.AwaitDone(TimeSpan.FromSeconds(5))
.replacedertResult();
}
19
Source : ObservableSourceFromTaskTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
public void Plain_Error()
{
ObservableSource.FromTask<int>(Task.Factory.StartNew(() => { throw new InvalidOperationException(); }))
.Test()
.AwaitDone(TimeSpan.FromSeconds(5))
.replacedertFailure(typeof(AggregateException))
.replacedertCompositeError(typeof(InvalidOperationException));
}
19
Source : MaybeFromTaskTest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
[Test]
public void Task_Basic()
{
var count = 0;
var task = Task.Factory.StartNew(() => { count++; });
var co = task.ToMaybe<int>();
co.Test()
.AwaitDone(TimeSpan.FromSeconds(5))
.replacedertResult();
replacedert.AreEqual(1, count);
}
See More Examples