public SynchronousCompletionAsyncResult <object> DoFindAsync(string name) { var src = new SynchronousCompletionAsyncResultSource <object>(); void ParentSearch() { var parentSearch = _parentScope.FindAsync(name); if (parentSearch.IsCompleted) { src.SetResult(parentSearch.GetResult()); } else { parentSearch.OnCompleted(() => src.SetResult(parentSearch.GetResult())); } } if (!_inner.IsCompleted) { // Guaranteed to be incomplete at this point var innerSearch = _inner.FindAsync(name); innerSearch.OnCompleted(() => { var value = innerSearch.GetResult(); if (value != null) { src.SetResult(value); } else { ParentSearch(); } }); } else { ParentSearch(); } return(src.AsyncResult); }
/// <summary> /// Tracks a named control relative to another control. /// </summary> /// <param name="scope">The scope relative from which the object should be resolved.</param> /// <param name="name">The name of the object to find.</param> public static IObservable <object> Track(INameScope scope, string name) { return(new NeverEndingSynchronousCompletionAsyncResultObservable <object>(scope.FindAsync(name))); }
async void FindAsync(INameScope scope, string name) { _found = await scope.FindAsync(name); }