Class GameEventExtensions
- Namespace
- SkyrimForge.Events
- Assembly
- SkyrimForge.dll
Provides extension members for IGameEvent<TArgs>.
public static class GameEventExtensions
- Inheritance
-
GameEventExtensions
- Inherited Members
Methods
SubscribeEvery(IGameEvent<FrameEventArgs>, TimeSpan, Action<TimeSpan>)
Registers handler to run each time UnpausedTime advances by interval.
It receives the unpaused time since the previous run, which is interval or more.
public static ISubscription SubscribeEvery(this IGameEvent<FrameEventArgs> frames, TimeSpan interval, Action<TimeSpan> handler)
Parameters
framesIGameEvent<FrameEventArgs>intervalTimeSpanhandlerAction<TimeSpan>
Returns
Exceptions
- ArgumentNullException
handlerisnull.- ArgumentOutOfRangeException
intervalis zero or negative.
SubscribeEvery(IGameEvent<FrameEventArgs>, TimeSpan, Func<TimeSpan, Task>)
Registers handler to run each time UnpausedTime advances by interval.
It receives the unpaused time since the previous run, which is interval or more.
public static ISubscription SubscribeEvery(this IGameEvent<FrameEventArgs> frames, TimeSpan interval, Func<TimeSpan, Task> handler)
Parameters
framesIGameEvent<FrameEventArgs>intervalTimeSpanhandlerFunc<TimeSpan, Task>
Returns
Remarks
An interval that completes while the previous run is in progress starts no run.
Exceptions
- ArgumentNullException
handlerisnull.- ArgumentOutOfRangeException
intervalis zero or negative.
WaitForNextAsync<TArgs>(IGameEvent<TArgs>, Func<TArgs, bool>, CancellationToken)
Waits for the next raise of the event whose arguments predicate accepts and returns them,
or faults with the exception predicate throws.
predicate and the code after the await run on the thread that raises the event, during the raise.
public static Task<TArgs> WaitForNextAsync<TArgs>(this IGameEvent<TArgs> gameEvent, Func<TArgs, bool> predicate, CancellationToken cancellationToken = default) where TArgs : struct
Parameters
gameEventIGameEvent<TArgs>predicateFunc<TArgs, bool>cancellationTokenCancellationToken
Returns
- Task<TArgs>
Type Parameters
TArgs
Remarks
A new game or a save load does not end the wait, unlike an IUtility wait.
To end it then, pass NewGameOrSaveLoading as cancellationToken.
Exceptions
- ArgumentNullException
predicateisnull.
WaitForNextAsync<TArgs>(IGameEvent<TArgs>, CancellationToken)
Waits for the next raise of the event and returns its arguments. The code after the await runs on the thread that raises the event, during the raise.
public static Task<TArgs> WaitForNextAsync<TArgs>(this IGameEvent<TArgs> gameEvent, CancellationToken cancellationToken = default) where TArgs : struct
Parameters
gameEventIGameEvent<TArgs>cancellationTokenCancellationToken
Returns
- Task<TArgs>
Type Parameters
TArgs
Remarks
A new game or a save load does not end the wait, unlike an IUtility wait.
To end it then, pass NewGameOrSaveLoading as cancellationToken.
Where<TArgs>(IGameEvent<TArgs>, Func<TArgs, bool>)
Returns an event raised as this one is, for the arguments predicate accepts.
public static IGameEvent<TArgs> Where<TArgs>(this IGameEvent<TArgs> gameEvent, Func<TArgs, bool> predicate) where TArgs : struct
Parameters
gameEventIGameEvent<TArgs>predicateFunc<TArgs, bool>
Returns
- IGameEvent<TArgs>
Type Parameters
TArgs
Remarks
predicate runs for each handler, on the thread that raises the event. If it throws, the event drops that handler.
Exceptions
- ArgumentNullException
predicateisnull.