diff --git a/README.md b/README.md index 281ab550..10d0cf2b 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,12 @@ The first thing to do to use `uvw` is to create a loop. In case the default one auto loop = uvw::Loop::getDefault(); Note that loop objects don't require to be closed explicitly, even if they offer the `close` member method in case an user wants to do that. -Loops can be run using the `run`, `runOnce` and `runWait` member methods. Please refer to the documentation of *libuv* for further details. +Loops can be started using the `run` member method. The two calls below are equivalent: + + loop->run(); + loop->run + +Available modes are: `DEFAULT`, `ONCE`, `NOWAIT`. Please refer to the documentation of *libuv* for further details. In order to create a resource and to bind it to the given loop, just do the following: diff --git a/src/uvw/loop.hpp b/src/uvw/loop.hpp index 6edc1ba6..0109c664 100644 --- a/src/uvw/loop.hpp +++ b/src/uvw/loop.hpp @@ -22,6 +22,13 @@ enum class UVLoopOption: std::underlying_type_t { }; +enum class UVRunMode: std::underlying_type_t { + DEFAULT = UV_RUN_DEFAULT, + ONCE = UV_RUN_ONCE, + NOWAIT = UV_RUN_NOWAIT +}; + + } @@ -49,6 +56,7 @@ class Loop final: public Emitter, public std::enable_shared_from_this create() { auto ptr = std::unique_ptr{new uv_loop_t, [](uv_loop_t *l){ delete l; }}; @@ -117,16 +125,11 @@ public: if(err) { publish(ErrorEvent{err}); } } + template bool run() noexcept { - return (uv_run(loop.get(), UV_RUN_DEFAULT) == 0); - } - - bool runOnce() noexcept { - return (uv_run(loop.get(), UV_RUN_ONCE) == 0); - } - - bool runNoWait() noexcept { - return (uv_run(loop.get(), UV_RUN_NOWAIT) == 0); + auto utm = static_cast>(mode); + auto uvrm = static_cast(utm); + return (uv_run(loop.get(), uvrm) == 0); } bool alive() const noexcept { diff --git a/test/uvw/check.cpp b/test/uvw/check.cpp index eed61198..f1e0cdd6 100644 --- a/test/uvw/check.cpp +++ b/test/uvw/check.cpp @@ -27,7 +27,7 @@ TEST(Check, PartiallyDone) { ASSERT_TRUE(handle->active()); ASSERT_FALSE(handle->closing()); - loop->runNoWait(); + loop->run(); ASSERT_FALSE(checkErrorEvent); ASSERT_TRUE(checkCheckEvent); diff --git a/test/uvw/loop.cpp b/test/uvw/loop.cpp index 4d47377c..2a774ac7 100644 --- a/test/uvw/loop.cpp +++ b/test/uvw/loop.cpp @@ -42,8 +42,8 @@ TEST(Loop, PartiallyDone) { loop->walk([](uvw::BaseHandle &) { ASSERT_TRUE(false); }); - ASSERT_NO_THROW(loop->runOnce()); - ASSERT_NO_THROW(loop->runNoWait()); + ASSERT_NO_THROW(loop->run()); + ASSERT_NO_THROW(loop->run()); ASSERT_FALSE(loop->alive()); }