Skip to content

Any real-world examples where the coroutine backing can be applied? #271

@AndrewLipscomb

Description

@AndrewLipscomb

I've been having a lot of ... fun implementing boost::asio alongside this lib - mainly due to the fact that the ASIO coroutine co_await handler looks like this

  // Support for co_await keyword.
  template <class U>
  void await_suspend(
      detail::coroutine_handle<detail::awaitable_frame<U, Executor>> h)
  {
    frame_->push_frame(&h.promise());
  }

Obviously, once cppgraphqlgen's resolve function has been entered, all the context needed for filling out the std::coroutine_handle<detail::awaitable_frame<U, Executor>> disappears, and is replaced with graphql::service::AwaitableObject<#value>::promise_type

My not-really-ideal workaround has been

  • Enter the GraphQL system from a boost::asio::awaitable context
  • Drop into the cppgraphqlgen resolve context, lose my immediate boost::asio context and have all functions return std::future<T> to fullfill the graphql::service::AwaitableObject
  • Use boost::asio:co_spawn to restart the boost::asio::awaitable contexts and return futures via boost::asio::use_future

I'm curious that due to the fact that boost::asio::awaitable's context is basically the internal guts for its actual coroutine-execution-operation-element-bits, are there any other good examples for async-execution frameworks/libraries that can be used with this library and don't require modifying that underlying service::Awaitable type to be aware of how the async library works?

I suppose for comparison, I'm thinking of C libraries which do a sync version of their calls, then specialise for libuv, libevent etc - I am really hoping that C++ coroutines give us some means of abstracting the libuv-equivalent away, but given my experience so far, I'm guessing maybe it can't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions