Unleash / unleash-client-rust

Unleash client SDK for Rust language projects
Apache License 2.0
23 stars 18 forks source link

poll_for_updates discussion #52

Open deweyjose opened 1 year ago

deweyjose commented 1 year ago

Describe the feature request

It would be helpful to understand the design decision not to automatically support execution of poll_for_updates.

Is the library trying to remain as agnostic as possible to different execution models - std::thread tokio async/await etc?

Or was there a total misunderstanding and we are able to configure the library to fetch updates?

Background

No response

Solution suggestions

No response

thomasheartman commented 1 year ago

That's a good question. I'm not entirely sure about the reasoning behind the design decisions in this library, but @rbtcollins would probably have some useful insights here. @sighphyre might also have some useful input.

rbtcollins commented 1 year ago

From the docs: https://docs.rs/unleash-api-client/latest/unleash_api_client/#client-overview

"As the client specification requires sending background metrics to the API, you will need to arrange to call the poll_for_updates method from a thread as demonstrated in examples/threads.rs"

(And since it also supports async networking, you can do that from a tokio task or whatever as well if you like).

The example code on that page has this:

        futures::future::join(client.poll_for_updates(), async {
            // Ensure we have initial load of features completed
            Delay::new(Duration::from_millis(500)).await;
            assert_eq!(true, client.is_enabled(UserFeatures::default, None, false));
            // ... serve more requests
            client.stop_poll().await;
        }).await;
        Ok(())

which demonstrates both doing polling for updates, and doing a graceful shutdown of the poller - though thats not needed if you like you can just drop the tokio task.

rbtcollins commented 1 year ago

Perhaps I misunderstood the question?

thomasheartman commented 1 year ago

Sorry for not responding sooner. I can't speak for the OP, but I interpreted it as "why do we have to set it up ourself" / "why doesn't the SDK do it automatically". The docs say you have to do it yourself, but it doesn't explicitly say why as far as I can tell. Presumably it's because you need an async runtime and the SDK doesn't pick one for you?

michaelkanis-dmtech commented 11 months ago

I would also like to know why the Rust client SDK requires you to setup the polling yourself. I have used the Unleash SDKs for other languages (Java, Python, Go) and none requires you to do that. It's always just: 1) create a client instance and 2) call isEnabled(). TBH, as an application developer I don't want to be bothered with setting up the details of a library like this.

Could the Rust SDK support this simpler usage, too?