You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to request a feature to allow asynchronous event handlers using the Task type. This would enable more flexibility and performance for handling complex or long-running events.
Currently, the GameEventHandler<T> delegate only accepts a HookResult as the return type, which limits the use of async and await keywords. For example, in this code snippet:
There is no way to make the handler parameter an async function that returns a Task<HookResult>.
I propose adding a new delegate type, such as AsyncGameEventHandler<T>, that supports Task<HookResult> as the return type, and a corresponding method to register it, such as RegisterAsyncEventHandler<T>. This would allow users to write event handlers like this:
publicasyncTask<HookResult>OnPlayerDeath(PlayerDeathEvent@event,GameEventInfoinfo){// Do some async work hereawaitTask.Delay(1000);// Return the hook resultreturnHookResult.Continue;}
This feature would be very useful for scenarios where the event handler needs to perform some asynchronous operations, such as database queries, web requests, or other I/O tasks. It would also improve the responsiveness and scalability of the game server by avoiding blocking the main thread.
Thank you for your consideration.
The text was updated successfully, but these errors were encountered:
If we do support Async game event handlers, then they would have to return void (or just Task in this case), since the game thread needs to immediately know whether or not to block the event, so hook result is somewhat useless in that context.
We would also need to make a copy of the game event values (as a readonly version), since the actual game event values disappear as soon as the next frame occurs
I would like to request a feature to allow asynchronous event handlers using the
Task
type. This would enable more flexibility and performance for handling complex or long-running events.Currently, the
GameEventHandler<T>
delegate only accepts aHookResult
as the return type, which limits the use ofasync
andawait
keywords. For example, in this code snippet:There is no way to make the
handler
parameter anasync
function that returns aTask<HookResult>
.I propose adding a new delegate type, such as
AsyncGameEventHandler<T>
, that supportsTask<HookResult>
as the return type, and a corresponding method to register it, such asRegisterAsyncEventHandler<T>
. This would allow users to write event handlers like this:This feature would be very useful for scenarios where the event handler needs to perform some asynchronous operations, such as database queries, web requests, or other I/O tasks. It would also improve the responsiveness and scalability of the game server by avoiding blocking the main thread.
Thank you for your consideration.
The text was updated successfully, but these errors were encountered: