PostHog / posthog-go

Official PostHog Go library
MIT License
20 stars 17 forks source link

Added ability to manually Flush() #10

Closed dselans closed 2 years ago

dselans commented 2 years ago

This PR extends the client interface to be able to perform a Flush() that will cause the looper to bypass the ticker, queue length checks etc. and send telemetry data right away.

This is useful when a service shuts down or exits; especially useful for CLI tools that may have short runtimes.

NOTE: I did not test ctx usage because it would require adding an interface for the looper (I think?) to cause the looper to wait and that would require a good chunk of code changes. Another option - maybe to expose a LoopFunc to the config and allow the client to set it but that seems janky because it would exist almost purely for tests. :|

dselans commented 2 years ago

Just realized that I missed that sends occur in a goroutine and that the Flush won't block until the send is completed.

Will re-open an updated version.