summaryrefslogtreecommitdiff
path: root/Impostor-dev/src/Impostor.Api/Events/Managers/IEventManager.cs
blob: 07a7f7cf134a98ee39ea65e936e612eda8b9497c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Threading.Tasks;

namespace Impostor.Api.Events.Managers
{
    public interface IEventManager
    {
        /// <summary>
        ///     Register a temporary event listener.
        /// </summary>
        /// <param name="listener">Event listener.</param>
        /// <param name="invoker">Middleware between the events, which can be used to swap to the correct thread dispatcher.</param>
        /// <returns>Disposable that unregisters the callback from the event manager.</returns>
        /// <typeparam name="TListener">Type of the event listener.</typeparam>
        IDisposable RegisterListener<TListener>(TListener listener, Func<Func<Task>, Task>? invoker = null)
            where TListener : IEventListener;

        /// <summary>
        ///     Returns true if an event with the type <see cref="TEvent"/> is registered.
        /// </summary>
        /// <returns>True if the <see cref="TEvent"/> is registered.</returns>
        /// <typeparam name="TEvent">Type of the event.</typeparam>
        bool IsRegistered<TEvent>()
            where TEvent : IEvent;

        /// <summary>
        ///     Call all the event listeners for the type <see cref="TEvent"/>.
        /// </summary>
        /// <param name="event">The event argument.</param>
        /// <typeparam name="TEvent">Type of the event.</typeparam>
        /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
        ValueTask CallAsync<TEvent>(TEvent @event)
            where TEvent : IEvent;
    }
}