rust-server-sdk icon indicating copy to clipboard operation
rust-server-sdk copied to clipboard

Expose a subscription-based API

Open aalexandrov opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

The SDK currently only exposes a based polling API. The only way to continuously monitor for changes in feature flags for a specific user / context is to periodically poll the Client for changes.

Describe the solution you'd like

It would be great to have a subscribe API in the SDK, when I would be able to do something like

ld_client.subscribe(&ld_ctx, handler)

and pass a handler that is called to handle Vec<FeatureUpdate> events. AFAICT this approximately the way the internal event source client works, so it shouldn't be too hard to implement this.

Describe alternatives you've considered

For example, at Materialize we use the following loop

let mut params = SynchronizedParameters::default();
loop {
    backend.pull(&mut params).await;
    if frontend.pull(&mut params) {
        backend.push(&mut params).await;
    }
    interval.tick().await;
}

where the frontend.pull makes the following call to ld_client: ld::Client using the ld_user: ld::User context.

self.ld_client.variation(&self.ld_user, flag_name, params.get(param_name));

Additional context

N/A

aalexandrov avatar Dec 13 '22 11:12 aalexandrov

Thank you for this feature request. I have filed this internally as sc-180507.

keelerm84 avatar Dec 13 '22 18:12 keelerm84