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

fix: allow events to return a promise #169

Merged
merged 1 commit into from
May 9, 2023

Conversation

OmgImAlexis
Copy link
Contributor

@OmgImAlexis OmgImAlexis commented May 9, 2023

This allows .on() to accept a promise as it's callback. For example this is very common.

ws.on('close', async () => {
  await db.doThing();
});

This also changes the class to using typed-emitter which makes it a lot easier to type the events. Would be nice if they were fully typed at some point too instead of using args.

@OmgImAlexis
Copy link
Contributor Author

Here are the types for the events if you also want to add that change.

type Events = {
    message: (message: string) => void | Promise<void>;
    close: (code: number, message: string) => void | Promise<void>;
    drain: () => void | Promise<void>;
    ping: () => void | Promise<void>;
    pong: () => void | Promise<void>;
}

@kartikk221 kartikk221 merged commit 6508288 into kartikk221:master May 9, 2023
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

Successfully merging this pull request may close these issues.

2 participants