/* * Copyright (c) 2021 ETH Zürich, Educational Development and Technology (LET) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ using System.Threading.Tasks; namespace SafeExamBrowser.Communication.Contracts.Events { /// /// The default handler for communication events of an interlocutor. /// public delegate void CommunicationEventHandler(); /// /// The handler with parameter for communication events of an interlocutor. /// public delegate void CommunicationEventHandler(T args) where T : CommunicationEventArgs; public static class CommunicationEventHandlerExtensions { /// /// Executes the event handler asynchronously, i.e. on a separate thread. /// public static async Task InvokeAsync(this CommunicationEventHandler handler) { await Task.Run(() => handler?.Invoke()); } /// /// Executes the event handler asynchronously, i.e. on a separate thread. /// public static async Task InvokeAsync(this CommunicationEventHandler handler, T args) where T : CommunicationEventArgs { await Task.Run(() => handler?.Invoke(args)); } } }