本文整理汇总了C++中Future::then方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::then方法的具体用法?C++ Future::then怎么用?C++ Future::then使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future::then方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BadRequest
Future<http::Response> MetricsProcess::_snapshot(
const http::Request& request,
const Option<string>& /* principal */)
{
// Parse the 'timeout' parameter.
Option<Duration> timeout;
if (request.url.query.contains("timeout")) {
string parameter = request.url.query.get("timeout").get();
Try<Duration> duration = Duration::parse(parameter);
if (duration.isError()) {
return http::BadRequest(
"Invalid timeout '" + parameter + "': " + duration.error() + ".\n");
}
timeout = duration.get();
}
Future<Nothing> acquire = Nothing();
if (limiter.isSome()) {
acquire = limiter.get()->acquire();
}
return acquire.then(defer(self(), &Self::snapshot, timeout))
.then([request](const hashmap<string, double>& metrics)
-> http::Response {
return http::OK(jsonify(metrics), request.url.query.get("jsonp"));
});
}
示例2: getCallbacksByMethod
Future<void> ServerPlugin::execute(const std::string &iUriPath, std::shared_ptr<ServerConnection> iTransaction) {
using CallbacksIntType = std::list<std::shared_ptr<CallbackDataBase>>;
using CallbacksMapIntType = std::map<size_t, CallbacksIntType>;
CallbacksMapIntType callbacksMap;
const std::string uriPath = iTransaction->getRequest().url().path();
// Plugins
for (std::shared_ptr<PluginData> plugin : _plugins) {
size_t length;
if (plugin->matchUri(iUriPath, length)) {
callbacksMap[length].push_back(plugin);
}
}
// callbacks use
getCallbacksByMethod("", iUriPath, callbacksMap);
// callbacks by method
getCallbacksByMethod(iTransaction->getRequest().getMethodStr(), iUriPath, callbacksMap);
// execute
Future<void> result = Promise<void>::Resolve(_loop);
bool isFirst = true;
for (CallbacksMapIntType::value_type &callbacksIt : callbacksMap) {
std::string newUriPath = iUriPath.substr(callbacksIt.first);
for (std::shared_ptr<CallbackDataBase> callback : callbacksIt.second) {
std::weak_ptr<CallbackDataBase> callbackWeak = callback;
if (!callback) {
continue;
}
callback->uri.extract(iTransaction->getRequest().getUriTemplateValues(), iUriPath, false);
if (!isFirst) {
result = result.then([callbackWeak, iTransaction, newUriPath]() -> Future<void> {
if (iTransaction->getResponse().isSent()) {
return Promise<void>::Resolve(iTransaction->_server->_loop);
}
return callbackWeak.lock()->execute(newUriPath, iTransaction);
});
} else {
isFirst = false;
result = callback->execute(iUriPath, iTransaction);
}
}
}
return result;
}
示例3:
Future<string> func2(const Future<int>& f)
{
return f.then(defer(self(), &Self::_func2));
}