Async tool: Simulate web API call
| 27 | |
| 28 | // Async tool: Simulate web API call |
| 29 | std::future<ai::JsonValue> fetch_news_async( |
| 30 | const ai::JsonValue& args, |
| 31 | const ai::ToolExecutionContext& context) { |
| 32 | std::string category = args["category"].get<std::string>(); |
| 33 | |
| 34 | return std::async(std::launch::async, [category]() { |
| 35 | std::cout << "📰 Fetching news for category: " << category << " (async)..." |
| 36 | << std::endl; |
| 37 | |
| 38 | // Simulate network delay |
| 39 | std::this_thread::sleep_for(std::chrono::milliseconds(1000)); |
| 40 | |
| 41 | ai::JsonValue news_articles = ai::JsonValue::array(); |
| 42 | if (category == "tech") { |
| 43 | news_articles = {"AI breakthrough in quantum computing", |
| 44 | "New smartphone features announced", |
| 45 | "Cloud computing trends for 2024"}; |
| 46 | } else if (category == "sports") { |
| 47 | news_articles = {"Championship game results", |
| 48 | "Olympic preparations underway", |
| 49 | "New stadium construction begins"}; |
| 50 | } else { |
| 51 | news_articles = {"General news update 1", "General news update 2", |
| 52 | "General news update 3"}; |
| 53 | } |
| 54 | |
| 55 | std::cout << "📰 News fetch completed for: " << category << std::endl; |
| 56 | |
| 57 | return ai::JsonValue{{"category", category}, |
| 58 | {"articles", news_articles}, |
| 59 | {"fetch_time_ms", 1000}}; |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | // Async tool: Simulate database query |
| 64 | std::future<ai::JsonValue> query_database_async( |
nothing calls this directly
no outgoing calls
no test coverage detected