feat!: Poll and use realtime at the same time#153
feat!: Poll and use realtime at the same time#153rolodato wants to merge 1 commit intofeat/event-channelfrom
Conversation
I remember someone complaining about this behaviour because now the whole application has to wait for Flagsmith to fetch the environment document, which was understandably a big no-no for them. |
|
Interesting, I can see how that could be a problem. I actually really like LaunchDarkly's solution for this and wouldn't mind outright copying it: https://pkg.go.dev/github.com/launchdarkly/go-server-sdk/v7#MakeClient Pretty much every use case is accounted for: timeouts, initial/recoverable/permanent failures, and async initialisation We could add a |
|
This work has been deprioritised. |
This PR is based on top of #151, but kept separate for easier reviewing.
Breaking changes
WithRealtimeno longer disables pollingBefore, using
WithRealtimewould prevent polling from happening, so that the SDK's only method of updating the environment is be via SSE. There was no way of using SSE combined with polling. This is undesirable for several reasons:To disable polling, use
WithEnvironmentRefreshInterval(0).NewClientnow returns an error if the environment could not be initialisedPreviously,
NewClientwould always succeed and then try to initialise the environment in the background. If this initialisation fails and is unrecoverable (e.g. network is unavailable and we're not working offline), users would have no way of catching this besides logs.Now, if
NewClientneeds to fetch an environment to initialise, it now blocks until the initial environment is fetched or an error is returned. The default timeout is 10 seconds, or can be changed withWithTimeout.New features
When
Clientpolls for environment updates, it now checks if it already has a recent environment (i.e. younger than the polling interval) before making requests.Real-time updates can now be used together with polling.
WithEnvironmentRefreshInterval(0)now prevents polling from starting. If realtime is also disabled,NewClientnow returns an error.Added
Client.Close. This lets customer applications cleanly terminate the goroutines created byNewClient.