Advertisement
Guest User

Unsugared await

a guest
Jan 3rd, 2015
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. std::future<ptrdiff_t> tcp_reader(int total)
  2. {
  3.     char bug[64 * 1024];
  4.     ptrdiff_t result = 0;
  5.  
  6.     return Tcp::Connect("127.0.0.1", 1337).then([=] (auto conn);
  7.     {
  8.         do
  9.         {
  10.             auto bytesRead = await conn.Read(buf, sizeof(buf));
  11.             total -= bytesRead;
  12.             result += std::count(buf, buf + bytesRead, 'c');
  13.         }
  14.         while (total > 0);
  15.         return result;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement