Skip to content

Consider removing inner Arc from TaskMonitor #85

@jplatte

Description

@jplatte

I've started using tokio-metrics at work recently and found it a bit unfortunate that if you put TaskMonitors in statics, you have to wrap them in LazyLock or similar for the initialization. It seems the only reason for this is that TaskMonitor is internally an Arc for easy cloning, but it doesn't seem like there is any need for that.

How about an API like this for construction?

// no Clone impl
pub struct TaskMonitor {
    // all the atomics currently found in the inner state type
}

impl TaskMonitor {
    pub fn new() -> Arc<Self> { /* ... */ }
    pub const fn new_static() -> Self { /* ... */ }
    pub const fn builder() -> TaskMonitorBuilder { /* ... */ }
}

pub struct TaskMonitorBuilder {
    // same as now
}

impl TaskMonitorBuilder {
    // with_* methods just like before
    pub fn build(self) -> Arc<TaskMonitor> { /* ... */ }
    pub const fn build_static(self) -> TaskMonitor { /* ... */ }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions