Skip to content

Commit

Permalink
Add support for callback style methods in API
Browse files Browse the repository at this point in the history
Closes #27
  • Loading branch information
whoshuu committed Jul 23, 2015
1 parent 6ef2223 commit a6e3703
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions include/api.h
Expand Up @@ -46,6 +46,14 @@ namespace cpr {
}, std::move(ts)...);
}

// Get callback methods
template <typename Then, typename... Ts>
auto GetCallback(Then then, Ts... ts) -> std::future<decltype(then(Get(std::move(ts)...)))> {
return std::async(std::launch::async, [] (Then then, Ts... ts) {
return then(Get(std::move(ts)...));
}, std::move(then), std::move(ts)...);
}

// Post methods
template <typename... Ts>
Response Post(Ts&&... ts) {
Expand All @@ -62,6 +70,14 @@ namespace cpr {
}, std::move(ts)...);
}

// Post callback methods
template <typename Then, typename... Ts>
auto PostCallback(Then then, Ts... ts) -> std::future<decltype(then(Post(std::move(ts)...)))> {
return std::async(std::launch::async, [] (Then then, Ts... ts) {
return then(Post(std::move(ts)...));
}, std::move(then), std::move(ts)...);
}

// Put methods
template <typename... Ts>
Response Put(Ts&&... ts) {
Expand All @@ -78,6 +94,14 @@ namespace cpr {
}, std::move(ts)...);
}

// Put callback methods
template <typename Then, typename... Ts>
auto PutCallback(Then then, Ts... ts) -> std::future<decltype(then(Put(std::move(ts)...)))> {
return std::async(std::launch::async, [] (Then then, Ts... ts) {
return then(Put(std::move(ts)...));
}, std::move(then), std::move(ts)...);
}

// Head methods
template <typename... Ts>
Response Head(Ts&&... ts) {
Expand All @@ -94,6 +118,14 @@ namespace cpr {
}, std::move(ts)...);
}

// Head callback methods
template <typename Then, typename... Ts>
auto HeadCallback(Then then, Ts... ts) -> std::future<decltype(then(Head(std::move(ts)...)))> {
return std::async(std::launch::async, [] (Then then, Ts... ts) {
return then(Head(std::move(ts)...));
}, std::move(then), std::move(ts)...);
}

// Delete methods
template <typename... Ts>
Response Delete(Ts&&... ts) {
Expand All @@ -109,6 +141,14 @@ namespace cpr {
return Delete(std::move(ts)...);
}, std::move(ts)...);
}

// Delete callback methods
template <typename Then, typename... Ts>
auto DeleteCallback(Then then, Ts... ts) -> std::future<decltype(then(Delete(std::move(ts)...)))> {
return std::async(std::launch::async, [] (Then then, Ts... ts) {
return then(Delete(std::move(ts)...));
}, std::move(then), std::move(ts)...);
}
};

#endif

0 comments on commit a6e3703

Please sign in to comment.