minor changes
This commit is contained in:
parent
7e8005a90a
commit
c159f37771
@ -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();
|
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.
|
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<uvw::Loop::Mode::DEFAULT>
|
||||||
|
|
||||||
|
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:
|
In order to create a resource and to bind it to the given loop, just do the following:
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,13 @@ enum class UVLoopOption: std::underlying_type_t<uv_loop_option> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum class UVRunMode: std::underlying_type_t<uv_run_mode> {
|
||||||
|
DEFAULT = UV_RUN_DEFAULT,
|
||||||
|
ONCE = UV_RUN_ONCE,
|
||||||
|
NOWAIT = UV_RUN_NOWAIT
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -49,6 +56,7 @@ class Loop final: public Emitter<Loop>, public std::enable_shared_from_this<Loop
|
|||||||
public:
|
public:
|
||||||
using Time = std::chrono::milliseconds;
|
using Time = std::chrono::milliseconds;
|
||||||
using Configure = details::UVLoopOption;
|
using Configure = details::UVLoopOption;
|
||||||
|
using Mode = details::UVRunMode;
|
||||||
|
|
||||||
static std::shared_ptr<Loop> create() {
|
static std::shared_ptr<Loop> create() {
|
||||||
auto ptr = std::unique_ptr<uv_loop_t, Deleter>{new uv_loop_t, [](uv_loop_t *l){ delete l; }};
|
auto ptr = std::unique_ptr<uv_loop_t, Deleter>{new uv_loop_t, [](uv_loop_t *l){ delete l; }};
|
||||||
@ -117,16 +125,11 @@ public:
|
|||||||
if(err) { publish(ErrorEvent{err}); }
|
if(err) { publish(ErrorEvent{err}); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<Mode mode = Mode::DEFAULT>
|
||||||
bool run() noexcept {
|
bool run() noexcept {
|
||||||
return (uv_run(loop.get(), UV_RUN_DEFAULT) == 0);
|
auto utm = static_cast<std::underlying_type_t<Mode>>(mode);
|
||||||
}
|
auto uvrm = static_cast<uv_run_mode>(utm);
|
||||||
|
return (uv_run(loop.get(), uvrm) == 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool alive() const noexcept {
|
bool alive() const noexcept {
|
||||||
|
|||||||
@ -27,7 +27,7 @@ TEST(Check, PartiallyDone) {
|
|||||||
ASSERT_TRUE(handle->active());
|
ASSERT_TRUE(handle->active());
|
||||||
ASSERT_FALSE(handle->closing());
|
ASSERT_FALSE(handle->closing());
|
||||||
|
|
||||||
loop->runNoWait();
|
loop->run<uvw::Loop::Mode::NOWAIT>();
|
||||||
|
|
||||||
ASSERT_FALSE(checkErrorEvent);
|
ASSERT_FALSE(checkErrorEvent);
|
||||||
ASSERT_TRUE(checkCheckEvent);
|
ASSERT_TRUE(checkCheckEvent);
|
||||||
|
|||||||
@ -42,8 +42,8 @@ TEST(Loop, PartiallyDone) {
|
|||||||
|
|
||||||
loop->walk([](uvw::BaseHandle &) { ASSERT_TRUE(false); });
|
loop->walk([](uvw::BaseHandle &) { ASSERT_TRUE(false); });
|
||||||
|
|
||||||
ASSERT_NO_THROW(loop->runOnce());
|
ASSERT_NO_THROW(loop->run<uvw::Loop::Mode::ONCE>());
|
||||||
ASSERT_NO_THROW(loop->runNoWait());
|
ASSERT_NO_THROW(loop->run<uvw::Loop::Mode::NOWAIT>());
|
||||||
|
|
||||||
ASSERT_FALSE(loop->alive());
|
ASSERT_FALSE(loop->alive());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user