public static IObjectFieldDescriptor Subscribe <T>(
     this IObjectFieldDescriptor descriptor,
     Func <IResolverContext, Task <IAsyncEnumerable <T> > > subscribe)
 {
     return(descriptor.Subscribe(async ctx =>
     {
         IAsyncEnumerable <T> enumerable = await subscribe(ctx).ConfigureAwait(false);
         return new SourceStreamWrapper(new AsyncEnumerableStreamAdapter <T>(enumerable));
     }));
 }
 public static IObjectFieldDescriptor Subscribe <T>(
     this IObjectFieldDescriptor descriptor,
     Func <IResolverContext, Task <IObservable <T> > > subscribe)
 {
     return(descriptor.Subscribe(async ctx =>
     {
         IObservable <T> observable = await subscribe(ctx).ConfigureAwait(false);
         return new ObservableSourceStreamAdapter <T>(observable);
     }));
 }
 /// <summary>
 /// Subscribes to a topic that is resolved by executing <paramref name="resolveTopic" />.
 /// </summary>
 /// <param name="descriptor">
 /// The object field descriptor.
 /// </param>
 /// <param name="resolveTopic">
 /// A delegate that resolves a value that will used as topic.
 /// </param>
 /// <typeparam name="TMessage">
 /// The type of the message / event payload.
 /// </typeparam>
 public static IObjectFieldDescriptor SubscribeToTopic <TTopic, TMessage>(
     this IObjectFieldDescriptor descriptor,
     Func <IResolverContext, ValueTask <TTopic> > resolveTopic)
 {
     return(descriptor.Subscribe(async ctx =>
     {
         ITopicEventReceiver receiver = ctx.Service <ITopicEventReceiver>();
         TTopic topic = await resolveTopic(ctx).ConfigureAwait(false);
         return await receiver.SubscribeAsync <TTopic, TMessage>(topic).ConfigureAwait(false);
     }));
 }
 public static IObjectFieldDescriptor Subscribe <T>(
     this IObjectFieldDescriptor descriptor,
     Func <IResolverContext, IAsyncEnumerable <T> > subscribe) =>
 descriptor.Subscribe(ctx => Task.FromResult(subscribe(ctx)));