Skip to content

Commit c92e90c

Browse files
committed
proxy-types Drop JoinPromises function
Also add comments to explain code using it the PassField proxy.capnp Context overload
1 parent 8da0524 commit c92e90c

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

include/mp/proxy-types.h

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ void CustomBuildField(TypeList<>,
9898
context.setCallbackThread(callback_thread->second.m_client);
9999
}
100100

101-
// Invoke promise1, then promise2, and return result of promise2.
102-
template <typename T, typename U>
103-
kj::Promise<U> JoinPromises(kj::Promise<T>&& prom1, kj::Promise<U>&& prom2)
104-
{
105-
return prom1.then([prom2 = kj::mv(prom2)]() mutable { return kj::mv(prom2); });
106-
}
107-
108101
//! PassField override for mp.Context arguments. Return asynchronously and call
109102
//! function on other thread found in context.
110103
template <typename Accessor, typename ServerContext, typename Fn, typename... Args>
@@ -181,27 +174,24 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
181174
// be a local Thread::Server object, but it needs to be looked up
182175
// asynchronously with getLocalServer().
183176
auto thread_client = context_arg.getThread();
184-
return JoinPromises(server.m_context.connection->m_threads.getLocalServer(thread_client)
185-
.then([&server, invoke, req](const kj::Maybe<Thread::Server&>& perhaps) {
186-
// Assuming the thread object is found, pass it a pointer to the
187-
// `invoke` lambda above which will invoke the function on that
188-
// thread.
189-
KJ_IF_MAYBE(thread_server, perhaps)
190-
{
191-
const auto& thread = static_cast<ProxyServer<Thread>&>(*thread_server);
192-
server.m_context.connection->m_loop.log() << "IPC server post request #" << req << " {"
193-
<< thread.m_thread_context.thread_name << "}";
194-
thread.m_thread_context.waiter->post(std::move(invoke));
195-
}
196-
else
197-
{
198-
server.m_context.connection->m_loop.log() << "IPC server error request #" << req
199-
<< ", missing thread to execute request";
200-
throw std::runtime_error("invalid thread handle");
201-
}
202-
}),
177+
return server.m_context.connection->m_threads.getLocalServer(thread_client)
178+
.then([&server, invoke, req](const kj::Maybe<Thread::Server&>& perhaps) {
179+
// Assuming the thread object is found, pass it a pointer to the
180+
// `invoke` lambda above which will invoke the function on that
181+
// thread.
182+
KJ_IF_MAYBE (thread_server, perhaps) {
183+
const auto& thread = static_cast<ProxyServer<Thread>&>(*thread_server);
184+
server.m_context.connection->m_loop.log()
185+
<< "IPC server post request #" << req << " {" << thread.m_thread_context.thread_name << "}";
186+
thread.m_thread_context.waiter->post(std::move(invoke));
187+
} else {
188+
server.m_context.connection->m_loop.log()
189+
<< "IPC server error request #" << req << ", missing thread to execute request";
190+
throw std::runtime_error("invalid thread handle");
191+
}
192+
})
203193
// Wait for the invocation to finish before returning to the caller.
204-
kj::mv(future.promise));
194+
.then([invoke_wait = kj::mv(future.promise)]() mutable { return kj::mv(invoke_wait); });
205195
}
206196

207197
// Destination parameter type that can be passed to ReadField function as an

0 commit comments

Comments
 (0)