private static async AsyncEnumerator <int> ExceptionTest1() { var yield = await AsyncEnumerator <int> .Capture(); await yield.Return(1); throw new Exception(); }
private static async AsyncEnumerator <int> Test2() { var yield = await AsyncEnumerator <int> .Capture(); for (var i = 1; i <= 3; i++) { await yield.Return(i); } return(yield.Break()); }
private static async AsyncEnumerator <int> Test1() { var yield = await AsyncEnumerator <int> .Capture(); await yield.Return(1); await yield.Return(2); await yield.Return(3); return(yield.Break()); }
public static async AsyncEnumerator <int> Producer() { var yield = await AsyncEnumerator <int> .Capture(); // Capture the underlying 'Task' await yield.Pause(); // Optionally Wait for first MoveNext call await Task.Delay(100).ConfigureAwait(false); // Use any async constructs await yield.Return(1); // Yield a value and wait for MoveNext await Task.Delay(100); await yield.Return(2); return(yield.Break()); // Return false to awaiting MoveNext }
private async AsyncEnumerator <TProjection> ProjectInternalAsync(TSource source, CancellationToken cancellation) { var yield = await AsyncEnumerator <TProjection> .Capture(); var member = _projectionDescriptor.Member; Assert(member != null); var invoker = HandlerActionInvoker.GetInvoker(member); object ResolveParameter(ParameterInfo parameter) { if (parameter.ParameterType == typeof(IServiceProvider)) { return(_serviceProvider); } else if (parameter.ParameterType == typeof(CancellationToken)) { return(cancellation); } else if (parameter.IsDefined <InjectAttribute>()) { return(_serviceProvider.GetRequiredService(parameter.ParameterType)); } else { return(_serviceProvider.GetService(parameter.ParameterType)); } } object result; //try //{ result = await invoker.InvokeAsync(_handler, source, ResolveParameter); // TODO: Await //} //catch (Exception exc) //{ // // TODO: What can we do here? // // TODO: Log this and rethrow // throw; //} if (result != null) { if (_projectionDescriptor.MultipleResults) { var enumerable = result as IEnumerable <TProjection>; Assert(enumerable != null); foreach (var singleResult in enumerable) { await yield.Return(singleResult); } } else { var projectionResult = result as TProjection; Assert(projectionResult != null); await yield.Return(projectionResult); } } return(yield.Break()); }
private static async AsyncEnumerator <int> GetEmptyEnumerator() { var yield = await AsyncEnumerator <int> .Capture(); return(yield.Break()); }