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

pubsub: add MethodHandler #739

Merged
merged 1 commit into from
Jun 2, 2023
Merged

Conversation

eandre
Copy link
Member

@eandre eandre commented Jun 1, 2023

This adds support for having Pub/Sub handlers that reference a method on a service struct.

@eandre eandre requested a review from DomBlack June 1, 2023 18:55
@encore-cla
Copy link

encore-cla bot commented Jun 1, 2023

All committers have signed the CLA.

@eandre eandre force-pushed the pubsub-methodhandler branch 3 times, most recently from 89cee3e to 805698d Compare June 2, 2023 08:38
This adds support for having Pub/Sub handlers
that reference a method on a service struct.
// Allow the rest of the service to initialize before we connect to NSQD.
// This is necessary because NSQD is so fast the receiver can process messages
// before all package-level initialization functions have been called.
time.Sleep(100 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to do this, than "100ms sleep" - this seems like we're just asking for trouble in the future; could there not be a apisdk.WaitForInit() method, which returns true once all services are init'ed

// Handler: pubsub.MethodHandler((*MyService).MyMethod),
// // ...
// })
func MethodHandler[T, SvcStruct any](handler func(s SvcStruct, ctx context.Context, msg T) error) func(ctx context.Context, msg T) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ Perfect, adding support while keeping type satefy in the IDE

@eandre eandre enabled auto-merge (rebase) June 2, 2023 08:47
@eandre eandre merged commit 6f115db into encoredev:main Jun 2, 2023
1 check passed
@eandre eandre deleted the pubsub-methodhandler branch June 2, 2023 08:55
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.

None yet

2 participants