Skip to content

Add client_arc method to return cloned API client#9

Open
devintrowbridge5905 wants to merge 5 commits intojBernavaPrah:mainfrom
devintrowbridge5905:main
Open

Add client_arc method to return cloned API client#9
devintrowbridge5905 wants to merge 5 commits intojBernavaPrah:mainfrom
devintrowbridge5905:main

Conversation

@devintrowbridge5905
Copy link
Copy Markdown

AriClient internally stores the API client as client: Arc<apis::client::Client>. However, the current accessor is defined as:

pub fn client(&self) -> &apis::client::Client {
    &self.client
}

Because Arc<T> dereferences to T, this coerces to &Client, preventing callers from moving the client into spawned async tasks. Returning Arc<Client> allows callers to cheaply clone and move the client where needed.

Proposed Change

/// add a method to return a clone of the underlying API client `Arc`.
pub fn client_arc(&self) -> Arc<apis::client::Client> {
    self.client.clone()
}

Copy link
Copy Markdown
Owner

@jBernavaPrah jBernavaPrah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Hope to have more PRs soon!

@jBernavaPrah
Copy link
Copy Markdown
Owner

@devintrowbridge5905,

This weekend I will try to check better why Clippy is complaining.

In the meantime, could you tell me how you will use this "client_arc"?

@devintrowbridge5905
Copy link
Copy Markdown
Author

Thanks for the consideration.

When I receive a stasis start event, I route the channel to a bridge and spin up a task for that channel that generates internal start/stop talking events based on RTP statistics for the channel. I have a separate long lived thread (i.e. TalkEventHandler) outside the context of stasis events that listens for these internal events and makes ari api calls using the AriClient.

I suppose an alternative would be to setup a second AriClient for my event handler since its not actually handling any ari events. It just needs to be able to make api calls.

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