Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async feature and rework Dispatcher #9

Merged
merged 3 commits into from
Jan 6, 2025
Merged

Add async feature and rework Dispatcher #9

merged 3 commits into from
Jan 6, 2025

Conversation

yukibtc
Copy link
Member

@yukibtc yukibtc commented Jan 6, 2025

No description provided.

JoeJoeTV and others added 2 commits January 6, 2025 12:35
Closes #7
Closes #8

Signed-off-by: Yuki Kishimoto <[email protected]>
* Rename `NtfyError` to `Error`

Ref #7

Signed-off-by: Yuki Kishimoto <[email protected]>
@JoeJoeTV
Copy link
Contributor

JoeJoeTV commented Jan 6, 2025

This looks good to me. I like the changes to separate the "method" out a bit more.

Things that would be nice to add:

  • Since the client/agent is now passed to the Dispatcher, maybe one could add some method to pass custom settings to it? For me, this would be useful to set the browser agent string of the client, since it is currently empty, at least with ureq. Maybe a function that is given a closure that is given the client/agent builder and can call additional methods on it, before the rest is done in the build_* function? Or by optionally passing an existing builder to the build_* function.
  • A builder function in the dispatcher module itself, which just returns DispatcherBuilder::new(). I have seen this in other libraries and I like it, even though it's just a small thing. Something like the following maybe:
    pub fn builder<S>(url: S) -> DispatcherBuilder
    where
        S: Into<String>,
    {
        DispatcherBuilder::new::<S>(url)
    }

@yukibtc
Copy link
Member Author

yukibtc commented Jan 6, 2025

Since the client/agent is now passed to the Dispatcher, maybe one could add some method to pass custom settings to it? For me, this would be useful to set the browser agent string of the client, since it is currently empty, at least with ureq. Maybe a function that is given a closure that is given the client/agent builder and can call additional methods on it, before the rest is done in the build_* method?

Yes, good idea. This can be done in another PR

A builder function in the dispatcher module itself, which just returns DispatcherBuilder::new(). I have seen this in other libraries and I like it, even though it's just a small thing.

Was already available the Dispatcher::builder, which return the DistaptcherBuilder. I like it too, but in this PR I deprecated it because require to specify a generic when calling Dispatcher::builder (i.e., Dispatcher::<Async>::builder). But there is a "trick" to allow to continue to use it without breaking changes:

#[derive(Debug, Clone)]
pub struct Dispatcher<T = ()> // <-- set a default value for the generic
where
    T: Clone,
{
    url: Url,
    inner: T,
}

// Impl the `builder` method for the `Dispatcher<()>`, allowing to call `Dispatcher::builder`.
impl Dispatcher {
    pub fn builder<S>(url: S) -> DispatcherBuilder
    where
        S: Into<String>,
    {
        DispatcherBuilder::new(url)
    }
}

@JoeJoeTV
Copy link
Contributor

JoeJoeTV commented Jan 6, 2025

Yes, good idea. This can be done in another PR

I guess first, this pull-request should be completed before that, then I could create that.

A builder function in the dispatcher module itself, which just returns DispatcherBuilder::new(). I have seen this in other libraries and I like it, even though it's just a small thing.

Was already available the Dispatcher::builder, which return the DistaptcherBuilder. I like it too, but in this PR I deprecated it because require to specify a generic when calling Dispatcher::builder (i.e., Dispatcher::<Async>::builder). But there is a "trick" to allow to continue to use it without breaking changes:

#[derive(Debug, Clone)]
pub struct Dispatcher<T = ()> // <-- set a default value for the generic
where
    T: Clone,
{
    url: Url,
    inner: T,
}

// Impl the `builder` method for the `Dispatcher<()>`, allowing to call `Dispatcher::builder`.
impl Dispatcher {
    pub fn builder<S>(url: S) -> DispatcherBuilder
    where
        S: Into<String>,
    {
        DispatcherBuilder::new(url)
    }
}

I know that there was a function inside the struct implementation before, but what I'm talking about is just putthing the method in the dispatcher module itself and not in the struct. From what I see, that also doesn't require the trick. An example would be ureq in the current stable version: https://github.com/algesten/ureq/blob/ba4555d54fd72e16fc737f7e8fcc812efb131260/src/lib.rs#L492

@yukibtc
Copy link
Member Author

yukibtc commented Jan 6, 2025

I know that there was a function inside the struct implementation before, but what I'm talking about is just putthing the method in the dispatcher module itself and not in the struct. From what I see, that also doesn't require the trick. An example would be ureq in the current stable version: https://github.com/algesten/ureq/blob/ba4555d54fd72e16fc737f7e8fcc812efb131260/src/lib.rs#L492

Ahh, sure, I'll add this!

Signed-off-by: Yuki Kishimoto <[email protected]>
@yukibtc yukibtc merged commit a112bdd into master Jan 6, 2025
2 checks passed
@yukibtc yukibtc deleted the blocking branch January 6, 2025 14:03
yukibtc pushed a commit that referenced this pull request Jan 8, 2025
As mentioned in #9, I added functionality to provide the dispatcher builder and the `Async`/`Blocking` structs with a custom client/agent builder, so things like the user agent, which is not handled by the dispatcher builder already, can be set beforehand.

Closes #10

Signed-off-by: Yuki Kishimoto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants