Ejemplo n.º 1
0
        // broadcast: [methodId, [argument]]

        public Task WriteAllAsync <T>(int methodId, T value, bool fireAndForget)
        {
            var message = BuildMessage(methodId, value);

            var source = members;

            if (fireAndForget)
            {
                for (int i = 0; i < source.Length; i++)
                {
                    WriteInAsyncLockVoid(source[i], message);
                }
                logger.InvokeHubBroadcast(GroupName, message.Length, source.Length);
                return(TaskEx.CompletedTask);
            }
            else
            {
                var promise = new ReservedWhenAllPromise(source.Length);
                for (int i = 0; i < source.Length; i++)
                {
                    promise.Add(WriteInAsyncLock(source[i], message));
                }
                logger.InvokeHubBroadcast(GroupName, message.Length, source.Length);
                return(promise.AsValueTask().AsTask());
            }
        }
        // broadcast: [methodId, [argument]]

        public Task WriteAllAsync <T>(int methodId, T value, bool fireAndForget)
        {
            var message = BuildMessage(methodId, value);

            if (fireAndForget)
            {
                var writeCount = 0;
                foreach (var item in members)
                {
                    WriteInAsyncLockVoid(item.Value, message);
                    writeCount++;
                }
                logger.InvokeHubBroadcast(GroupName, message.Length, writeCount);
                return(Task.CompletedTask);
            }
            else
            {
                var rent = ArrayPool <ValueTask> .Shared.Rent(approximatelyLength);

                var       writeCount = 0;
                ValueTask promise;
                try
                {
                    var buffer = rent;
                    var index  = 0;
                    foreach (var item in members)
                    {
                        if (buffer.Length < index)
                        {
                            Array.Resize(ref buffer, buffer.Length * 2);
                        }
                        buffer[index++] = WriteInAsyncLock(item.Value, message);
                        writeCount++;
                    }

                    promise = ToPromise(buffer, index);
                }
                finally
                {
                    ArrayPool <ValueTask> .Shared.Return(rent, true);
                }
                logger.InvokeHubBroadcast(GroupName, message.Length, writeCount);
                return(promise.AsTask());
            }
        }
Ejemplo n.º 3
0
        // broadcast: [methodId, [argument]]

        public Task WriteAllAsync <T>(int methodId, T value, bool fireAndForget)
        {
            var message = BuildMessage(methodId, value);

            if (fireAndForget)
            {
                var writeCount = 0;
                foreach (var item in members)
                {
                    WriteInAsyncLockVoid(item.Value, message);
                    writeCount++;
                }
                logger.InvokeHubBroadcast(GroupName, message.Length, writeCount);
                return(TaskEx.CompletedTask);
            }
            else
            {
                throw new NotSupportedException("The write operation must be called with Fire and Forget option");
            }
        }
        // broadcast: [methodId, [argument]]

        public Task WriteAllAsync <T>(int methodId, T value, bool fireAndForget)
        {
            var message = BuildMessage(methodId, value);

            var source = members;

            if (fireAndForget)
            {
                for (int i = 0; i < source.Length; i++)
                {
                    source[i].QueueResponseStreamWrite(message);
                }
                logger.InvokeHubBroadcast(GroupName, message.Length, source.Length);
                return(TaskEx.CompletedTask);
            }
            else
            {
                throw new NotSupportedException("The write operation must be called with Fire and Forget option");
            }
        }