本文整理汇总了C#中AsyncSubject.OnCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncSubject.OnCompleted方法的具体用法?C# AsyncSubject.OnCompleted怎么用?C# AsyncSubject.OnCompleted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncSubject
的用法示例。
在下文中一共展示了AsyncSubject.OnCompleted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
});
}
示例2: 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);
}
示例3: PhotosetsGeneralAsyncTest
public void PhotosetsGeneralAsyncTest()
{
Flickr f = TestData.GetAuthInstance();
var photoId1 = "7519320006"; // Tree/Write/Wall
var photoId2 = "7176125763"; // Rainbow Rose
var w = new AsyncSubject<FlickrResult<Photoset>>();
f.PhotosetsCreateAsync("Test Photoset", photoId1, r => { w.OnNext(r); w.OnCompleted(); });
var photosetResult = w.Next().First();
Assert.IsFalse(photosetResult.HasError);
var photoset = photosetResult.Result;
try
{
var w2 = new AsyncSubject<FlickrResult<NoResponse>>();
f.PhotosetsEditMetaAsync(photoset.PhotosetId, "New Title", "New Description", r => { w2.OnNext(r); w2.OnCompleted(); });
var noResponseResult = w2.Next().First();
Assert.IsFalse(noResponseResult.HasError);
var w3 = new AsyncSubject<FlickrResult<NoResponse>>();
f.PhotosetsAddPhotoAsync(photoset.PhotosetId, photoId2, r => { w3.OnNext(r); w3.OnCompleted(); });
noResponseResult = w3.Next().First();
Assert.IsFalse(noResponseResult.HasError);
}
finally
{
var w4 = new AsyncSubject<FlickrResult<NoResponse>>();
// Clean up and delete photoset
f.PhotosetsDeleteAsync(photoset.PhotosetId, r => { w4.OnNext(r); w4.OnCompleted(); });
var noResponseResult = w4.Next().First();
}
}
示例4: WriteAsync
public static IObservable<Unit> WriteAsync(this Stream This, byte[] data, int start, int length)
{
var ret = new AsyncSubject<Unit>();
try
{
This.BeginWrite(data, start, length, result =>
{
try
{
This.EndWrite(result);
ret.OnNext(Unit.Default);
ret.OnCompleted();
}
catch (Exception ex)
{
ret.OnError(ex);
}
}, null);
}
catch (Exception ex)
{
ret.OnError(ex);
}
return ret;
}
示例5: detect
private IObservable<string> detect(string text)
{
var subject = new AsyncSubject<string>();
string detectUri = String.Format(GetDetectUri(text), appId, HttpUtility.HtmlEncode(text));
var wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler((obj, args) =>
{
if (args.Error != null)
{
subject.OnError(args.Error);
}
else
{
if (!args.Cancelled)
{
var xdoc = XDocument.Load(args.Result);
subject.OnNext(xdoc.Root.Value);
}
subject.OnCompleted();
}
});
wc.OpenReadAsync(new Uri(detectUri));
return subject;
}
示例6: PhotosGetCountsAsyncTest
public void PhotosGetCountsAsyncTest()
{
DateTime date1 = DateTime.Today.AddMonths(-12);
DateTime date2 = DateTime.Today.AddMonths(-6);
DateTime date3 = DateTime.Today;
DateTime[] uploadDates = new DateTime[] { date1, date2, date3 };
Flickr f = TestData.GetAuthInstance();
var w = new AsyncSubject<FlickrResult<PhotoCountCollection>>();
f.PhotosGetCountsAsync(uploadDates, false, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
var counts = result.Result;
Assert.AreEqual(2, counts.Count, "Should be two counts returned.");
var count1 = counts[0];
Assert.AreEqual(date1, count1.FromDate);
Assert.AreEqual(date2, count1.ToDate);
var count2 = counts[1];
Assert.AreEqual(date2, count2.FromDate);
Assert.AreEqual(date3, count2.ToDate);
}
示例7: PhotosetsGetContextAsyncTest
public void PhotosetsGetContextAsyncTest()
{
Flickr f = TestData.GetInstance();
var photosetId = "72157626420254033"; // Beamish
var photos = f.PhotosetsGetPhotos(photosetId, 1, 100);
var firstPhoto = photos.First();
var lastPhoto = photos.Last();
var w = new AsyncSubject<FlickrResult<Context>>();
f.PhotosetsGetContextAsync(firstPhoto.PhotoId, photosetId, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
var context = result.Result;
Assert.IsNull(context.PreviousPhoto, "As this is the first photo the previous photo should be null.");
Assert.IsNotNull(context.NextPhoto, "As this is the first photo the next photo should not be null.");
w = new AsyncSubject<FlickrResult<Context>>();
f.PhotosetsGetContextAsync(lastPhoto.PhotoId, photosetId, r => { w.OnNext(r); w.OnCompleted(); });
result = w.Next().First();
Assert.IsFalse(result.HasError);
context = result.Result;
Assert.IsNull(context.NextPhoto, "As this is the last photo the next photo should be null.");
Assert.IsNotNull(context.PreviousPhoto, "As this is the last photo the previous photo should not be null.");
}
示例8: 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();
}
示例9: PhotosGetExifAsyncTest
public void PhotosGetExifAsyncTest()
{
Flickr f = TestData.GetInstance();
var w = new AsyncSubject<FlickrResult<ExifTagCollection>>();
f.PhotosGetExifAsync(TestData.PhotoId, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
}
示例10: PhotosAddTagTest
public void PhotosAddTagTest()
{
string photoId = "4499284951";
string tag = "testx";
var w = new AsyncSubject<FlickrResult<NoResponse>>();
AuthInstance.PhotosAddTagsAsync(photoId, tag, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
}
示例11: PhotosGetContactsPhotosAsyncTest
public void PhotosGetContactsPhotosAsyncTest()
{
var w = new AsyncSubject<FlickrResult<PhotoCollection>>();
AuthInstance.PhotosGetContactsPhotosAsync(50, true, true, true, PhotoSearchExtras.All, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
Assert.IsNotNull(result.Result);
Assert.IsTrue(result.Result.Count > 0, "Should return some photos.");
}
示例12: Run
public void Run()
{
ConsoleUtility.PrintSuccess(string.Format("Rx AsyncSubject example"));
var topic = new AsyncSubject<Price>();
WriteToConsole(topic);
topic.OnNext(new Price(1, 99, 100, 101));
topic.OnNext(new Price(1, 98, 99, 100));
topic.OnNext(new Price(1, 97, 98, 99));
topic.OnCompleted();
}
示例13: PhotosGetRecentAsyncTest
public void PhotosGetRecentAsyncTest()
{
Flickr f = TestData.GetInstance();
var w = new AsyncSubject<FlickrResult<PhotoCollection>>();
f.PhotosGetRecentAsync(1, 50, PhotoSearchExtras.All, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
Assert.IsNotNull(result.Result);
Assert.IsTrue(result.Result.Count > 0, "Should return some photos.");
}
示例14: PhotosSearchAsyncBasicTest
public void PhotosSearchAsyncBasicTest()
{
var o = new PhotoSearchOptions();
o.Tags = "microsoft";
var w = new AsyncSubject<FlickrResult<PhotoCollection>>();
Instance.PhotosSearchAsync(o, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsTrue(result.Result.Total > 0);
}
示例15: StatsGetPhotosetDomainsAsyncTest
public void StatsGetPhotosetDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();
DateTime d = DateTime.Today.AddDays(-7);
var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotosetDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
}