/// <inheritdoc />
        public Task <T> InvokeMethodAsync <T>(GrainReference reference, int methodId, object[] arguments, InvokeMethodOptions options, SiloAddress silo)
        {
            if (arguments != null)
            {
                CheckForGrainArguments(arguments);
                SetGrainCancellationTokensTarget(arguments, reference);
                this.serializationManager.DeepCopyElementsInPlace(arguments);
            }

            var request = new InvokeMethodRequest(reference.InterfaceId, reference.InterfaceVersion, methodId, arguments);

            if (IsUnordered(reference))
            {
                options |= InvokeMethodOptions.Unordered;
            }

            Task <object> resultTask = InvokeMethod_Impl(reference, request, options);

            if (resultTask == null)
            {
                if (typeof(T) == typeof(object))
                {
                    // optimize for most common case when using one way calls.
                    return(OrleansTaskExtentions.CompletedTask as Task <T>);
                }

                return(Task.FromResult(default(T)));
            }
#if !NETCOREAPP
            resultTask = OrleansTaskExtentions.ConvertTaskViaTcs(resultTask);
#endif
            return(resultTask.ToTypedTask <T>());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called from generated code.
        /// </summary>
        protected async Task <T> InvokeMethodAsync <T>(int methodId, object[] arguments, InvokeMethodOptions options = InvokeMethodOptions.None, SiloAddress silo = null)
        {
            object[] argsDeepCopy = null;
            if (arguments != null)
            {
                CheckForGrainArguments(arguments);
                argsDeepCopy = (object[])SerializationManager.DeepCopy(arguments);
            }

            var request = new InvokeMethodRequest(this.InterfaceId, methodId, argsDeepCopy);

            if (IsUnordered)
            {
                options |= InvokeMethodOptions.Unordered;
            }

            Task <object> resultTask = InvokeMethod_Impl(request, null, options);

            if (resultTask == null)
            {
                return(default(T));
            }

            resultTask = OrleansTaskExtentions.ConvertTaskViaTcs(resultTask);
            return((T)await resultTask);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called from generated code.
        /// </summary>
        protected Task <T> InvokeMethodAsync <T>(int methodId, object[] arguments, InvokeMethodOptions options = InvokeMethodOptions.None, SiloAddress silo = null)
        {
            object[] argsDeepCopy = null;
            if (arguments != null)
            {
                CheckForGrainArguments(arguments);
                SetGrainCancellationTokensTarget(arguments, this);
                argsDeepCopy = (object[])SerializationManager.DeepCopy(arguments);
            }

            var request = new InvokeMethodRequest(this.InterfaceId, methodId, argsDeepCopy);

            if (IsUnordered)
            {
                options |= InvokeMethodOptions.Unordered;
            }

            Task <object> resultTask = InvokeMethod_Impl(request, null, options);

            if (resultTask == null)
            {
                if (typeof(T) == typeof(object))
                {
                    // optimize for most common case when using one way calls.
                    return(PublicOrleansTaskExtensions.CompletedTask as Task <T>);
                }

                return(Task.FromResult(default(T)));
            }

            resultTask = OrleansTaskExtentions.ConvertTaskViaTcs(resultTask);
            return(resultTask.Unbox <T>());
        }