Exemple #1
0
        /// <summary>
        /// Queues a method for execution. The method executes when this worker is ready.
        /// </summary>
        /// <param name="function">The work to execute asynchronously.</param>
        public void Invoke(Func <Task> function,
                           InvokeOptions options   = InvokeOptions.Normal,
                           SyncOptions syncOptions = null)
        {
            if (syncOptions != null)
            {
                ValidateSyncOptions(syncOptions);
            }

            var work = new WorkF
            {
                Function = function,
                Options  = (WorkOptions)((int)options),
                Sync     = syncOptions != null ? new WorkSyncContext(syncOptions) : null
            };

            QueueWork(work);
        }
Exemple #2
0
        /// <summary>
        /// Queues the specified work to run when this worker is ready and returns a proxy for the task returned by function.
        /// </summary>
        /// <param name="function">The work to execute asynchronously.</param>
        public Task <Task> InvokeAsync(Func <Task> function,
                                       InvokeOptions options   = InvokeOptions.Normal,
                                       SyncOptions syncOptions = null)
        {
            if (syncOptions != null)
            {
                ValidateSyncOptions(syncOptions);
            }

            var work = new WorkF
            {
                Function         = function,
                Options          = (WorkOptions)((int)options),
                CompletionSource = new TaskCompletionSource <Task>(),
                Sync             = syncOptions != null ? new WorkSyncContext(syncOptions) : null
            };

            QueueWork(work);
            return(work.CompletionSource.Task);
        }