Table of Contents

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

frames IGameEvent<FrameEventArgs>
interval TimeSpan
handler Action<TimeSpan>

Returns

ISubscription

Exceptions

ArgumentNullException

handler is null.

ArgumentOutOfRangeException

interval is 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

frames IGameEvent<FrameEventArgs>
interval TimeSpan
handler Func<TimeSpan, Task>

Returns

ISubscription

Remarks

An interval that completes while the previous run is in progress starts no run.

Exceptions

ArgumentNullException

handler is null.

ArgumentOutOfRangeException

interval is 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

gameEvent IGameEvent<TArgs>
predicate Func<TArgs, bool>
cancellationToken CancellationToken

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

predicate is null.

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

gameEvent IGameEvent<TArgs>
cancellationToken CancellationToken

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

gameEvent IGameEvent<TArgs>
predicate Func<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

predicate is null.