Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to prepend listeners or run listeners in reversed order in emit #91

Open
koteisaev opened this issue Nov 22, 2021 · 0 comments
Open

Comments

@koteisaev
Copy link

koteisaev commented Nov 22, 2021

Usage case:

  1. On new requiest an event request fired. This allows to capture request state and deserialize access tokens, session from cookies, etc.
  2. On just before the body would be sent, event before-response fired with request and response refs, to serialize security claims into cookies if necessary.
    It is important to schedule for request event handlers like
[interceptSession, rebuildClaims]

while on the before-response the event handlers must be run in opposite order:

[serializeClaims, packSession]

But with current API I can not directly express this with Emittery.
So, I would like to see either

prepend<TName, TData>(eventName:TName, data:TData);

in an Emittery instance, or some flag like:

emitSerial<TName, TData>(name:TName, data:TData, reversed?:boolean):Promise<void>;

in my case I can wrap event handlers registration and postpone actual on calls, until the building of web application will be completed.
But async match of EventEmitter.prependListener and EventEmitter.prependOnceListener may be helpful in some other cases when delayed listeners construction is not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant