本文整理汇总了C#中BehaviorSubject.OnCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# BehaviorSubject.OnCompleted方法的具体用法?C# BehaviorSubject.OnCompleted怎么用?C# BehaviorSubject.OnCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BehaviorSubject
的用法示例。
在下文中一共展示了BehaviorSubject.OnCompleted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
private void Start()
{
//BehaviorSubjectは初期値を設定できる
behaviorSubject = new BehaviorSubject<int>(0);
/*
OnNext → Subscribe と実行し、Subscribeした瞬間に直前の値が発行されることを確認しよう
*/
// Subscribeボタンが押されたらSubjectをSubscribeしてresultTextに表示する
subscribeButton.OnClickAsObservable().Subscribe(_ =>
{
if (behaviorSubject != null)
{
behaviorSubject.Subscribe(
time => resultText.text += time.ToString() + " ", //OnNext
() => resultText.text += "OnCompleted "); //OnCompleted
}
});
// OnNextボタンが押されたら今が何度目のOnNextであるかを発行する
onNextButton.OnClickAsObservable().Subscribe(_ =>
{
if (behaviorSubject != null)
{
behaviorSubject.OnNext(++onNextCount);
}
});
// OnCompletedボタンが押されたらOnCompletedを発行する
onCompletedButton.OnClickAsObservable().Subscribe(_ =>
{
if (behaviorSubject != null)
{
behaviorSubject.OnCompleted();
}
});
// Resetボタンが押されたら全体を初期化する
resetButton.OnClickAsObservable().Subscribe(_ =>
{
if (behaviorSubject != null)
{
behaviorSubject.OnCompleted();
}
behaviorSubject = new BehaviorSubject<int>(0);
resultText.text = "";
onNextCount = 0;
});
}
示例2: BehaviorSubjectCompletedExample
public static void BehaviorSubjectCompletedExample()
{
var subject = new BehaviorSubject<string>("a");
subject.OnNext("b");
subject.OnNext("c");
subject.OnCompleted();
subject.Subscribe(Console.WriteLine);
}
示例3: Should_Complete_When_Source_Observable_Completes
public void Should_Complete_When_Source_Observable_Completes()
{
var source = new BehaviorSubject<object>(1);
var target = new ExpressionObserver(source, "Foo");
var completed = false;
target.Subscribe(_ => { }, () => completed = true);
source.OnCompleted();
Assert.True(completed);
}
示例4: Should_Complete_When_Activator_Completes
public void Should_Complete_When_Activator_Completes()
{
var activator = new BehaviorSubject<bool>(false);
var target = new ActivatedValue(activator, 1, string.Empty);
var completed = false;
target.Subscribe(_ => { }, () => completed = true);
activator.OnCompleted();
Assert.True(completed);
}
示例5: Should_Complete_When_Source_Completes
public void Should_Complete_When_Source_Completes()
{
var activator = new BehaviorSubject<bool>(false);
var source = new BehaviorSubject<object>(1);
var target = new ActivatedObservable(activator, source, string.Empty);
var completed = false;
target.Subscribe(_ => { }, () => completed = true);
source.OnCompleted();
Assert.True(completed);
}
示例6: Main
static void Main(string[] args)
{
var serviceClient = new JsonRestClientAsync("http://g-un--:1337/");
var responseSubject = new BehaviorSubject<Unit>(Unit.Default);
responseSubject.Subscribe(_ =>
{
serviceClient.PostAsync<ResourceResponse>(
"/async",
new ResourceRequest()
{
ResourceKey = Guid.NewGuid().ToString()
},
response =>
{
Console.WriteLine("Data received");
Console.WriteLine(response.ResourceData);
responseSubject.OnNext(Unit.Default);
},
(response, ex) =>
{
Console.WriteLine("Exception on calling service post method");
Console.WriteLine(ex);
responseSubject.OnCompleted();
});
});
Observable.Interval(TimeSpan.FromSeconds(1))
.Subscribe(_ =>
{
var newClient = new JsonRestClientAsync("http://g-un--:1337/");
newClient.PutAsync<object>(
"/async",
new ResourceRequest() { ResourceKey = Guid.NewGuid().ToString() },
response =>
{
Console.WriteLine("Put was sent!");
},
(response, exception) =>
{
Console.WriteLine(exception);
});
});
Console.ReadLine();
}
示例7: complete_is_sent_through_scheduler
public void complete_is_sent_through_scheduler()
{
ManualScheduler scheduler = new ManualScheduler();
BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnCompleted();
subject.Subscribe(stats);
Assert.IsFalse(stats.NextCalled);
scheduler.RunNext();
Assert.AreEqual(0, stats.NextCount);
Assert.IsTrue(stats.CompletedCalled);
}
示例8: BehaviorSubject
public void BehaviorSubject()
{
// OnCompletedPattern
{
var subject = new BehaviorSubject<int>(3333);
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
var _ = subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(3333);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.IsCollection(3333, 1, 10, 100, 1000);
// re subscription
onNext.Clear();
_.Dispose();
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(1000);
subject.OnCompleted();
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
onNext.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(0);
onCompletedCallCount.Is(1);
}
// OnErrorPattern
{
var subject = new BehaviorSubject<int>(3333);
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.IsCollection(3333, 1, 10, 100, 1000);
subject.OnError(new Exception());
exception.Count.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(5);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(1);
onCompletedCallCount.Is(0);
// ++subscription
onNext.Clear();
exception.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(1);
onCompletedCallCount.Is(0);
}
}
示例9: Value_FrozenAfterOnCompleted
public void Value_FrozenAfterOnCompleted()
{
var s = new BehaviorSubject<int>(42);
Assert.AreEqual(42, s.Value);
s.OnNext(43);
Assert.AreEqual(43, s.Value);
s.OnNext(44);
Assert.AreEqual(44, s.Value);
s.OnCompleted();
Assert.AreEqual(44, s.Value);
s.OnNext(1234);
Assert.AreEqual(44, s.Value);
}
示例10: HasObservers_OnCompleted
public void HasObservers_OnCompleted()
{
var s = new BehaviorSubject<int>(42);
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);
}
示例11: Observable_Current_completes_on_source_completion
public async Task Observable_Current_completes_on_source_completion()
{
var subject = new BehaviorSubject<int>(1);
var asyncEnumerable = subject.Current();
using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
{
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
Assert.False(await asyncEnumerator.MoveNext(CancellationToken.None));
}
}
示例12: Value_FrozenAfterOnCompleted
public void Value_FrozenAfterOnCompleted()
{
var s = new BehaviorSubject<int>(42);
Assert.AreEqual(42, s.Value);
var x = default(int);
Assert.IsTrue(s.TryGetValue(out x));
Assert.AreEqual(42, x);
s.OnNext(43);
Assert.AreEqual(43, s.Value);
Assert.IsTrue(s.TryGetValue(out x));
Assert.AreEqual(43, x);
s.OnNext(44);
Assert.AreEqual(44, s.Value);
Assert.IsTrue(s.TryGetValue(out x));
Assert.AreEqual(44, x);
s.OnCompleted();
Assert.AreEqual(44, s.Value);
Assert.IsTrue(s.TryGetValue(out x));
Assert.AreEqual(44, x);
s.OnNext(1234);
Assert.AreEqual(44, s.Value);
Assert.IsTrue(s.TryGetValue(out x));
Assert.AreEqual(44, x);
}
示例13: live_values_are_sent_through_scheduler
public void live_values_are_sent_through_scheduler()
{
ManualScheduler scheduler = new ManualScheduler();
BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);
StatsObserver<int> stats = new StatsObserver<int>();
subject.Subscribe(stats);
subject.OnNext(1);
subject.OnNext(2);
subject.OnCompleted();
Assert.IsFalse(stats.NextCalled);
scheduler.RunNext();
Assert.AreEqual(1, stats.NextCount);
Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 }));
Assert.IsFalse(stats.CompletedCalled);
scheduler.RunNext();
Assert.AreEqual(2, stats.NextCount);
Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1 }));
Assert.IsFalse(stats.CompletedCalled);
scheduler.RunNext();
Assert.AreEqual(3, stats.NextCount);
Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1, 2 }));
Assert.IsFalse(stats.CompletedCalled);
scheduler.RunNext();
Assert.IsTrue(stats.CompletedCalled);
}
示例14: sends_live_values_after_replay
public void sends_live_values_after_replay()
{
BehaviorSubject<int> subject = new BehaviorSubject<int>(0);
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.Subscribe(stats);
subject.OnNext(3);
subject.OnCompleted();
Assert.AreEqual(2, stats.NextCount);
Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2, 3 }));
Assert.IsTrue(stats.CompletedCalled);
}
示例15: replays_no_values_when_complete
public void replays_no_values_when_complete()
{
BehaviorSubject<int> subject = new BehaviorSubject<int>(0);
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
subject.Subscribe(stats);
Assert.AreEqual(0, stats.NextCount);
Assert.IsTrue(stats.CompletedCalled);
}