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

onSubscribe send a message to the subscriber #177

Open
Cyliann opened this issue Feb 5, 2024 · 0 comments
Open

onSubscribe send a message to the subscriber #177

Cyliann opened this issue Feb 5, 2024 · 0 comments

Comments

@Cyliann
Copy link

Cyliann commented Feb 5, 2024

Is it possible to send a message to the subscriber as soon as it subscribes? I need to send an ID to every new client connected.
Sadly, this doesn't work:

func main() {
        server := sse.New()
	mux := http.NewServeMux()
	mux.HandleFunc("/events", eventHandler)

	http.ListenAndServe(":8080", mux)
}

func eventHandler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("Message"))
	w.(http.Flusher).Flush()

	server.ServeHTTP(w, r)
}

I though that onSubsrcibe() can to that, but it doesn't allow passing http.ResponseWriter in any way and I can't see how it can be accomplished otherwise.
I've been banging my head over the wall for the past 2 days and I can't get it to work.
Could you provide any help?

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