コード例 #1
0
        /// <summary>
        /// Add graceful shutdown monitor to terminators. Cancellation token will be triggered when the process receives exit graceful signal.
        /// </summary>
        /// <param name="teleport">Existing teleport</param>
        /// <param name="react">Method to ecexute before SigTerm or CTRL+C is passed further</param>
        public static AsyncTeleport CancelOnGracefulShutdown(this AsyncTeleport teleport, Action react = null)
        {
            var term = _exitTcs.Task;

            if (react != null)
            {
                term = term.ContinueWith(t => { react(); return(true); });
            }

            teleport.AddTerminator(ct => term);
            return(teleport);
        }
コード例 #2
0
 public static T Run <T, TA1>(this AsyncTeleport teleport, Func <TA1, CancellationToken, Task <T> > task, TA1 a1)
 {
     return(ExecuteSync(teleport, ct => task(a1, ct)));
 }
コード例 #3
0
 public static T Run <T>(this AsyncTeleport teleport, Func <CancellationToken, Task <T> > task)
 {
     return(ExecuteSync(teleport, task));
 }
コード例 #4
0
 /// <summary>
 /// Add async task to terminators. Cancellation token will be triggered when the task exits.
 /// </summary>
 /// <param name="teleport">Existing teleport</param>
 /// <param name="task">Task to wait until cancel</param>
 public static AsyncTeleport CancelOn(this AsyncTeleport teleport, Func <CancellationToken, Task> task)
 {
     teleport.AddTerminator(task);
     return(teleport);
 }
コード例 #5
0
 /// <summary>
 /// Add sync method to terminators. Cancellation token will be triggered when the method exits.
 /// </summary>
 /// <param name="teleport">Existing teleport</param>
 /// <param name="method">Method to wait until cancel</param>
 public static AsyncTeleport CancelOn(this AsyncTeleport teleport, Action method)
 {
     teleport.AddTerminator(ct => Task.Run(method, ct));
     return(teleport);
 }
コード例 #6
0
 private static void ExecuteSync(AsyncTeleport teleport, Func <CancellationToken, Task> task)
 {
     teleport.Execute(task).ConfigureAwait(false).GetAwaiter().GetResult();
 }
コード例 #7
0
 private static T ExecuteSync <T>(AsyncTeleport teleport, Func <CancellationToken, Task <T> > task)
 {
     return(teleport.Execute(task).ConfigureAwait(false).GetAwaiter().GetResult());
 }
コード例 #8
0
 public static void Run <TA1, TA2>(this AsyncTeleport teleport, Func <TA1, TA2, CancellationToken, Task> task, TA1 a1, TA2 a2)
 {
     ExecuteSync(teleport, ct => task(a1, a2, ct));
 }
コード例 #9
0
 public static void Run(this AsyncTeleport teleport, Func <CancellationToken, Task> task)
 {
     ExecuteSync(teleport, task);
 }