/// <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); }
/// <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); }
/// <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); }