8 #include "resource.hpp" 14 template<
typename T,
typename U>
15 class Request:
public Resource<T, U> {
17 static auto reserve(U *req) {
18 auto ptr =
static_cast<T*
>(req->data)->shared_from_this();
24 static void defaultCallback(U *req,
int status) {
25 auto ptr = reserve(req);
26 if(status) { ptr->publish(ErrorEvent{status}); }
27 else { ptr->publish(E{}); }
30 template<
typename F,
typename... Args>
31 auto invoke(F &&f, Args&&... args) {
32 if constexpr(std::is_void_v<std::invoke_result_t<F, Args...>>) {
33 std::forward<F>(f)(std::forward<Args>(args)...);
36 auto err = std::forward<F>(f)(std::forward<Args>(args)...);
37 if(err) { Emitter<T>::publish(ErrorEvent{err}); }
38 else { this->leak(); }
43 using Resource<T, U>::Resource;
59 return (0 == uv_cancel(this->
template get<uv_req_t>()));
66 std::size_t size() const noexcept {
67 return uv_req_size(this->
template get<uv_req_t>()->type);