Hi Jens, Two options for writing sync-like code that is actually async: - KJ supports "Fibers", which allocates a separate stack that runs in the same thread. When running on that stack, you get a `WaitScope` that you can use to wait on promises. When you wait, the thread switches back to the main stack. - We have some support for C++20 coroutines using co_await/co_return (aka async/await). However, it's currently based on `-fcoroutines-ts` in Clang; it may not work with any other compiler, and this flag is going to go away soon, though we'll likely upgrade to the final version of coroutines before that happens.
-Kenton On Wed, Aug 31, 2022 at 12:29 PM Jens Alfke <j...@mooseyard.com> wrote: > > > > On Aug 30, 2022, at 7:37 PM, 'Kenton Varda' via Cap'n Proto < > capnproto@googlegroups.com> wrote: > > > > Hi Jens, > > > > It sounds very obnoxious that your debugger insists on breaking on this > signal. > > I’ve filed a bug report with Apple. > > > With that said, you could try compiling with `-DKJ_USE_PIPE_FOR_WAKEUP`, > which causes it to avoid using signals for this. You need to compile both > KJ itself and your own code that depends on it with this define; if they > don't match you may get undefined behavior. > > For posterity: since I’m building with CMake, I accomplished this by > adding `add_compile_definitions(KJ_USE_PIPE_FOR_WAKEUP)` to my top-level > CMakeLists.txt, above the line `add_subdirectory(vendor/capnproto)`. > > Now my code can talk inter-thread RPC over the fake socket! Yay! > > But of course there’s always another roadblock. The next one I hit is a > fatal exception "expected !loop.running; wait() is not allowed from within > event callbacks.” Apparently code running in an Executor block on the > target thread is not allowed to call Promise.wait()? This is a bummer, as > so far I’ve been lazy and written my RPC client code in blocking style. > Looks like it’s time to fully async-ify it. > > —Jens -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/CAJouXQnMWk2ZROUhaVzr14YnM9yKghdjA1%3Dy7pN94DkkMkWGiQ%40mail.gmail.com.