Esempio n. 1
0
        /// <summary>
        /// Subscribe a consumer to this stream reference using strongly-typed delegate.
        /// </summary>
        /// <typeparam name="T">The type of the items produced by the stream.</typeparam>
        /// <param name="stream">The stream reference.</param>
        /// <param name="callback">Strongly-typed version of callback delegate.</param>
        /// <returns>
        /// A promise for a StreamSubscription that represents the subscription.
        /// The consumer may unsubscribe by using this object.
        /// The subscription remains active for as long as it is not explicitely unsubscribed.
        /// </returns>
        public static Task <StreamSubscription> Subscribe <T>(this StreamRef stream, Action <T> callback)
        {
            Requires.NotNull(callback, nameof(callback));

            return(stream.Subscribe((source, item) =>
            {
                callback((T)item);
                return TaskDone.Done;
            }));
        }
Esempio n. 2
0
 public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
     this StreamRef <TItem> stream,
     Action <IList <SequentialItem <TItem> > > callback,
     StreamSequenceToken token = null) =>
 stream.Subscribe(b =>
 {
     callback(b);
     return(Task.CompletedTask);
 },
                  token);
Esempio n. 3
0
 public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
     this StreamRef <TItem> stream,
     Action <TItem, StreamSequenceToken> callback,
     StreamFilter filter       = null,
     StreamSequenceToken token = null) =>
 stream.Subscribe((i, t) =>
 {
     callback(i, t);
     return(Task.CompletedTask);
 },
                  filter, token);
Esempio n. 4
0
        public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
            this StreamRef <TItem> stream,
            Func <IList <SequentialItem <TItem> >, Task> callback,
            StreamSequenceToken token = null)
        {
            Task Handler(StreamMessage message) =>
            message is StreamItemBatch <TItem> x
                    ? callback(x.Items)
                    : Task.CompletedTask;

            return(stream.Subscribe(Handler, new SubscribeReceiveBatch(token)));
        }
Esempio n. 5
0
        public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
            this StreamRef <TItem> stream,
            Func <TItem, StreamSequenceToken, Task> callback,
            StreamFilter filter       = null,
            StreamSequenceToken token = null)
        {
            Task Handler(StreamMessage message) =>
            message is StreamItem <TItem> x
                    ? callback(x.Item, x.Token)
                    : Task.CompletedTask;

            return(stream.Subscribe(Handler, new SubscribeReceiveItem(filter, token)));
        }
Esempio n. 6
0
        public static async Task Subscribe(this StreamRef stream, ActorGrain actor, StreamFilter filter = null)
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 1)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 0,
                         "We should keep only one active subscription per-stream per-actor");

            await stream.Subscribe(actor.ReceiveRequest, filter);
        }
Esempio n. 7
0
        public static async Task Subscribe(this StreamRef stream, Actor actor, StreamFilter filter = null)
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 1)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 0,
                         "We should keep only one active subscription per-stream per-actor");

            await stream.Subscribe(x => actor.Host.Receive(x), filter ?? DeclaredHandlerOnlyFilter(actor));
        }
Esempio n. 8
0
        public static async Task Subscribe <TItem, TOptions>(this StreamRef <TItem> stream, ActorGrain actor, TOptions options)
            where TOptions : SubscribeOptions
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 1)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 0,
                         "We should keep only one active subscription per-stream per-actor");

            await stream.Subscribe(actor.ReceiveRequest, options);
        }
Esempio n. 9
0
 public static Task Subscribe <TItem>(this StreamRef <TItem> stream, ActorGrain actor) =>
 stream.Subscribe(actor, new SubscribeReceiveItem());
Esempio n. 10
0
        /// <summary>
        /// Subscribe a consumer to this stream reference using strongly-typed delegate.
        /// </summary>
        /// <typeparam name="T">The type of the items produced by the stream.</typeparam>
        /// <param name="stream">The stream reference.</param>
        /// <param name="callback">Strongly-typed version of callback delegate.</param>
        /// <returns>
        /// A promise for a StreamSubscription that represents the subscription.
        /// The consumer may unsubscribe by using this object.
        /// The subscription remains active for as long as it is not explicitely unsubscribed.
        /// </returns>
        public static Task <StreamSubscription> Subscribe <T>(this StreamRef stream, Func <T, Task> callback)
        {
            Requires.NotNull(callback, nameof(callback));

            return(stream.Subscribe((source, item) => callback((T)item)));
        }