Closed Kazurin-775 closed 2 years ago
@Kazurin-775 The pr https://github.com/containerd/ttrpc-rust/pull/123 has been merged and the new version of ttrpc-compiler and ttrpc-codegen has been published
you can rebase this pr now.
@Tim-Zhang Done rebasing. (Sorry for being late)
@lifupan PTAL
Currently, the
request()
method ofttrpc::r#async::Client
takes an&mut self
. This prevents theClient
from being used concurrently, since a mutable reference in Rust indicates (and enforces) exclusive use of an object.In this patch, we change the signature of
request()
to take&self
instead of&mut self
. This allows multiple coroutines to issue concurrent RPC requests via the sameClient
object (e.g. by using anArc
), without breaking the API compatibility (although most of existing code will generate a warning indicating that alet mut
is unnecessary).We see (in the example code) that this problem is currently worked around by cloning the
Client
. However, we still hope to propose this patch, since by avoiding cloning theClient
, we could improve the performance in scenarios where theClient
is already wrapped in anArc
.Meanwhile, the synchronized flavor of this library already takes
&self
in therequest()
method: https://github.com/containerd/ttrpc-rust/blob/dfae1ad06ec29d93ed76dfcf3e931168cd1d426a/src/sync/client.rs#L216Therefore, by applying this patch, we maintain the consistency between the synchronized and asynchronized APIs.
(UPDATE: changes in the compiler part has been moved to a sub-PR #123.)