Listing 7

dti::async::astream ast;
std::string buf;

ast(ts) >> buf;

try {
    std::ios_base *b = ast.wait(5000);  // Wait at most 5000 ms
    if (b == &ts)
        std::cout << "Input:" << buf << std::endl;
    else {  // Timeout
        ast.abort();
        ast.wait();  // Wait for abort operation to complete
    }
}
catch (dti::async::async_error& e) {
    std::cout << "Async error: " << e.what() << std::endl;
}