Skip to content

Commit 78c7dd0

Browse files
committed
doc: Document ProxyClient construct/destroy methods
1 parent e99c0b7 commit 78c7dd0

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

include/mp/proxy.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,35 @@ class ProxyClientBase : public Impl_
6060
ProxyClientBase(typename Interface::Client client, Connection* connection, bool destroy_connection);
6161
~ProxyClientBase() noexcept;
6262

63-
// Methods called during client construction/destruction that can optionally
64-
// be defined in capnp interface to trigger the server.
63+
// construct/destroy methods called during client construction/destruction
64+
// that can optionally be defined in capnp interfaces to invoke code on the
65+
// server when proxy client objects are created and destroyed.
66+
//
67+
// The construct() method is not generally very useful, but can be used to
68+
// run custom code on the server automatically when a ProxyClient client is
69+
// constructed. The only current use is adding a construct method to Init
70+
// interfaces that is called automatically on construction, so client and
71+
// server exchange ThreadMap references and set Connection::m_thread_map
72+
// values as soon as the Init client is created.
73+
//
74+
// construct @0 (threadMap: Proxy.ThreadMap) -> (threadMap: Proxy.ThreadMap);
75+
//
76+
// But construct() is not necessary for this, thread maps could be passed
77+
// through a normal method that is just called explicitly rather than
78+
// implicitly.
79+
//
80+
// The destroy() method is more generally useful than construct(), because
81+
// it ensures that the server object will be destroyed synchronously before
82+
// the client destructor returns, instead of asynchronously at some
83+
// unpredictable time after the client object is already destroyed and
84+
// client code has moved on. If the destroy method accepts a Context
85+
// parameter like:
86+
//
87+
// destroy @0 (context: Proxy.Context) -> ();
88+
//
89+
// then it will also ensure that the destructor runs on the same thread the
90+
// client used to make other RPC calls, instead of running on the server
91+
// EventLoop thread and possibly blocking it.
6592
void construct() {}
6693
void destroy() {}
6794

0 commit comments

Comments
 (0)