added Loop::create overload to allow using external resources (close #157)

This commit is contained in:
Michele Caini 2019-08-28 16:39:12 +02:00
parent ea4b6c84d0
commit 3264417f15

View File

@ -169,6 +169,21 @@ public:
return loop;
}
/**
* @brief Initializes a new Loop instance from an existing resource.
*
* The lifetime of the resource must exceed that of the instance to which
* it's associated. Management of the memory associated with the resource is
* in charge of the user.
*
* @param loop A valid pointer to a correctly initialized resource.
* @return A pointer to the newly created loop.
*/
static std::shared_ptr<Loop> create(uv_loop_t *loop) {
auto ptr = std::unique_ptr<uv_loop_t, Deleter>{loop, [](uv_loop_t *){}};
return std::shared_ptr<Loop>{new Loop{std::move(ptr)}};
}
/**
* @brief Gets the initialized default loop.
*