1

I'm trying to use Microsoft's Parallel Patterns Library's coroutines in my code, which uses Asio for most of its async stuff.

The cleanest way would be to define a token, use_ppl, which somehow behaves the same way as asio::use_awaitable but for ppl coroutines (there isn't a ton of documentation about pplawait.h it seems).

For example:

#include <chrono>
#include <iostream>

#include <pplawait.h>

#include "asio/high_resolution_timer.hpp"

#include "use_ppl.h" // doesn't exist yet

concurrency::task<void> print_after_wait(asio::io_context ctx) {
  using namespace std::chrono;

  asio::high_resolution_timer t(ctx);
  t.expires_after(2s);
  co_await t.async_wait(use_ppl);       // adapter here
  std::cout << "print\n";
}

I've checked asio\impl\use_awaitable.hpp for some pointers, but it seems like most of the code is very specific to asio's particular awaitable implementation (which makes sense).

I've also looked at cti::use_continuable_t from Naios's continuable library, which seems similar, but again it's pretty library-specific.

Does anyone have any pointers for how to go about this? What parts of use_awaitable are "boilerplate" and which parts do I need to actually specialize for PPL tasks?

sehe
  • 374,641
  • 47
  • 450
  • 633
MHebes
  • 2,290
  • 1
  • 16
  • 29
  • Note: I ran into some other problems ([case A](https://stackoverflow.com/q/75189913/3554391), [case B](https://stackoverflow.com/q/75218245/3554391)) while attempting this, and I'm not sure it's possible with a token. Sehe's [answer on the second question](https://stackoverflow.com/a/75228866/3554391) is a conceptually simpler way of going about the same thing using async_compose. See my comment for the modification that allows use of `concurrency::create_task` as the thread provider. – MHebes Jan 25 '23 at 19:33

0 Answers0