feat!: Poll and use realtime at the same time #153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is based on top of #151, but kept separate for easier reviewing.
Breaking changes
WithRealtime
no longer disables pollingBefore, using
WithRealtime
would 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)
.NewClient
now returns an error if the environment could not be initialisedPreviously,
NewClient
would 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
NewClient
needs 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
Client
polls 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,NewClient
now returns an error.Added
Client.Close
. This lets customer applications cleanly terminate the goroutines created byNewClient
.