本文整理汇总了C#中AsyncSubject.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncSubject.Subscribe方法的具体用法?C# AsyncSubject.Subscribe怎么用?C# AsyncSubject.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncSubject
的用法示例。
在下文中一共展示了AsyncSubject.Subscribe方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: each_subscriber_is_scheduled_individually
public void each_subscriber_is_scheduled_individually()
{
ManualScheduler scheduler = new ManualScheduler();
AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);
StatsObserver<int> statsA = new StatsObserver<int>();
StatsObserver<int> statsB = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
subject.Subscribe(statsA);
subject.Subscribe(statsB);
scheduler.RunNext();
Assert.IsTrue(statsA.NextCalled);
Assert.IsFalse(statsB.NextCalled);
scheduler.RunNext();
Assert.IsTrue(statsB.NextCalled);
}
示例2: AsyncSubject
///<summary>
///With AsyncSubject<T> ,the subscriber will only get all the last publication made.
///Simply, AsyncSubject has a one value buffer. The publication is made only on the OnCompleted() call.
///</summary>
private static void AsyncSubject()
{
var subject = new AsyncSubject<string>();
subject.OnNext("a");
subject.OnNext("b");
subject.OnNext("c");
subject.Subscribe(Console.WriteLine);
subject.OnCompleted();
}
示例3: Start
private void Start()
{
//BehaviorSubjectは初期値を設定できる
asyncSubject = new AsyncSubject<int>();
/*
Subscribe後にOnNextを繰り返しても値が発行されず、OnCompletedを実行した際に初めてOnNextが通知されるところ確認しよう
また、その時のOnNextの値は最後の値1つだけになっていることも確認しよう
*/
// Subscribeボタンが押されたらSubjectをSubscribeしてresultTextに表示する
subscribeButton.OnClickAsObservable().Subscribe(_ =>
{
if (asyncSubject != null)
{
asyncSubject.Subscribe(
time => resultText.text += time.ToString() + " ", //OnNext
() => resultText.text += "OnCompleted "); //OnCompleted
}
});
// OnNextボタンが押されたら今が何度目のOnNextであるかを発行する
onNextButton.OnClickAsObservable().Subscribe(_ =>
{
if (asyncSubject != null)
{
asyncSubject.OnNext(++onNextCount);
}
});
// OnCompletedボタンが押されたらOnCompletedを発行する
onCompletedButton.OnClickAsObservable().Subscribe(_ =>
{
if (asyncSubject != null)
{
asyncSubject.OnCompleted();
}
});
// Resetボタンが押されたら全体を初期化する
resetButton.OnClickAsObservable().Subscribe(_ =>
{
if (asyncSubject != null)
{
asyncSubject.OnCompleted();
}
asyncSubject = new AsyncSubject<int>();
resultText.text = "";
onNextCount = 0;
});
}
示例4: scheduler_is_used_to_distribute_values
public void scheduler_is_used_to_distribute_values()
{
ManualScheduler scheduler = new ManualScheduler();
AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);
StatsObserver<int> statsA = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
subject.Subscribe(statsA);
Assert.IsFalse(statsA.NextCalled);
scheduler.RunNext();
Assert.IsTrue(statsA.NextCalled);
}
示例5: next_and_complete_are_scheduled_separately
public void next_and_complete_are_scheduled_separately()
{
ManualScheduler scheduler = new ManualScheduler();
AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);
StatsObserver<int> statsA = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
subject.Subscribe(statsA);
Assert.AreEqual(1, scheduler.QueueSize);
scheduler.RunNext();
Assert.IsTrue(statsA.NextCalled);
Assert.IsFalse(statsA.CompletedCalled);
Assert.AreEqual(1, scheduler.QueueSize);
scheduler.RunNext();
Assert.IsTrue(statsA.CompletedCalled);
}
示例6: HasObservers_OnError
public void HasObservers_OnError()
{
var s = new AsyncSubject<int>();
Assert.IsFalse(s.HasObservers);
var d = s.Subscribe(_ => { }, ex => { });
Assert.IsTrue(s.HasObservers);
s.OnNext(42);
Assert.IsTrue(s.HasObservers);
s.OnError(new Exception());
Assert.IsFalse(s.HasObservers);
}
示例7: HasObservers_OnCompleted
public void HasObservers_OnCompleted()
{
var s = new AsyncSubject<int>();
Assert.IsFalse(s.HasObservers);
var d = s.Subscribe(_ => { });
Assert.IsTrue(s.HasObservers);
s.OnNext(42);
Assert.IsTrue(s.HasObservers);
s.OnCompleted();
Assert.IsFalse(s.HasObservers);
}
示例8: HasObservers_Dispose2
public void HasObservers_Dispose2()
{
var s = new AsyncSubject<int>();
Assert.IsFalse(s.HasObservers);
Assert.IsFalse(s.IsDisposed);
var d = s.Subscribe(_ => { });
Assert.IsTrue(s.HasObservers);
Assert.IsFalse(s.IsDisposed);
d.Dispose();
Assert.IsFalse(s.HasObservers);
Assert.IsFalse(s.IsDisposed);
s.Dispose();
Assert.IsFalse(s.HasObservers);
Assert.IsTrue(s.IsDisposed);
}
示例9: HasObservers
public void HasObservers()
{
var s = new AsyncSubject<int>();
Assert.IsFalse(s.HasObservers);
var d1 = s.Subscribe(_ => { });
Assert.IsTrue(s.HasObservers);
d1.Dispose();
Assert.IsFalse(s.HasObservers);
var d2 = s.Subscribe(_ => { });
Assert.IsTrue(s.HasObservers);
var d3 = s.Subscribe(_ => { });
Assert.IsTrue(s.HasObservers);
d2.Dispose();
Assert.IsTrue(s.HasObservers);
d3.Dispose();
Assert.IsFalse(s.HasObservers);
}
示例10: AsyncSubjectTest
public void AsyncSubjectTest()
{
// OnCompletedPattern
{
var subject = new AsyncSubject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.Count.Is(0);
subject.OnCompleted();
onNext.IsCollection(1000);
onCompletedCallCount.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(1);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(0);
onCompletedCallCount.Is(1);
// ++subscription
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(1000, 1000);
exception.Count.Is(0);
onCompletedCallCount.Is(2);
}
// OnErrorPattern
{
var subject = new AsyncSubject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.Count.Is(0);
subject.OnError(new Exception());
exception.Count.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(0);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(1);
onCompletedCallCount.Is(0);
// ++subscription
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(2);
onCompletedCallCount.Is(0);
}
}
示例11: sends_last_value_after_completion_if_subscribed_after_values
public void sends_last_value_after_completion_if_subscribed_after_values()
{
AsyncSubject<int> subject = new AsyncSubject<int>();
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
subject.Subscribe(stats);
Assert.AreEqual(1, stats.NextCount);
Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 3 }));
Assert.IsTrue(stats.CompletedCalled);
}
示例12: sends_no_values_before_completion
public void sends_no_values_before_completion()
{
AsyncSubject<int> subject = new AsyncSubject<int>();
StatsObserver<int> stats = new StatsObserver<int>();
subject.Subscribe(stats);
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
Assert.IsFalse(stats.NextCalled);
Assert.IsFalse(stats.CompletedCalled);
}
示例13: sends_no_values_after_error
public void sends_no_values_after_error()
{
AsyncSubject<int> subject = new AsyncSubject<int>();
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnError(new Exception());
subject.Subscribe(stats);
Assert.IsFalse(stats.NextCalled);
Assert.IsFalse(stats.CompletedCalled);
}