Use a proxy to handle the assignment issue after middleware execution for multiple instances.
"await next()" is not supported, but the middleware supports async functions.
When encountering async in a middleware, it will return the defaultValue set instead of the result after awaiting. It also means that the return value of subsequent middlewares is not important. If all the middlewares are synchronous functions until the last one, and the last one also returns the result of "next()", it will return the defaultValue.
If you don't have a better idea, you can return the result of "next()" after each middleware callback.
Usually, the callbacks for creating and destroying each event instance should be registered and paired. Otherwise, unpredictable accidents may occur, such as the "onConnect" and "onDisconnect" events for a player, or the "onCreated" and "onDestroyed" events for an object.
It's just an experiment, and I don't have the energy to refactor yet.
"await next()"
is not supported, but the middleware supportsasync
functions."next()"
, it will return the defaultValue."next()"
after each middleware callback."onConnect"
and"onDisconnect"
events for a player, or the"onCreated"
and"onDestroyed"
events for an object.